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
@@ -10,5 +10,6 @@ export declare type BackportResponse = {
10
10
  status: 'failure';
11
11
  commits: Commit[];
12
12
  error: Error | HandledError;
13
+ errorMessage: string;
13
14
  };
14
15
  export declare function backportRun(processArgs: string[], optionsFromModule?: ConfigFileOptions): Promise<BackportResponse>;
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.backportRun = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
- const ora_1 = __importDefault(require("ora"));
9
8
  const yargs_parser_1 = __importDefault(require("yargs-parser"));
10
9
  const options_1 = require("./options/options");
11
10
  const runSequentially_1 = require("./runSequentially");
@@ -16,13 +15,14 @@ const apiRequestV4_1 = require("./services/github/v4/apiRequestV4");
16
15
  const logger_1 = require("./services/logger");
17
16
  const getCommits_1 = require("./ui/getCommits");
18
17
  const getTargetBranches_1 = require("./ui/getTargetBranches");
18
+ const ora_1 = require("./ui/ora");
19
19
  async function backportRun(processArgs, optionsFromModule = {}) {
20
20
  const argv = (0, yargs_parser_1.default)(processArgs);
21
21
  const ci = argv.ci ?? optionsFromModule.ci;
22
22
  const logFilePath = argv.logFilePath ?? optionsFromModule.logFilePath;
23
23
  (0, logger_1.initLogger)({ ci, logFilePath });
24
24
  // don't show spinner for yargs commands that exit the process without stopping the spinner first
25
- const spinner = (0, ora_1.default)();
25
+ const spinner = (0, ora_1.ora)(ci);
26
26
  if (!argv.help && !argv.version && !argv.v) {
27
27
  spinner.start('Initializing...');
28
28
  }
@@ -55,6 +55,7 @@ async function backportRun(processArgs, optionsFromModule = {}) {
55
55
  status: 'failure',
56
56
  commits,
57
57
  error: e,
58
+ errorMessage: e.message,
58
59
  };
59
60
  if (options) {
60
61
  await (0, createStatusComment_1.createStatusComment)({
@@ -1,7 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
3
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ const yargs_parser_1 = __importDefault(require("yargs-parser"));
4
8
  const backportRun_1 = require("./backportRun");
5
9
  const processArgs = process.argv.slice(2);
6
10
  // this is the entrypoint when running from command line
7
- (0, backportRun_1.backportRun)(processArgs);
11
+ (0, backportRun_1.backportRun)(processArgs).then((backportResponse) => {
12
+ const argv = (0, yargs_parser_1.default)(processArgs);
13
+ const ci = argv.ci;
14
+ if (ci) {
15
+ // eslint-disable-next-line no-console
16
+ console.log(JSON.stringify(backportResponse));
17
+ }
18
+ });
@@ -1,8 +1,9 @@
1
1
  import { ConfigFileOptions } from './options/ConfigOptions';
2
2
  import { ValidConfigOptions } from './options/options';
3
+ import { Commit } from './services/sourceCommit/parseSourceCommit';
3
4
  export { BackportResponse } from './backportRun';
4
5
  export { ConfigFileOptions } from './options/ConfigOptions';
5
- export { Commit } from './services/sourceCommit/parseSourceCommit';
6
+ export { Commit };
6
7
  export { fetchRemoteProjectConfig as getRemoteProjectConfig } from './services/github/v4/fetchRemoteProjectConfig';
7
8
  export { getGlobalConfig as getLocalGlobalConfig } from './options/config/globalConfig';
8
9
  export declare function backportRun(options: ConfigFileOptions, processArgs?: string[]): Promise<import("./backportRun").BackportResponse>;
@@ -14,9 +15,9 @@ export declare function getCommits(options: {
14
15
  branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
15
16
  githubApiBaseUrlV4?: string;
16
17
  pullNumber?: number;
17
- sha?: string;
18
+ sha?: string | string[];
18
19
  skipRemoteConfig?: boolean;
19
20
  sourceBranch?: string;
20
21
  dateUntil?: string;
21
22
  dateSince?: string;
22
- }): Promise<import("./services/sourceCommit/parseSourceCommit").Commit[]>;
23
+ }): Promise<Commit[]>;
@@ -37,13 +37,8 @@ async function getCommits(options) {
37
37
  ];
38
38
  }
39
39
  if (options.sha) {
40
- return [
41
- await (0, fetchCommitBySha_1.fetchCommitBySha)({
42
- ...optionsFromGithub,
43
- ...options,
44
- sha: options.sha,
45
- }),
46
- ];
40
+ const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
41
+ return Promise.all(shas.map((sha) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...optionsFromGithub, ...options, sha })));
47
42
  }
