backport 7.0.1-beta.2 → 7.2.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/dist/backportRun.d.ts +1 -0
  2. package/dist/backportRun.js +3 -2
  3. package/dist/entrypoint.cli.js +12 -1
  4. package/dist/entrypoint.module.d.ts +4 -3
  5. package/dist/entrypoint.module.js +2 -7
  6. package/dist/options/ConfigOptions.d.ts +1 -1
  7. package/dist/options/cliArgs.d.ts +2 -1
  8. package/dist/options/cliArgs.js +4 -0
  9. package/dist/options/config/config.d.ts +1 -1
  10. package/dist/options/config/readConfigFile.d.ts +2 -2
  11. package/dist/options/options.d.ts +3 -6
  12. package/dist/runSequentially.js +1 -0
  13. package/dist/services/HandledError.js +3 -1
  14. package/dist/services/git.d.ts +2 -0
  15. package/dist/services/git.js +47 -10
  16. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  17. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -6
  18. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  19. package/dist/services/github/v3/addLabelsToPullRequest.js +3 -6
  20. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +1 -1
  21. package/dist/services/github/v3/addReviewersToPullRequest.js +3 -6
  22. package/dist/services/github/v3/createPullRequest.js +2 -5
  23. package/dist/services/github/v3/createStatusComment.js +1 -1
  24. package/dist/services/github/v4/FetchPullRequestId.js +5 -1
  25. package/dist/services/github/v4/apiRequestV4.d.ts +7 -4
  26. package/dist/services/github/v4/apiRequestV4.js +22 -21
  27. package/dist/services/github/v4/disablePullRequestAutoMerge.js +5 -1
  28. package/dist/services/github/v4/enablePullRequestAutoMerge.js +4 -3
  29. package/dist/services/github/v4/fetchAuthorId.js +5 -1
  30. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -1
  31. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +24 -13
  32. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -1
  33. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +24 -13
  34. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -1
  35. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +20 -10
  36. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +20 -9
  37. package/dist/services/github/v4/fetchExistingPullRequest.js +5 -1
  38. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +5 -1
  39. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +1 -1
  40. package/dist/services/github/v4/fetchRemoteProjectConfig.js +13 -20
  41. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -5
  42. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +12 -66
  43. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +3 -16
  44. package/dist/services/github/v4/getOptionsFromGithub/query.js +9 -19
  45. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +5 -1
  46. package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
  47. package/dist/services/logger.d.ts +5 -5
  48. package/dist/services/logger.js +24 -23
  49. package/dist/services/remoteConfig.d.ts +20 -0
  50. package/dist/services/remoteConfig.js +52 -0
  51. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -1
  52. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +5 -1
  53. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +4 -0
  54. package/dist/services/sourceCommit/getMockSourceCommit.js +21 -6
  55. package/dist/services/sourceCommit/parseSourceCommit.d.ts +3 -4
  56. package/dist/services/sourceCommit/parseSourceCommit.js +73 -77
  57. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +16 -22
  58. package/dist/ui/getCommits.js +8 -6
  59. package/dist/ui/maybeSetupRepo.js +7 -14
  60. package/dist/ui/ora.d.ts +9 -0
  61. package/dist/ui/ora.js +21 -0
  62. package/dist/utils/packageVersion.d.ts +1 -1
  63. package/dist/utils/packageVersion.js +1 -1
  64. package/package.json +10 -10
  65. package/yarn.lock +121 -114
  66. package/dist/entrypoint.cli.e2e.private.test.d.ts +0 -1
  67. package/dist/entrypoint.cli.e2e.private.test.js +0 -319
  68. package/dist/entrypoint.cli.private.test.d.ts +0 -1
  69. package/dist/entrypoint.cli.private.test.js +0 -46
  70. package/dist/options/cliArgs.test.d.ts +0 -1
  71. package/dist/options/cliArgs.test.js +0 -182
  72. package/dist/options/config/config.test.d.ts +0 -1
  73. package/dist/options/config/config.test.js +0 -32
  74. package/dist/options/config/globalConfig.test.d.ts +0 -1
  75. package/dist/options/config/globalConfig.test.js +0 -61
  76. package/dist/options/config/projectConfig.test.d.ts +0 -1
  77. package/dist/options/config/projectConfig.test.js +0 -109
  78. package/dist/options/options.test.d.ts +0 -1
  79. package/dist/options/options.test.js +0 -386
  80. package/dist/runSequentially.test.d.ts +0 -1
  81. package/dist/runSequentially.test.js +0 -218
  82. package/dist/scripts/postinstall.test.d.ts +0 -1
  83. package/dist/scripts/postinstall.test.js +0 -53
  84. package/dist/services/env.test.d.ts +0 -1
  85. package/dist/services/env.test.js +0 -21
  86. package/dist/services/git.integration.test.d.ts +0 -1
  87. package/dist/services/git.integration.test.js +0 -267
  88. package/dist/services/git.test.d.ts +0 -1
  89. package/dist/services/git.test.js +0 -518
  90. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  91. package/dist/services/github/commitFormatters.test.js +0 -11
  92. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  93. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  94. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  95. package/dist/services/github/v3/createPullRequest.test.js +0 -325
  96. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  97. package/dist/services/github/v3/createStatusComment.test.js +0 -386
  98. package/dist/services/github/v3/index.d.ts +0 -1
  99. package/dist/services/github/v3/index.js +0 -61
  100. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  101. package/dist/services/github/v4/apiRequestV4.test.js +0 -82
  102. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  103. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  104. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  105. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -28
  106. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  107. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -96
  108. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  109. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -143
  110. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  111. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -124
  112. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  113. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -200
  114. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  115. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -153
  116. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  117. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -102
  118. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  119. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -47
  120. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  121. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -52
  122. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  123. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -136
  124. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  125. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -71
  126. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  127. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -154
  128. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  129. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  130. package/dist/services/prompt.test.d.ts +0 -1
  131. package/dist/services/prompt.test.js +0 -134
  132. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  133. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -433
  134. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  135. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -235
  136. package/dist/test/ExecError.d.ts +0 -16
  137. package/dist/test/ExecError.js +0 -15
  138. package/dist/test/backport-e2e.mutation.test.d.ts +0 -1
  139. package/dist/test/backport-e2e.mutation.test.js +0 -347
  140. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +0 -1
  141. package/dist/test/handleUnbackportedPullRequests.private.test.js +0 -57
  142. package/dist/test/mockConfigFiles.d.ts +0 -5
  143. package/dist/test/mockConfigFiles.js +0 -21
  144. package/dist/test/mocks.d.ts +0 -10
  145. package/dist/test/mocks.js +0 -23
  146. package/dist/test/nockHelpers.d.ts +0 -16
  147. package/dist/test/nockHelpers.js +0 -32
  148. package/dist/test/private/getDevAccessToken.d.ts +0 -2
  149. package/dist/test/private/getDevAccessToken.js +0 -12
  150. package/dist/test/sandbox.d.ts +0 -5
  151. package/dist/test/sandbox.js +0 -43
  152. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  153. package/dist/test/setupFiles/automatic-mocks.js +0 -63
  154. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  155. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -455
  156. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  157. package/dist/ui/getCommitsWithoutBackports.test.js +0 -311
  158. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  159. package/dist/ui/getTargetBranches.test.js +0 -198
  160. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  161. package/dist/ui/maybeSetupRepo.test.js +0 -204
  162. package/dist/utils/excludeUndefined.test.d.ts +0 -1
  163. package/dist/utils/excludeUndefined.test.js +0 -24