48
43
  return (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
49
44
  ...optionsFromGithub,
@@ -45,7 +45,7 @@ declare type Options = Partial<{
45
45
  repoOwner: string;
46
46
  resetAuthor: boolean;
47
47
  reviewers: string[];
48
- sha: string;
48
+ sha: string | string[];
49
49
  skipRemoteConfig: boolean;
50
50
  sourceBranch: string;
51
51
  sourcePRLabels: string[];
@@ -5,6 +5,7 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
5
5
  fork?: boolean | undefined;
6
6
  dir?: string | undefined;
7
7
  verbose?: boolean | undefined;
8
+ logFilePath?: string | undefined;
8
9
  accessToken?: string | undefined;
9
10
  author?: string | null | undefined;
10
11
  autoAssign?: boolean | undefined;
@@ -15,12 +16,12 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
15
16
  cherrypickRef?: boolean | undefined;
16
17
  configFile?: string | undefined;
17
18
  details?: boolean | undefined;
19
+ dryRun?: boolean | undefined;
18
20
  editor?: string | undefined;
19
21
  skipRemoteConfig?: boolean | undefined;
20
22
  gitHostname?: string | undefined;
21
23
  githubApiBaseUrlV3?: string | undefined;
22
24
  githubApiBaseUrlV4?: string | undefined;
23
- logFilePath?: string | undefined;
24
25
  mainline?: number | undefined;
25
26
  maxNumber?: number | undefined;
26
27
  multipleBranches?: boolean | undefined;
@@ -83,6 +83,10 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
83
83
  .option('details', {
84
84
  description: 'Show details about each commit',
85
85
  type: 'boolean',
86
+ })
87
+ .option('dryRun', {
88
+ description: 'Run backport locally without pushing to Github',
89
+ type: 'boolean',
86
90
  })
87
91
  .option('editor', {
88
92
  description: 'Editor to be opened during conflict resolution',
@@ -45,7 +45,7 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
45
45
  repoOwner?: string | undefined;
46
46
  resetAuthor?: boolean | undefined;
47
47
  reviewers?: string[] | undefined;
48
- sha?: string | undefined;
48
+ sha?: string | string[] | undefined;
49
49
  skipRemoteConfig?: boolean | undefined;
50
50
  sourceBranch?: string | undefined;
51
51
  sourcePRLabels?: string[] | undefined;
@@ -5,6 +5,7 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
5
5
  dir?: string | undefined;
6
6
  help?: boolean | undefined;
7
7
  verbose?: boolean | undefined;
8
+ logFilePath?: string | undefined;
8
9
  accessToken?: string | undefined;
9
10
  author?: string | null | undefined;
10
11
  autoAssign?: boolean | undefined;
@@ -20,7 +21,6 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
20
21
  gitHostname?: string | undefined;
21
22
  githubApiBaseUrlV3?: string | undefined;
22
23
  githubApiBaseUrlV4?: string | undefined;
23
- logFilePath?: string | undefined;
24
24
  maxNumber?: number | undefined;
25
25
  multiple?: boolean | undefined;
26
26
  multipleBranches?: boolean | undefined;
@@ -30,7 +30,7 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
30
30
  prTitle?: string | undefined;
31
31
  prFilter?: string | undefined;
32
32
  pullNumber?: number | undefined;
33
- sha?: string | undefined;
33
+ sha?: string | string[] | undefined;
34
34
  resetAuthor?: boolean | undefined;
35
35
  repoOwner?: string | undefined;
36
36
  repoName?: string | undefined;
@@ -7,6 +7,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
7
7
  fork: boolean;
8
8
  dir?: string | undefined;
9
9
  verbose: boolean;
10
+ logFilePath?: string | undefined;
10
11
  author: string | null;
11
12
  autoAssign: boolean;
12
13
  assignees: string[];
@@ -16,12 +17,12 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
16
17
  cherrypickRef: boolean;
17
18
  configFile?: string | undefined;
18
19
  details: boolean;
20
+ dryRun?: boolean | undefined;
19
21
  editor?: string | undefined;
20
22
  skipRemoteConfig?: boolean | undefined;
21
23
  gitHostname: string;
22
24
  githubApiBaseUrlV3?: string | undefined;
23
25
  githubApiBaseUrlV4?: string | undefined;
24
- logFilePath?: string | undefined;
25
26
  mainline?: number | undefined;
26
27
  maxNumber: number;
27
28
  multipleBranches: boolean;
@@ -31,7 +32,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
31
32
  prTitle?: string | undefined;
32
33
  prFilter?: string | undefined;
33
34
  pullNumber?: number | undefined;
34
- sha?: string | undefined;
35
+ sha?: string | string[] | undefined;
35
36
  resetAuthor: boolean;
36
37
  sourceBranch: string;
37
38
  username?: string | undefined;
@@ -44,10 +45,6 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
44
45
  targetBranches: string[];
45
46
  targetPRLabels: string[];
46
47
  publishStatusComment: boolean;
47
- historicalBranchLabelMappings: {
48
- branchLabelMapping: Record<string, string>;
49
- committedDate: string;
50
- }[];
51
48
  autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
52
49
  files: string[];
53
50
  directory: string;
@@ -26,6 +26,7 @@ async function runSequentially({ options, commits, targetBranches, }) {
26
26
  });
27
27
  }
28
28
  catch (e) {
29
+ process.exitCode = 1;
29
30
  results.push({
30
31
  targetBranch,
31
32
  status: 'failure',
@@ -16,9 +16,11 @@ function getMessage(errorContext) {
16
16
  }
17
17
  class HandledError extends Error {
18
18
  constructor(errorContext) {
19
- super(getMessage(errorContext));
19
+ const message = getMessage(errorContext);
20
+ super(message);
20
21
  Error.captureStackTrace(this, HandledError);
21
22
  this.name = 'HandledError';
23
+ this.message = message;
22
24
  if (typeof errorContext !== 'string') {
23
25
  this.errorContext = errorContext;
24
26
  }
@@ -28,6 +28,8 @@ export declare function getIsCommitInBranch(options: ValidConfigOptions, commitS
28
28
  export declare function deleteRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
29
29
  export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
30
30
  export declare function fetchBranch(options: ValidConfigOptions, branch: string): Promise<void>;
31
+ export declare function getIsMergeCommit(options: ValidConfigOptions, sha: string): Promise<boolean>;
32
+ export declare function getCommitsInMergeCommit(options: ValidConfigOptions, sha: string): Promise<string[]>;
31
33
  export declare function cherrypick(options: ValidConfigOptions, sha: string, mergedTargetPullRequest?: ExpectedTargetPullRequest): Promise<{
32
34
  conflictingFiles: {
33
35
  absolute: string;
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRoot = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
3
+ exports.getSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.getCommitsInMergeCommit = exports.getIsMergeCommit = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRoot = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
7
4
  const path_1 = require("path");
8
5
  const lodash_1 = require("lodash");
9
- const ora_1 = __importDefault(require("ora"));
6
+ const ora_1 = require("../ui/ora");
10
7
  const filterEmpty_1 = require("../utils/filterEmpty");
11
8
  const HandledError_1 = require("./HandledError");
12
9
  const child_process_promisified_1 = require("./child-process-promisified");
@@ -159,10 +156,50 @@ async function fetchBranch(options, branch) {
159
156
  });
160
157
  }
161
158
  exports.fetchBranch = fetchBranch;
159
+ async function getIsMergeCommit(options, sha) {
160
+ const res = await (0, child_process_promisified_1.exec)(`git rev-list -1 --merges ${sha}~1..${sha}`, {
161
+ cwd: (0, env_1.getRepoPath)(options),
162
+ });
163
+ return res.stdout !== '';
164
+ }
165
+ exports.getIsMergeCommit = getIsMergeCommit;
166
+ async function getCommitsInMergeCommit(options, sha) {
167
+ try {
168
+ const res = await (0, child_process_promisified_1.exec)(`git --no-pager log ${sha}^1..${sha}^2 --pretty=format:"%H"`, {
169
+ cwd: (0, env_1.getRepoPath)(options),
170
+ });
171
+ return res.stdout.split('\n');
172
+ }
173
+ catch (e) {
174
+ // swallow error
175
+ if (e.code === 128) {
176
+ return [];
177
+ }
178
+ throw e;
179
+ }
180
+ }
181
+ exports.getCommitsInMergeCommit = getCommitsInMergeCommit;
162
182
  async function cherrypick(options, sha, mergedTargetPullRequest) {
163
183
  const mainlinArg = options.mainline != undefined ? ` --mainline ${options.mainline}` : '';
164
184
  const cherrypickRefArg = options.cherrypickRef === false ? '' : ' -x';
165
- const cmd = `git cherry-pick${cherrypickRefArg}${mainlinArg} ${sha}`;
185
+ let shaOrRange = sha;
186
+ if (!options.mainline) {
187
+ try {
188
+ const isMergeCommit = await getIsMergeCommit(options, sha);
189
+ if (isMergeCommit) {
190
+ const shas = await getCommitsInMergeCommit(options, sha);
191
+ shaOrRange = `${(0, lodash_1.last)(shas)}^..${(0, lodash_1.first)(shas)}`;
192
+ }
193
+ }
194
+ catch (e) {
195
+ // swallow error if it's a known error
196
+ // exit 128 will happen for many things, among others when the cherrypicked commit is empty
197
+ if (e.code !== 128) {
198
+ throw e;
199
+ }
200
+ }
201
+ }
202
+ const cmd = `git cherry-pick${cherrypickRefArg}${mainlinArg} ${shaOrRange}`;
166
203
  try {
167
204
  await (0, child_process_promisified_1.exec)(cmd, { cwd: (0, env_1.getRepoPath)(options) });
168
205
  return { conflictingFiles: [], unstagedFiles: [], needsResolving: false };
@@ -269,7 +306,7 @@ async function getUnstagedFiles(options) {
269
306
  }
270
307
  exports.getUnstagedFiles = getUnstagedFiles;
271
308
  async function setCommitAuthor(options, author) {
272
- const spinner = (0, ora_1.default)(`Changing author to "${author}"`).start();
309
+ const spinner = (0, ora_1.ora)(options.ci, `Changing author to "${author}"`).start();
273
310
  try {
274
311
  const res = await (0, child_process_promisified_1.exec)(`git commit --amend --no-edit --author "${author} <${author}@users.noreply.github.com>"`, { cwd: (0, env_1.getRepoPath)(options) });
275
312
  spinner.succeed();
@@ -285,7 +322,7 @@ exports.setCommitAuthor = setCommitAuthor;
285
322
  // ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
286
323
  // master -> backport/7.x/pr-1234 -> 7.x
287
324
  async function createBackportBranch({ options, targetBranch, backportBranch, }) {
288
- const spinner = (0, ora_1.default)('Pulling latest changes').start();
325
+ const spinner = (0, ora_1.ora)(options.ci, 'Pulling latest changes').start();
289
326
  try {
290
327
  const res = await (0, child_process_promisified_1.exec)(`git reset --hard && git clean -d --force && git fetch ${options.repoOwner} ${targetBranch} && git checkout -B ${backportBranch} ${options.repoOwner}/${targetBranch} --no-track`, { cwd: (0, env_1.getRepoPath)(options) });
291
328
  spinner.succeed();
@@ -303,7 +340,7 @@ async function createBackportBranch({ options, targetBranch, backportBranch, })
303
340
  }
304
341
  exports.createBackportBranch = createBackportBranch;
305
342
  async function deleteBackportBranch({ options, backportBranch, }) {
306
- const spinner = (0, ora_1.default)().start();
343
+ const spinner = (0, ora_1.ora)(options.ci).start();
307
344
  await (0, child_process_promisified_1.exec)(`git reset --hard && git checkout ${options.sourceBranch} && git branch -D ${backportBranch}`, { cwd: (0, env_1.getRepoPath)(options) });
308
345
  spinner.stop();
309
346
  }
@@ -317,7 +354,7 @@ function getRepoForkOwner(options) {
317
354
  exports.getRepoForkOwner = getRepoForkOwner;
318
355
  async function pushBackportBranch({ options, backportBranch, }) {
319
356
  const repoForkOwner = getRepoForkOwner(options);
320
- const spinner = (0, ora_1.default)(`Pushing branch "${repoForkOwner}:${backportBranch}"`).start();
357
+ const spinner = (0, ora_1.ora)(options.ci, `Pushing branch "${repoForkOwner}:${backportBranch}"`).start();
321
358
  try {
322
359
  const res = await (0, child_process_promisified_1.exec)(`git push ${repoForkOwner} ${backportBranch}:${backportBranch} --force`, { cwd: (0, env_1.getRepoPath)(options) });
323
360
  spinner.succeed();
@@ -1,2 +1,2 @@
1
1
  import { ValidConfigOptions } from '../../../options/options';
2
- export declare function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, }: ValidConfigOptions, pullNumber: number, assignees: string[]): Promise<void>;
2
+ export declare function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, ci, }: ValidConfigOptions, pullNumber: number, assignees: string[]): Promise<void>;
@@ -1,18 +1,15 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.addAssigneesToPullRequest = void 0;
7
4
  const rest_1 = require("@octokit/rest");
8
- const ora_1 = __importDefault(require("ora"));
5
+ const ora_1 = require("../../../ui/ora");
9
6
  const logger_1 = require("../../logger");
10
- async function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, }, pullNumber, assignees) {
7
+ async function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, ci, }, pullNumber, assignees) {
11
8
  const text = autoAssign
12
9
  ? `Self-assigning to #${pullNumber}`
13
10
  : `Adding assignees to #${pullNumber}: ${assignees.join(', ')}`;
14
11
  logger_1.logger.info(text);
15
- const spinner = (0, ora_1.default)(text).start();
12
+ const spinner = (0, ora_1.ora)(ci, text).start();
16
13
  try {
17
14
  const octokit = new rest_1.Octokit({
18
15
  auth: accessToken,
@@ -1,2 +1,2 @@
1
1
  import { ValidConfigOptions } from '../../../options/options';
2
- export declare function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }: ValidConfigOptions, pullNumber: number, labels: string[]): Promise<void>;
2
+ export declare function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }: ValidConfigOptions, pullNumber: number, labels: string[]): Promise<void>;
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.addLabelsToPullRequest = void 0;
7
4
  const rest_1 = require("@octokit/rest");
8
- const ora_1 = __importDefault(require("ora"));
5
+ const ora_1 = require("../../../ui/ora");
9
6
  const logger_1 = require("../../logger");
10
- async function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }, pullNumber, labels) {
7
+ async function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }, pullNumber, labels) {
11
8
  const text = `Adding labels: ${labels.join(', ')}`;
12
9
  logger_1.logger.info(text);
13
- const spinner = (0, ora_1.default)(text).start();
10
+ const spinner = (0, ora_1.ora)(ci, text).start();
14
11
  try {
15
12
  const octokit = new rest_1.Octokit({
16
13
  auth: accessToken,
@@ -1,2 +1,2 @@
1
1
  import { ValidConfigOptions } from '../../../options/options';
2
- export declare function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }: ValidConfigOptions, pullNumber: number, reviewers: string[]): Promise<void>;
2
+ export declare function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }: ValidConfigOptions, pullNumber: number, reviewers: string[]): Promise<void>;
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.addReviewersToPullRequest = void 0;
7
4
  const rest_1 = require("@octokit/rest");
8
- const ora_1 = __importDefault(require("ora"));
5
+ const ora_1 = require("../../../ui/ora");
9
6
  const logger_1 = require("../../logger");
10
- async function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }, pullNumber, reviewers) {
7
+ async function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }, pullNumber, reviewers) {
11
8
  const text = `Adding reviewers: ${reviewers}`;
12
9
  logger_1.logger.info(text);
13
- const spinner = (0, ora_1.default)(text).start();
10
+ const spinner = (0, ora_1.ora)(ci, text).start();
14
11
  try {
15
12
  const octokit = new rest_1.Octokit({
16
13
  auth: accessToken,
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getTitle = exports.getPullRequestBody = exports.createPullRequest = void 0;
7
4
  const rest_1 = require("@octokit/rest");
8
- const ora_1 = __importDefault(require("ora"));
5
+ const ora_1 = require("../../../ui/ora");
9
6
  const packageVersion_1 = require("../../../utils/packageVersion");
10
7
  const HandledError_1 = require("../../HandledError");
11
8
  const logger_1 = require("../../logger");
@@ -15,7 +12,7 @@ const getGithubV3ErrorMessage_1 = require("./getGithubV3ErrorMessage");
15
12
  async function createPullRequest({ options, prPayload, }) {
16
13
  logger_1.logger.info(`Creating PR with title: "${prPayload.title}". ${prPayload.head} -> ${prPayload.base}`);
17
14
  const { accessToken, githubApiBaseUrlV3 } = options;
18
- const spinner = (0, ora_1.default)(`Creating pull request`).start();
15
+ const spinner = (0, ora_1.ora)(options.ci, `Creating pull request`).start();
19
16
  try {
20
17
  const octokit = new rest_1.Octokit({
21
18
  auth: accessToken,
@@ -9,7 +9,7 @@ const logger_1 = require("../../logger");
9
9
  const commitFormatters_1 = require("../commitFormatters");
10
10
  async function createStatusComment({ options, backportResponse, }) {
11
11
  const { githubApiBaseUrlV3, repoName, repoOwner, accessToken, publishStatusComment, } = options;
12
- if (!publishStatusComment) {
12
+ if (!publishStatusComment || options.dryRun) {
13
13
  return;
14
14
  }
15
15
  try {
@@ -1,10 +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
6
  exports.fetchPullRequestId = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const apiRequestV4_1 = require("./apiRequestV4");
5
9
  async function fetchPullRequestId(options, pullNumber) {
6
10
  const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
7
- const prQuery = /* GraphQL */ `
11
+ const prQuery = (0, graphql_tag_1.default) `
8
12
  query PullRequestId(
9
13
  $repoOwner: String!
10
14
  $repoName: String!
@@ -1,4 +1,5 @@
1
1
  import { AxiosResponse } from 'axios';
2
+ import { DocumentNode } from 'graphql';
2
3
  interface GithubError {
3
4
  type: string;
4
5
  path: string[];
@@ -16,13 +17,15 @@ declare type Variables = Record<string, string | number | null>;
16
17
  export declare function apiRequestV4<DataResponse>({ githubApiBaseUrlV4, accessToken, query, variables, }: {
17
18
  githubApiBaseUrlV4?: string;
18
19
  accessToken: string;
19
- query: string;
20
+ query: DocumentNode;
20
21
  variables?: Variables;
21
22
  }): Promise<DataResponse>;
22
23
  declare type AxiosGithubResponse<DataResponse> = AxiosResponse<GithubV4Response<DataResponse | null>, any>;
23
24
  export declare class GithubV4Exception<DataResponse> extends Error {
24
- message: string;
25
- axiosResponse: AxiosGithubResponse<DataResponse>;
26
- constructor(message: string, axiosResponse: AxiosGithubResponse<DataResponse>);
25
+ githubResponse: AxiosGithubResponse<DataResponse> & {
26
+ request: undefined;
27
+ };
28
+ constructor(githubResponse: AxiosGithubResponse<DataResponse>, errorMessage?: string);
27
29
  }
30
+ export declare function getQueryName(query: DocumentNode): string;
28
31
  export {};
@@ -3,30 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.GithubV4Exception = exports.apiRequestV4 = void 0;
6
+ exports.getQueryName = exports.GithubV4Exception = exports.apiRequestV4 = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const printer_1 = require("graphql/language/printer");
9
9
  const HandledError_1 = require("../../HandledError");
10
10
  const logger_1 = require("../../logger");
11
11
  async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graphql', accessToken, query, variables, }) {
12
12
  try {
13
- const response = await axios_1.default.post(githubApiBaseUrlV4, { query, variables }, {
13
+ const response = await axios_1.default.post(githubApiBaseUrlV4, { query: (0, printer_1.print)(query), variables }, {
14
14
  headers: {
15
15
  'Content-Type': 'application/json',
16
16
  Authorization: `bearer ${accessToken}`,
17
17
  },
18
18
  });
19
19
  if (response.data.errors) {
20
- const message = `${response.data.errors
21
- .map((error) => error.message)
22
- .join(',')} (Github API v4)`;
23
- throw new GithubV4Exception(message, response);
20
+ throw new GithubV4Exception(response);
24
21
  }
25
22
  addDebugLogs({
26
23
  githubApiBaseUrlV4,
27
24
  query,
28
25
  variables,
29
- axiosResponse: response,
26
+ githubResponse: response,
30
27
  didSucceed: false,
31
28
  });
32
29
  return response.data.data;
@@ -37,37 +34,41 @@ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graph
37
34
  githubApiBaseUrlV4,
38
35
  query,
39
36
  variables,
40
- axiosResponse: e.response,
37
+ githubResponse: e.response,
41
38
  didSucceed: false,
42
39
  });
43
- throw new GithubV4Exception(`${e.message} (Unhandled Github API v4)`, e.response);
40
+ throw new GithubV4Exception(e.response, e.message);
44
41
  }
45
42
  throw e;
46
43
  }
47
44
  }
48
45
  exports.apiRequestV4 = apiRequestV4;
49
- function addDebugLogs({ githubApiBaseUrlV4, query, variables, axiosResponse, didSucceed, }) {
50
- const gqlQueryName = getGqlQueryName(query);
51
- logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${axiosResponse.status})`);
46
+ function addDebugLogs({ githubApiBaseUrlV4, query, variables, githubResponse, didSucceed, }) {
47
+ const gqlQueryName = getQueryName(query);
48
+ logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${githubResponse.status})`);
52
49
  const logMethod = didSucceed ? logger_1.logger.verbose : logger_1.logger.info;
53
50
  logMethod(`Query name ${gqlQueryName}`);
54
51
  logMethod(`Query: ${query}`);
55
52
  logMethod('Variables:', variables);
56
- logMethod('Response headers:', axiosResponse.headers);
57
- logMethod('Response data:', axiosResponse.data);
53
+ logMethod('Response headers:', githubResponse.headers);
54
+ logMethod('Response data:', githubResponse.data);
58
55
  }
59
56
  class GithubV4Exception extends Error {
60
- constructor(message, axiosResponse) {
57
+ constructor(githubResponse, errorMessage) {
58
+ const githubMessage = githubResponse.data.errors
59
+ ?.map((error) => error.message)
60
+ .join(',');
61
+ const message = `${errorMessage ?? githubMessage ?? 'Unknown error'} (Github API v4)`;
61
62
  super(message);
62
- this.message = message;
63
- this.axiosResponse = axiosResponse;
64
63
  Error.captureStackTrace(this, HandledError_1.HandledError);
65
64
  this.name = 'GithubV4Exception';
65
+ this.message = message;
66
+ this.githubResponse = { ...githubResponse, request: undefined };
66
67
  }
67
68
  }
68
69
  exports.GithubV4Exception = GithubV4Exception;
69
- function getGqlQueryName(query) {
70
- const ast = (0, graphql_tag_1.default)(query);
70
+ function getQueryName(query) {
71
71
  //@ts-expect-error
72
- return ast.definitions[0].name.value;
72
+ return query.definitions[0].name?.value;
73
73
  }
74
+ exports.getQueryName = getQueryName;
@@ -1,12 +1,16 @@
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
6
  exports.disablePullRequestAutoMerge = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const FetchPullRequestId_1 = require("./FetchPullRequestId");
5
9
  const apiRequestV4_1 = require("./apiRequestV4");
6
10
  async function disablePullRequestAutoMerge(options, pullNumber) {
7
11
  const { accessToken, githubApiBaseUrlV4 } = options;
8
12
  const pullRequestId = await (0, FetchPullRequestId_1.fetchPullRequestId)(options, pullNumber);
9
- const query = /* GraphQL */ `
13
+ const query = (0, graphql_tag_1.default) `
10
14
  mutation DisablePullRequestAutoMerge($pullRequestId: ID!) {
11
15
  disablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId }) {
12
16
  pullRequest {