@@ -12,13 +12,13 @@ function throwOnInvalidAccessToken({ error, repoOwner, repoName, }) {
12
12
  return matches[1];
13
13
  }
14
14
  }
15
- const statusCode = error.axiosResponse.status;
15
+ const statusCode = error.githubResponse.status;
16
16
  switch (statusCode) {
17
17
  case 200: {
18
- const repoNotFound = error.axiosResponse.data.errors?.some((error) => error.type === 'NOT_FOUND' && error.path.join('.') === 'repository');
19
- const grantedScopes = error.axiosResponse.headers['x-oauth-scopes'] || '';
20
- const requiredScopes = error.axiosResponse.headers['x-accepted-oauth-scopes'] || '';
21
- const ssoHeader = (0, maybe_1.maybe)(error.axiosResponse.headers['x-github-sso']);
18
+ const repoNotFound = error.githubResponse.data.errors?.some((error) => error.type === 'NOT_FOUND' && error.path.join('.') === 'repository');
19
+ const grantedScopes = error.githubResponse.headers['x-oauth-scopes'] || '';
20
+ const requiredScopes = error.githubResponse.headers['x-accepted-oauth-scopes'] || '';
21
+ const ssoHeader = (0, maybe_1.maybe)(error.githubResponse.headers['x-github-sso']);
22
22
  if (repoNotFound) {
23
23
  const hasRequiredScopes = (0, lodash_1.isEmpty)((0, lodash_1.difference)(requiredScopes.split(','), grantedScopes.split(',')));
24
24
  // user does not have permission to the repo
@@ -28,7 +28,7 @@ function throwOnInvalidAccessToken({ error, repoOwner, repoName, }) {
28
28
  // repo does not exist
29
29
  throw new HandledError_1.HandledError(`The repository "${repoOwner}/${repoName}" doesn't exist`);
30
30
  }
31
- const repoAccessForbidden = error.axiosResponse.data.errors?.some((error) => error.type === 'FORBIDDEN');
31
+ const repoAccessForbidden = error.githubResponse.data.errors?.some((error) => error.type === 'FORBIDDEN');
32
32
  const ssoAuthUrl = getSSOAuthUrl(ssoHeader);
33
33
  // user does not have permissions
34
34
  if (repoAccessForbidden && ssoAuthUrl) {
@@ -1,12 +1,12 @@
1
1
  import winston from 'winston';
2
2
  export declare let logger: winston.Logger;
3
+ export declare function initLogger({ ci, accessToken, logFilePath, }: {
4
+ ci: boolean | undefined;
5
+ accessToken?: string;
6
+ logFilePath?: string;
7
+ }): winston.Logger;
3
8
  export declare function consoleLog(message: string): void;
4
9
  export declare function updateLogger({ accessToken, verbose, }: {
5
10
  accessToken: string;
6
11
  verbose?: boolean;
7
12
  }): void;
8
- export declare function initLogger({ ci, accessToken, logFilePath, }: {
9
- ci?: boolean;
10
- accessToken?: string;
11
- logFilePath?: string;
12
- }): winston.Logger;
@@ -19,18 +19,37 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.initLogger = exports.updateLogger = exports.consoleLog = exports.logger = void 0;
22
+ exports.updateLogger = exports.consoleLog = exports.initLogger = exports.logger = void 0;
23
23
  const winston_1 = __importStar(require("winston"));
24
24
  const redact_1 = require("../utils/redact");
25
25
  const env_1 = require("./env");
26
+ let _accessToken;
27
+ let _ci;
28
+ function initLogger({ ci, accessToken, logFilePath, }) {
29
+ const fileTransport = getFileTransport({ logFilePath });
30
+ if (accessToken) {
31
+ _accessToken = accessToken;
32
+ }
33
+ _ci = ci;
34
+ exports.logger = winston_1.default.createLogger({
35
+ format: winston_1.format.combine(winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
36
+ // Format the metadata object
37
+ winston_1.format.metadata({
38
+ fillExcept: ['message', 'level', 'timestamp', 'label'],
39
+ })),
40
+ transports: fileTransport,
41
+ });
42
+ return exports.logger;
43
+ }
44
+ exports.initLogger = initLogger;
26
45
  // wrapper around console.log
27
46
  function consoleLog(message) {
28
- // eslint-disable-next-line no-console
29
- console.log(redactAccessToken(message));
30
- //process.stdout.write(message);
47
+ if (!_ci) {
48
+ // eslint-disable-next-line no-console
49
+ console.log(redactAccessToken(message));
50
+ }
31
51
  }
32
52
  exports.consoleLog = consoleLog;
33
- let _accessToken;
34
53
  function updateLogger({ accessToken, verbose, }) {
35
54
  // set access token
36
55
  _accessToken = accessToken;
@@ -45,24 +64,6 @@ function redactAccessToken(str) {
45
64
  }
46
65
  return str;
47
66
  }
48
- function initLogger({ ci, accessToken, logFilePath, }) {
49
- const fileTransport = getFileTransport({ logFilePath });
50
- if (accessToken) {
51
- _accessToken = accessToken;
52
- }
53
- exports.logger = winston_1.default.createLogger({
54
- format: winston_1.format.combine(winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
55
- // Format the metadata object
56
- winston_1.format.metadata({
57
- fillExcept: ['message', 'level', 'timestamp', 'label'],
58
- })),
59
- transports: ci
60
- ? [fileTransport, new winston_1.default.transports.Console()]
61
- : [fileTransport],
62
- });
63
- return exports.logger;
64
- }
65
- exports.initLogger = initLogger;
66
67
  function getFileTransport({ logFilePath }) {
67
68
  return new winston_1.default.transports.File({
68
69
  filename: (0, env_1.getLogfilePath)({ logFilePath }),
@@ -0,0 +1,20 @@
1
+ import { ConfigFileOptions } from '../entrypoint.module';
2
+ import { GithubV4Exception } from './github/v4/apiRequestV4';
3
+ export declare const RemoteConfigHistoryFragment: import("graphql").DocumentNode;
4
+ export interface RemoteConfig {
5
+ committedDate: string;
6
+ file: {
7
+ object: {
8
+ text: string;
9
+ };
10
+ };
11
+ }
12
+ export interface RemoteConfigHistory {
13
+ remoteConfigHistory: {
14
+ edges: Array<{
15
+ remoteConfig: RemoteConfig;
16
+ }> | null;
17
+ };
18
+ }
19
+ export declare function parseRemoteConfig(remoteConfig: RemoteConfig): ConfigFileOptions | undefined;
20
+ export declare function swallowMissingConfigFileException<T>(error: GithubV4Exception<T>): T;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.swallowMissingConfigFileException = exports.parseRemoteConfig = exports.RemoteConfigHistoryFragment = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const readConfigFile_1 = require("../options/config/readConfigFile");
9
+ const logger_1 = require("./logger");
10
+ exports.RemoteConfigHistoryFragment = (0, graphql_tag_1.default) `
11
+ fragment RemoteConfigHistoryFragment on Commit {
12
+ remoteConfigHistory: history(first: 1, path: ".backportrc.json") {
13
+ edges {
14
+ remoteConfig: node {
15
+ committedDate
16
+ file(path: ".backportrc.json") {
17
+ ... on TreeEntry {
18
+ object {
19
+ ... on Blob {
20
+ text
21
+ }
22
+ }
23
+ }
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
29
+ `;
30
+ function parseRemoteConfig(remoteConfig) {
31
+ try {
32
+ return (0, readConfigFile_1.withConfigMigrations)(JSON.parse(remoteConfig.file.object.text));
33
+ }
34
+ catch (e) {
35
+ logger_1.logger.info('Parsing remote config failed', e);
36
+ return;
37
+ }
38
+ }
39
+ exports.parseRemoteConfig = parseRemoteConfig;
40
+ function swallowMissingConfigFileException(error) {
41
+ const { data, errors } = error.githubResponse.data;
42
+ const missingConfigError = errors?.some((error) => {
43
+ return error.path.includes('remoteConfig') && error.type === 'NOT_FOUND';
44
+ });
45
+ // swallow error if it's just the config file that's missing
46
+ if (missingConfigError && data != null) {
47
+ return data;
48
+ }
49
+ // Throw unexpected error
50
+ throw error;
51
+ }
52
+ exports.swallowMissingConfigFileException = swallowMissingConfigFileException;
@@ -10,4 +10,7 @@ export declare type ExpectedTargetPullRequest = {
10
10
  message: string;
11
11
  };
12
12
  };
13
- export declare function getExpectedTargetPullRequests(sourceCommit: SourceCommitWithTargetPullRequest, branchLabelMapping: ValidConfigOptions['branchLabelMapping']): ExpectedTargetPullRequest[];
13
+ export declare function getExpectedTargetPullRequests({ sourceCommit, latestBranchLabelMapping, }: {
14
+ sourceCommit: SourceCommitWithTargetPullRequest;
15
+ latestBranchLabelMapping: ValidConfigOptions['branchLabelMapping'];
16
+ }): ExpectedTargetPullRequest[];
@@ -4,8 +4,12 @@ exports.getExpectedTargetPullRequests = void 0;
4
4
  const lodash_1 = require("lodash");
5
5
  const filterEmpty_1 = require("../../utils/filterEmpty");
6
6
  const commitFormatters_1 = require("../github/commitFormatters");
7
- function getExpectedTargetPullRequests(sourceCommit, branchLabelMapping) {
7
+ const remoteConfig_1 = require("../remoteConfig");
8
+ function getExpectedTargetPullRequests({ sourceCommit, latestBranchLabelMapping, }) {
8
9
  const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
10
+ const remoteConfig = sourcePullRequest?.mergeCommit.remoteConfigHistory.edges?.[0]?.remoteConfig;
11
+ const branchLabelMapping = (remoteConfig && (0, remoteConfig_1.parseRemoteConfig)(remoteConfig)?.branchLabelMapping) ??
12
+ latestBranchLabelMapping;
9
13
  // if there is no source pull request the commit was pushed directly to the source branch
10
14
  // in that case there will be no labels, and thus not possible to deduce the expected target branches
11
15
  if (!sourcePullRequest) {
@@ -1,6 +1,10 @@
1
1
  import { SourceCommitWithTargetPullRequest } from './parseSourceCommit';
2
2
  export declare function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems, }: {
3
3
  sourceCommit: {
4
+ remoteConfig?: {
5
+ branchLabelMapping: Record<string, string>;
6
+ committedDate: string;
7
+ };
4
8
  sha?: string;
5
9
  message: string;
6
10
  commitedDate?: string;
@@ -12,15 +12,29 @@ function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems =
12
12
  committedDate: sourceCommit.commitedDate ?? '2021-12-22T00:00:00Z',
13
13
  sha: sourceCommit.sha ?? defaultSourceCommitSha,
14
14
  message: sourceCommit.message,
15
+ associatedPullRequests: { edges: null },
15
16
  };
16
17
  if (!sourcePullRequest) {
17
- return {
18
- ...baseMockCommit,
19
- associatedPullRequests: {
20
- edges: null,
21
- },
22
- };
18
+ return baseMockCommit;
23
19
  }
20
+ const remoteConfigHistory = sourceCommit.remoteConfig
21
+ ? {
22
+ edges: [
23
+ {
24
+ remoteConfig: {
25
+ committedDate: sourceCommit.remoteConfig.committedDate,
26
+ file: {
27
+ object: {
28
+ text: JSON.stringify({
29
+ branchLabelMapping: sourceCommit.remoteConfig.branchLabelMapping,
30
+ }),
31
+ },
32
+ },
33
+ },
34
+ },
35
+ ],
36
+ }
37
+ : { edges: [] };
24
38
  return {
25
39
  ...baseMockCommit,
26
40
  associatedPullRequests: {
@@ -28,6 +42,7 @@ function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems =
28
42
  {
29
43
  node: {
30
44
  mergeCommit: {
45
+ remoteConfigHistory,
31
46
  sha: sourceCommit.sha ?? defaultSourceCommitSha,
32
47
  message: sourceCommit.message,
33
48
  },
@@ -1,4 +1,5 @@
1
1
  import { ValidConfigOptions } from '../../options/options';
2
+ import { RemoteConfigHistory } from '../remoteConfig';
2
3
  import { ExpectedTargetPullRequest } from './getExpectedTargetPullRequests';
3
4
  export interface Commit {
4
5
  sourceCommit: {
@@ -27,6 +28,7 @@ export interface SourcePullRequestNode {
27
28
  }[];
28
29
  };
29
30
  mergeCommit: {
31
+ remoteConfigHistory: RemoteConfigHistory['remoteConfigHistory'];
30
32
  sha: string;
31
33
  message: string;
32
34
  };
@@ -94,11 +96,8 @@ export declare function parseSourceCommit({ sourceCommit, options, }: {
94
96
  sourceCommit: SourceCommitWithTargetPullRequest;
95
97
  options: {
96
98
  branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
97
- historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
98
99
  sourceBranch: string;
99
100
  };
100
101
  }): Commit;
101
- export declare const sourceCommitWithTargetPullRequestFragment: {
102
- source: string;
103
- };
102
+ export declare const SourceCommitWithTargetPullRequestFragment: import("graphql").DocumentNode;
104
103
  export {};
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sourceCommitWithTargetPullRequestFragment = exports.parseSourceCommit = void 0;
4
- const lodash_1 = require("lodash");
6
+ exports.SourceCommitWithTargetPullRequestFragment = exports.parseSourceCommit = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const remoteConfig_1 = require("../remoteConfig");
5
9
  const getExpectedTargetPullRequests_1 = require("./getExpectedTargetPullRequests");
6
10
  function parseSourceCommit({ sourceCommit, options, }) {
7
11
  const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
8
- // use info from associated pull request if available. Fall back to commit info
9
- const sourceBranch = sourcePullRequest?.baseRefName ?? options.sourceBranch;
10
- const branchLabelMapping = getBranchLabelMappingForCommit(sourceCommit, options.branchLabelMapping, options.historicalBranchLabelMappings);
11
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)(sourceCommit, branchLabelMapping);
12
12
  return {
13
13
  sourceCommit: {
14
14
  committedDate: sourceCommit.committedDate,
@@ -25,77 +25,79 @@ function parseSourceCommit({ sourceCommit, options, }) {
25
25
  },
26
26
  }
27
27
  : undefined,
28
- sourceBranch,
29
- expectedTargetPullRequests,
28
+ sourceBranch: sourcePullRequest?.baseRefName ?? options.sourceBranch,
29
+ expectedTargetPullRequests: (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
30
+ sourceCommit,
31
+ latestBranchLabelMapping: options.branchLabelMapping,
32
+ }),
30
33
  };
31
34
  }
32
35
  exports.parseSourceCommit = parseSourceCommit;
33
- exports.sourceCommitWithTargetPullRequestFragment = {
34
- source: /* GraphQL */ `
35
- fragment SourceCommitWithTargetPullRequest on Commit {
36
- # Source Commit
37
- repository {
38
- name
39
- owner {
40
- login
41
- }
36
+ exports.SourceCommitWithTargetPullRequestFragment = (0, graphql_tag_1.default) `
37
+ fragment SourceCommitWithTargetPullRequestFragment on Commit {
38
+ # Source Commit
39
+ repository {
40
+ name
41
+ owner {
42
+ login
42
43
  }
43
- sha: oid
44
- message
45
- committedDate
44
+ }
45
+ sha: oid
46
+ message
47
+ committedDate
46
48
 
47
- # Source pull request: PR where source commit was merged in
48
- associatedPullRequests(first: 1) {
49
- edges {
50
- node {
51
- url
52
- number
53
- labels(first: 50) {
54
- nodes {
55
- name
56
- }
49
+ # Source pull request: PR where source commit was merged in
50
+ associatedPullRequests(first: 1) {
51
+ edges {
52
+ node {
53
+ url
54
+ number
55
+ labels(first: 50) {
56
+ nodes {
57
+ name
57
58
  }
58
- baseRefName
59
+ }
60
+ baseRefName
59
61
 
60
- # source merge commit (the commit that actually went into the source branch)
61
- mergeCommit {
62
- sha: oid
63
- message
64
- }
62
+ # source merge commit (the commit that actually went into the source branch)
63
+ mergeCommit {
64
+ ...RemoteConfigHistoryFragment
65
+ sha: oid
66
+ message
67
+ }
65
68
 
66
- # (possible) backport pull requests referenced in the source pull request
67
- timelineItems(last: 20, itemTypes: CROSS_REFERENCED_EVENT) {
68
- edges {
69
- node {
70
- ... on CrossReferencedEvent {
71
- targetPullRequest: source {
72
- __typename
69
+ # (possible) backport pull requests referenced in the source pull request
70
+ timelineItems(last: 20, itemTypes: CROSS_REFERENCED_EVENT) {
71
+ edges {
72
+ node {
73
+ ... on CrossReferencedEvent {
74
+ targetPullRequest: source {
75
+ __typename
73
76
 
74
- # Target PRs (backport PRs)
75
- ... on PullRequest {
76
- # target merge commit: the backport commit that was merged into the target branch
77
- targetMergeCommit: mergeCommit {
78
- sha: oid
79
- message
80
- }
81
- repository {
82
- name
83
- owner {
84
- login
85
- }
77
+ # Target PRs (backport PRs)
78
+ ... on PullRequest {
79
+ # target merge commit: the backport commit that was merged into the target branch
80
+ targetMergeCommit: mergeCommit {
81
+ sha: oid
82
+ message
83
+ }
84
+ repository {
85
+ name
86
+ owner {
87
+ login
86
88
  }
87
- url
88
- title
89
- state
90
- baseRefName
91
- number
92
- commits(first: 20) {
93
- edges {
94
- node {
95
- targetCommit: commit {
96
- message
97
- sha: oid
98
- }
89
+ }
90
+ url
91
+ title
92
+ state
93
+ baseRefName
94
+ number
95
+ commits(first: 20) {
96
+ edges {
97
+ node {
98
+ targetCommit: commit {
99
+ message
100
+ sha: oid
99
101
  }
100
102
  }
101
103
  }
@@ -109,13 +111,7 @@ exports.sourceCommitWithTargetPullRequestFragment = {
109
111
  }
110
112
  }
111
113
  }
112
- `,
113
- };
114
- function getBranchLabelMappingForCommit(sourceCommit, branchLabelMapping, historicalBranchLabelMappings = []) {
115
- if ((0, lodash_1.isEmpty)(historicalBranchLabelMappings)) {
116
- return branchLabelMapping;
117
- }
118
- const match = historicalBranchLabelMappings.find((branchLabelMapping) => sourceCommit.committedDate > branchLabelMapping.committedDate);
119
- return (match?.branchLabelMapping ??
120
- historicalBranchLabelMappings[0].branchLabelMapping);
121
- }
114
+ }
115
+
116
+ ${remoteConfig_1.RemoteConfigHistoryFragment}
117
+ `;
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.cherrypickAndCreateTargetPullRequest = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const lodash_1 = require("lodash");
9
- const ora = require("ora");
10
9
  const HandledError_1 = require("../services/HandledError");
11
10
  const child_process_promisified_1 = require("../services/child-process-promisified");
12
11
  const env_1 = require("../services/env");
@@ -21,10 +20,22 @@ const logger_1 = require("../services/logger");
21
20
  const prompts_1 = require("../services/prompts");
22
21
  const sequentially_1 = require("../services/sequentially");
23
22
  const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
23
+ const ora_1 = require("./ora");
24
24
  async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBranch, }) {
25
25
  const backportBranch = getBackportBranchName(targetBranch, commits);
26
26
  const repoForkOwner = (0, git_1.getRepoForkOwner)(options);
27
27
  (0, logger_1.consoleLog)(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
28
+ await (0, git_1.createBackportBranch)({ options, targetBranch, backportBranch });
29
+ await (0, sequentially_1.sequentially)(commits, (commit) => waitForCherrypick(options, commit, targetBranch));
30
+ if (options.resetAuthor) {
31
+ await (0, git_1.setCommitAuthor)(options, options.authenticatedUsername);
32
+ }
33
+ if (options.dryRun) {
34
+ (0, ora_1.ora)(options.ci).succeed('Dry run');
35
+ return { url: 'https://localhost/dry-run', didUpdate: false, number: 1337 };
36
+ }
37
+ await (0, git_1.pushBackportBranch)({ options, backportBranch });
38
+ await (0, git_1.deleteBackportBranch)({ options, backportBranch });
28
39
  const prPayload = {
29
40
  owner: options.repoOwner,
30
41
  repo: options.repoName,
@@ -33,13 +44,7 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
33
44
  head: `${repoForkOwner}:${backportBranch}`,
34
45
  base: targetBranch, // eg. 7.x
35
46
  };
36
- const targetPullRequest = await backportViaFilesystem({
37
- options,
38
- prPayload,
39
- targetBranch,
40
- backportBranch,
41
- commits,
42
- });
47
+ const targetPullRequest = await (0, createPullRequest_1.createPullRequest)({ options, prPayload });
43
48
  // add assignees to target pull request
44
49
  const assignees = options.autoAssign
45
50
  ? [options.authenticatedUsername]
@@ -72,17 +77,6 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
72
77
  return targetPullRequest;
73
78
  }
74
79
  exports.cherrypickAndCreateTargetPullRequest = cherrypickAndCreateTargetPullRequest;
75
- async function backportViaFilesystem({ options, prPayload, commits, targetBranch, backportBranch, }) {
76
- logger_1.logger.info('Backporting via filesystem');
77
- await (0, git_1.createBackportBranch)({ options, targetBranch, backportBranch });
78
- await (0, sequentially_1.sequentially)(commits, (commit) => waitForCherrypick(options, commit, targetBranch));
79
- if (options.resetAuthor) {
80
- await (0, git_1.setCommitAuthor)(options, options.authenticatedUsername);
81
- }
82
- await (0, git_1.pushBackportBranch)({ options, backportBranch });
83
- await (0, git_1.deleteBackportBranch)({ options, backportBranch });
84
- return (0, createPullRequest_1.createPullRequest)({ options, prPayload });
85
- }
86
80
  /*
87
81
  * Returns the name of the backport branch without remote name
88
82
  *
@@ -103,7 +97,7 @@ function getBackportBranchName(targetBranch, commits) {
103
97
  async function waitForCherrypick(options, commit, targetBranch) {
104
98
  const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))}`;
105
99
  const mergedTargetPullRequest = commit.expectedTargetPullRequests.find((pr) => pr.state === 'MERGED' && pr.branch === targetBranch);
106
- const cherrypickSpinner = ora(spinnerText).start();
100
+ const cherrypickSpinner = (0, ora_1.ora)(options.ci, spinnerText).start();
107
101
  let conflictingFiles;
108
102
  let unstagedFiles;
109
103
  let needsResolving;
@@ -124,7 +118,7 @@ async function waitForCherrypick(options, commit, targetBranch) {
124
118
  }
125
119
  // resolve conflicts automatically
126
120
  if (options.autoFixConflicts) {
127
- const autoResolveSpinner = ora('Attempting to resolve conflicts automatically').start();
121
+ const autoResolveSpinner = (0, ora_1.ora)(options.ci, 'Attempting to resolve conflicts automatically').start();
128
122
  const repoPath = (0, env_1.getRepoPath)(options);
129
123
  const didAutoFix = await options.autoFixConflicts({
130
124
  files: conflictingFiles.map((f) => f.absolute),
@@ -171,7 +165,7 @@ async function waitForCherrypick(options, commit, targetBranch) {
171
165
  unstagedFiles,
172
166
  });
173
167
  // Conflicts should be resolved and files staged at this point
174
- const stagingSpinner = ora(`Finalizing cherrypick`).start();
168
+ const stagingSpinner = (0, ora_1.ora)(options.ci, `Finalizing cherrypick`).start();
175
169
  try {
176
170
  // Run `git commit`
177
171
  await (0, git_1.commitChanges)(commit, options);
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getCommits = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
- const ora_1 = __importDefault(require("ora"));
9
8
  const HandledError_1 = require("../services/HandledError");
10
9
  const commitFormatters_1 = require("../services/github/commitFormatters");
11
10
  const fetchCommitByPullNumber_1 = require("../services/github/v4/fetchCommits/fetchCommitByPullNumber");
@@ -13,6 +12,7 @@ const fetchCommitBySha_1 = require("../services/github/v4/fetchCommits/fetchComm
13
12
  const fetchCommitsByAuthor_1 = require("../services/github/v4/fetchCommits/fetchCommitsByAuthor");
14
13
  const fetchPullRequestBySearchQuery_1 = require("../services/github/v4/fetchCommits/fetchPullRequestBySearchQuery");
15
14
  const prompts_1 = require("../services/prompts");
15
+ const ora_1 = require("./ora");
16
16
  function getOraPersistsOption(question, answer) {
17
17
  return {
18
18
  symbol: chalk_1.default.green('?'),
@@ -20,13 +20,15 @@ function getOraPersistsOption(question, answer) {
20
20
  };
21
21
  }
22
22
  async function getCommits(options) {
23
- const spinner = (0, ora_1.default)().start();
23
+ const spinner = (0, ora_1.ora)(options.ci).start();
24
24
  try {
25
25
  if (options.sha) {
26
- spinner.text = `Loading commit "${(0, commitFormatters_1.getShortSha)(options.sha)}"`;
27
- const commit = await (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha: options.sha });
28
- spinner.stopAndPersist(getOraPersistsOption('Select commit', commit.sourceCommit.message));
29
- return [commit];
26
+ const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
27
+ // TODO: use Intl.ListFormat to format the sha's
28
+ spinner.text = `Loading commit "${shas.map(commitFormatters_1.getShortSha)}"`;
29
+ const commits = await Promise.all(shas.map((sha) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha })));
30
+ spinner.stopAndPersist(getOraPersistsOption('Select commit', commits.map((commit) => commit.sourceCommit.message).join(', ')));
31
+ return commits;
30
32
  }
31
33
  if (options.pullNumber) {
32
34
  spinner.text = `Loading pull request #${options.pullNumber}`;
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.maybeSetupRepo = void 0;
4
- const promises_1 = require("fs/promises");
5
4
  const del = require("del");
6
5
  const ora = require("ora");
7
6
  const env_1 = require("../services/env");
8
7
  const git_1 = require("../services/git");
9
8
  async function maybeSetupRepo(options) {
10
9
  const repoPath = (0, env_1.getRepoPath)(options);
11
- const isAlreadyCloned = await getIsRepoCloned(repoPath);
10
+ const isAlreadyCloned = await getIsRepoCloned(options);
12
11
  // clone repo if folder does not already exists
13
12
  if (!isAlreadyCloned) {
14
13
  const spinner = ora().start();
@@ -19,6 +18,7 @@ async function maybeSetupRepo(options) {
19
18
  : sourcePath;
20
19
  const spinnerCloneText = `Cloning repository from ${sourcePathHumanReadable} (one-time operation)`;
21
20
  spinner.text = `0% ${spinnerCloneText}`;
21
+ await del(repoPath, { force: true });
22
22
  await (0, git_1.cloneRepo)({ sourcePath, targetPath: repoPath }, (progress) => {
23
23
  spinner.text = `${progress}% ${spinnerCloneText}`;
24
24
  });
@@ -26,7 +26,7 @@ async function maybeSetupRepo(options) {
26
26
  }
27
27
  catch (e) {
28
28
  spinner.fail();
29
- await del(repoPath);
29
+ await del(repoPath, { force: true });
30
30
  throw e;
31
31
  }
32
32
  }
@@ -42,15 +42,8 @@ async function maybeSetupRepo(options) {
42
42
  }
43
43
  }
44
44
  exports.maybeSetupRepo = maybeSetupRepo;
45
- async function getIsRepoCloned(path) {
46
- try {
47
- const stats = await (0, promises_1.stat)(path);
48
- return stats.isDirectory();
49
- }
50
- catch (e) {
51
- if (e.code === 'ENOENT') {
52
- return false;
53
- }
54
- throw e;
55
- }
45
+ async function getIsRepoCloned(options) {
46
+ const repoPath = (0, env_1.getRepoPath)(options);
47
+ const projectRoot = await (0, git_1.getGitProjectRoot)(options);
48
+ return repoPath === projectRoot;
56
49
  }