backport 7.0.0 → 7.1.0

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 (75) hide show
  1. package/README.md +2 -1
  2. package/dist/backportRun.d.ts +1 -0
  3. package/dist/backportRun.js +4 -3
  4. package/dist/entrypoint.cli.e2e.private.test.js +58 -19
  5. package/dist/entrypoint.cli.js +12 -1
  6. package/dist/options/ConfigOptions.d.ts +1 -0
  7. package/dist/options/cliArgs.d.ts +1 -1
  8. package/dist/options/cliArgs.test.js +12 -0
  9. package/dist/options/config/config.d.ts +1 -0
  10. package/dist/options/config/projectConfig.js +2 -2
  11. package/dist/options/config/readConfigFile.d.ts +2 -1
  12. package/dist/options/options.d.ts +2 -5
  13. package/dist/options/options.test.js +26 -28
  14. package/dist/runSequentially.test.js +1 -2
  15. package/dist/services/HandledError.js +3 -1
  16. package/dist/services/git.js +5 -8
  17. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  18. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -6
  19. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  20. package/dist/services/github/v3/addLabelsToPullRequest.js +3 -6
  21. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +1 -1
  22. package/dist/services/github/v3/addReviewersToPullRequest.js +3 -6
  23. package/dist/services/github/v3/createPullRequest.js +2 -5
  24. package/dist/services/github/v3/createPullRequest.test.js +5 -5
  25. package/dist/services/github/v3/createStatusComment.test.js +7 -7
  26. package/dist/services/github/v4/FetchPullRequestId.js +5 -1
  27. package/dist/services/github/v4/apiRequestV4.d.ts +3 -1
  28. package/dist/services/github/v4/apiRequestV4.js +7 -7
  29. package/dist/services/github/v4/apiRequestV4.test.js +38 -11
  30. package/dist/services/github/v4/disablePullRequestAutoMerge.js +5 -1
  31. package/dist/services/github/v4/enablePullRequestAutoMerge.js +4 -3
  32. package/dist/services/github/v4/fetchAuthorId.js +5 -1
  33. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -3
  34. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -1
  35. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +6 -2
  36. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +3 -12
  37. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -1
  38. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +6 -2
  39. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -11
  40. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -1
  41. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +6 -2
  42. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +7 -12
  43. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -1
  44. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +6 -2
  45. package/dist/services/github/v4/fetchExistingPullRequest.js +5 -1
  46. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +5 -1
  47. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +1 -1
  48. package/dist/services/github/v4/fetchRemoteProjectConfig.js +13 -20
  49. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -4
  50. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +14 -55
  51. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -19
  52. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +3 -16
  53. package/dist/services/github/v4/getOptionsFromGithub/query.js +9 -19
  54. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +5 -1
  55. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +5 -0
  56. package/dist/services/logger.d.ts +5 -5
  57. package/dist/services/logger.js +24 -23
  58. package/dist/services/remoteConfig.d.ts +18 -0
  59. package/dist/services/remoteConfig.js +39 -0
  60. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +4 -0
  61. package/dist/services/sourceCommit/getMockSourceCommit.js +20 -6
  62. package/dist/services/sourceCommit/parseSourceCommit.d.ts +3 -4
  63. package/dist/services/sourceCommit/parseSourceCommit.js +73 -71
  64. package/dist/services/sourceCommit/parseSourceCommit.test.js +7 -17
  65. package/dist/test/backport-e2e.mutation.test.js +3 -3
  66. package/dist/test/nockHelpers.js +6 -2
  67. package/dist/test/setupFiles/automatic-mocks.js +5 -1
  68. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -4
  69. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +3 -3
  70. package/dist/ui/getCommits.js +2 -2
  71. package/dist/ui/ora.d.ts +9 -0
  72. package/dist/ui/ora.js +21 -0
  73. package/dist/utils/packageVersion.d.ts +1 -1
  74. package/dist/utils/packageVersion.js +1 -1
  75. package/package.json +2 -2
package/README.md CHANGED
@@ -41,6 +41,7 @@ Add a [project config](https://github.com/sqren/backport/blob/master/docs/config
41
41
  "targetBranchChoices": ["main", "6.3", "6.2", "6.1", "6.0"],
42
42
 
43
43
  // Optional: Automatically detect which branches a pull request should be backported to based on the pull request labels.
44
+ // In this case, adding the label "backport-to-production" will backport the PR to the "production" branch
44
45
  "branchLabelMapping": {
45
46
  "^backport-to-(.+)$": "$1"
46
47
  }
@@ -111,7 +112,7 @@ The CLI options will override the [configuration options](https://github.com/sqr
111
112
 
112
113
  ## Backport Module API
113
114
 
114
- `backport` can be imported as a Node module and interacted with programatically. This can be useful when creating automation around the Backport tool. See for example the [Backport Github Action](https://github.com/elastic/kibana-github-actions/blob/f5c58195840b8b0cf6036cfeba6e0b497306fb39/backport/index.ts)
115
+ `backport` can be imported as a Node module and interacted with programatically. This can be useful when creating automation around the Backport tool. See for example the [Backport Github Action](https://github.com/sqren/backport-github-action)
115
116
 
116
117
  ### `backportRun`
117
118
 
@@ -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,14 +15,15 @@ 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)();
26
- if (!argv.help && !argv.version) {
25
+ const spinner = (0, ora_1.ora)(ci);
26
+ if (!argv.help && !argv.version && !argv.v) {
27
27
  spinner.start('Initializing...');
28
28
  }
29
29
  let options = null;
@@ -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,4 +1,23 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
23
  };
@@ -9,13 +28,11 @@ const strip_ansi_1 = __importDefault(require("strip-ansi"));
9
28
  const child_process_promisified_1 = require("./services/child-process-promisified");
10
29
  const getDevAccessToken_1 = require("./test/private/getDevAccessToken");
11
30
  const sandbox_1 = require("./test/sandbox");
31
+ const packageVersion = __importStar(require("./utils/packageVersion"));
12
32
  const TIMEOUT_IN_SECONDS = 10;
13
33
  jest.setTimeout(15000);
34
+ const devAccessToken = (0, getDevAccessToken_1.getDevAccessToken)();
14
35
  describe('inquirer cli', () => {
15
- let devAccessToken;
16
- beforeAll(() => {
17
- devAccessToken = (0, getDevAccessToken_1.getDevAccessToken)();
18
- });
19
36
  it('--version', async () => {
20
37
  const res = await runBackportAsync([`--version`]);
21
38
  expect(res).toContain(process.env.npm_package_version);
@@ -24,6 +41,10 @@ describe('inquirer cli', () => {
24
41
  const res = await runBackportAsync([`-v`]);
25
42
  expect(res).toContain(process.env.npm_package_version);
26
43
  });
44
+ it('PACKAGE_VERSION should match', async () => {
45
+ // @ts-expect-error
46
+ expect(packageVersion.UNMOCKED_PACKAGE_VERSION).toBe(process.env.npm_package_version);
47
+ });
27
48
  it('--help', async () => {
28
49
  const res = await runBackportAsync([`--help`]);
29
50
  expect(res).toMatchInlineSnapshot(`
@@ -79,8 +100,7 @@ describe('inquirer cli', () => {
79
100
  -b, --targetBranch, --branch Branch(es) to backport to [array]
80
101
  --targetBranchChoice List branches to backport to [array]
81
102
  -l, --targetPRLabel, --label Add labels to the target (backport) PR [array]
82
- --username User repo that branch will be pushed to. Defaults to the
83
- authenticated user [string]
103
+ --username Defaults to the authenticated user [string]
84
104
  --verbose Show additional debug information [boolean]
85
105
  --verify Opposite of no-verify [boolean]
86
106
  --help Show help [boolean]
@@ -180,7 +200,7 @@ describe('inquirer cli', () => {
180
200
  6. Merge pull request #1 from backport-org/add-heart-emoji"
181
201
  `);
182
202
  });
183
- it(`should limit commits by since and until`, async () => {
203
+ it(`should filter commits by "since" and "until"`, async () => {
184
204
  jest.setTimeout(TIMEOUT_IN_SECONDS * 1000 * 1.1);
185
205
  const output = await runBackportAsync([
186
206
  '--branch',
@@ -192,22 +212,16 @@ describe('inquirer cli', () => {
192
212
  '--accessToken',
193
213
  devAccessToken,
194
214
  '--since',
195
- '2020-08-15T00:00:00.000Z',
215
+ '2020-08-15T10:00:00.000Z',
196
216
  '--until',
197
- '2020-08-15T14:00:00.000Z',
217
+ '2020-08-15T10:30:00.000Z',
198
218
  ], { waitForString: 'Select commit' });
199
219
  expect(output).toMatchInlineSnapshot(`
200
220
  "? Select commit (Use arrow keys)
201
- ❯ 1. Add 🍏 emoji (#5) 7.x, 7.8
202
- 2. Add family emoji (#2) 7.x
203
- 3. Add \`backport\` dep
204
- 4. Merge pull request #1 from backport-org/add-heart-emoji
205
- 5. Add ❤️ emoji
206
- 6. Update .backportrc.json
207
- 7. Bump to 8.0.0
208
- 8. Add package.json
209
- 9. Update .backportrc.json
210
- 10.Create .backportrc.json"
221
+ ❯ 1. Bump to 8.0.0
222
+ 2. Add package.json
223
+ 3. Update .backportrc.json
224
+ 4. Create .backportrc.json"
211
225
  `);
212
226
  });
213
227
  it(`should list commits from 7.x`, async () => {
@@ -237,6 +251,31 @@ describe('inquirer cli', () => {
237
251
  6. Bump to 8.0.0"
238
252
  `);
239
253
  });
254
+ describe('repo: different-merge-strategies', () => {
255
+ it('list all commits regardless how they were merged', async () => {
256
+ jest.setTimeout(TIMEOUT_IN_SECONDS * 1000 * 1.1);
257
+ const output = await runBackportAsync([
258
+ '--branch',
259
+ 'foo',
260
+ '--repo-owner',
261
+ 'backport-org',
262
+ '--repo-name',
263
+ 'different-merge-strategies',
264
+ '--accessToken',
265
+ devAccessToken,
266
+ ], { waitForString: 'Select commit' });
267
+ expect(output).toMatchInlineSnapshot(`
268
+ "? Select commit (Use arrow keys)
269
+ ❯ 1. Using squash to merge commits (#3) 7.x
270
+ 2. Rebase strategy: Second commit 7.x
271
+ 3. Rebase strategy: First commit
272
+ 4. Merge pull request #1 from backport-org/merge-strategy
273
+ 5. Merge strategy: Second commit
274
+ 6. Merge strategy: First commit
275
+ 7. Initial commit"
276
+ `);
277
+ });
278
+ });
240
279
  });
241
280
  function runBackportAsync(cliArgs, { waitForString, cwd, } = {}) {
242
281
  const tsNodeBinary = path_1.default.resolve('./node_modules/.bin/ts-node');
@@ -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
+ });
@@ -58,6 +58,7 @@ declare type Options = Partial<{
58
58
  export declare type ConfigFileOptions = Options & Partial<{
59
59
  help: boolean;
60
60
  version: boolean;
61
+ v: boolean;
61
62
  branchLabelMapping: Record<string, string>;
62
63
  /**
63
64
  * @deprecated Replaced by `repoOwner` and `repoName`
@@ -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;
@@ -20,7 +21,6 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
20
21
  gitHostname?: string | undefined;
21
22
  githubApiBaseUrlV3?: string | undefined;
22
23
  githubApiBaseUrlV4?: string | undefined;
23
- logFilePath?: string | undefined;
24
24
  mainline?: number | undefined;
25
25
  maxNumber?: number | undefined;
26
26
  multipleBranches?: boolean | undefined;
@@ -139,6 +139,18 @@ describe('getOptionsFromCliArgs', () => {
139
139
  expect(res.targetBranches).toEqual(['6.0']);
140
140
  });
141
141
  });
142
+ describe('repo', () => {
143
+ it('splits into repoOwner and repoName', () => {
144
+ const argv = ['--repo', 'elastic/kibana'];
145
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
146
+ expect(res.repoOwner).toEqual('elastic');
147
+ expect(res.repoName).toEqual('kibana');
148
+ });
149
+ it('throw if both --repo and --repo-name is given', () => {
150
+ const argv = ['--repo', 'elastic/kibana', '--repo-name', 'foo'];
151
+ expect(() => (0, cliArgs_1.getOptionsFromCliArgs)(argv, { exitOnError: false })).toThrowError('Arguments repo and repoName are mutually exclusive');
152
+ });
153
+ });
142
154
  describe('since/until', () => {
143
155
  it('should always be UTC time (configured globally in jest.config.js)', () => {
144
156
  expect(new Date().getTimezoneOffset()).toBe(0);
@@ -56,6 +56,7 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
56
56
  verbose?: boolean | undefined;
57
57
  help?: boolean | undefined;
58
58
  version?: boolean | undefined;
59
+ v?: boolean | undefined;
59
60
  branchLabelMapping?: Record<string, string> | undefined;
60
61
  upstream?: string | undefined;
61
62
  branches?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
@@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getProjectConfig = void 0;
7
- const posix_1 = __importDefault(require("path/posix"));
7
+ const path_1 = __importDefault(require("path"));
8
8
  const find_up_1 = __importDefault(require("find-up"));
9
9
  const readConfigFile_1 = require("../config/readConfigFile");
10
10
  async function getProjectConfig({ configFile, }) {
11
11
  const filepath = configFile
12
- ? posix_1.default.resolve(configFile)
12
+ ? path_1.default.resolve(configFile)
13
13
  : await (0, find_up_1.default)('.backportrc.json');
14
14
  if (!filepath) {
15
15
  return;
@@ -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;
@@ -37,6 +37,7 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
37
37
  sourceBranch?: string | undefined;
38
38
  username?: string | undefined;
39
39
  version?: boolean | undefined;
40
+ v?: boolean | undefined;
40
41
  commitPaths?: string[] | undefined;
41
42
  reviewers?: string[] | undefined;
42
43
  sourcePRLabels?: 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[];
@@ -21,7 +22,6 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
21
22
  gitHostname: string;
22
23
  githubApiBaseUrlV3?: string | undefined;
23
24
  githubApiBaseUrlV4?: string | undefined;
24
- logFilePath?: string | undefined;
25
25
  mainline?: number | undefined;
26
26
  maxNumber: number;
27
27
  multipleBranches: boolean;
@@ -44,10 +44,6 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
44
44
  targetBranches: string[];
45
45
  targetPRLabels: string[];
46
46
  publishStatusComment: boolean;
47
- historicalBranchLabelMappings: {
48
- branchLabelMapping: Record<string, string>;
49
- committedDate: string;
50
- }[];
51
47
  autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
52
48
  files: string[];
53
49
  directory: string;
@@ -58,6 +54,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
58
54
  multiple?: boolean | undefined;
59
55
  help?: boolean | undefined;
60
56
  version?: boolean | undefined;
57
+ v?: boolean | undefined;
61
58
  branchLabelMapping?: Record<string, string> | undefined;
62
59
  upstream?: string | undefined;
63
60
  branches?: TargetBranchChoiceOrString[] | undefined;
@@ -126,6 +126,14 @@ describe('getOptions', () => {
126
126
  });
127
127
  });
128
128
  });
129
+ it('reads options from remote config', async () => {
130
+ mockGithubConfigOptions({ hasRemoteConfig: true });
131
+ const options = await (0, options_1.getOptions)([], {});
132
+ expect(options.branchLabelMapping).toEqual({
133
+ '^v8.2.0$': 'option-from-remote',
134
+ });
135
+ expect(options.autoMergeMethod).toEqual('rebase');
136
+ });
129
137
  it('should ensure that "backport" branch does not exist', async () => {
130
138
  mockGithubConfigOptions({ hasBackportBranch: true });
131
139
  await expect((0, options_1.getOptions)([], {})).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
@@ -145,12 +153,6 @@ describe('getOptions', () => {
145
153
  mockGithubConfigOptions({
146
154
  viewerLogin: 'john.diller',
147
155
  defaultBranchRef: 'default-branch-from-github',
148
- historicalMappings: [
149
- {
150
- committedDate: '2022-01-02T20:52:45.173Z',
151
- branchLabelMapping: { foo: 'bar' },
152
- },
153
- ],
154
156
  });
155
157
  const options = await (0, options_1.getOptions)([], {});
156
158
  expect(options).toEqual({
@@ -162,9 +164,6 @@ describe('getOptions', () => {
162
164
  autoMerge: false,
163
165
  autoMergeMethod: 'merge',
164
166
  backportBinary: 'backport',
165
- branchLabelMapping: {
166
- foo: 'bar',
167
- },
168
167
  cherrypickRef: true,
169
168
  ci: false,
170
169
  commitPaths: [],
@@ -176,12 +175,6 @@ describe('getOptions', () => {
176
175
  fork: true,
177
176
  gitHostname: 'github.com',
178
177
  githubApiBaseUrlV4: 'http://localhost/graphql',
179
- historicalBranchLabelMappings: [
180
- {
181
- branchLabelMapping: { foo: 'bar' },
182
- committedDate: '2022-01-02T20:52:45.173Z',
183
- },
184
- ],
185
178
  maxNumber: 10,
186
179
  multipleBranches: true,
187
180
  multipleCommits: false,
@@ -325,7 +318,7 @@ function mockProjectConfig(projectConfig) {
325
318
  },
326
319
  });
327
320
  }
328
- function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBranchRef = 'DO_NOT_USE-default-branch-name', hasBackportBranch, historicalMappings = [], }) {
321
+ function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBranchRef = 'DO_NOT_USE-default-branch-name', hasBackportBranch, hasRemoteConfig, }) {
329
322
  return (0, nockHelpers_1.mockGqlRequest)({
330
323
  name: 'GithubConfigOptions',
331
324
  statusCode: 200,
@@ -339,21 +332,26 @@ function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBran
339
332
  defaultBranchRef: {
340
333
  name: defaultBranchRef,
341
334
  target: {
342
- history: {
343
- edges: historicalMappings.map(({ committedDate, branchLabelMapping }) => {
344
- return {
345
- remoteConfig: {
346
- committedDate,
347
- file: {
348
- object: {
349
- text: JSON.stringify({
350
- branchLabelMapping,
351
- }),
335
+ remoteConfigHistory: {
336
+ edges: hasRemoteConfig
337
+ ? [
338
+ {
339
+ remoteConfig: {
340
+ committedDate: '2020-08-15T00:00:00.000Z',
341
+ file: {
342
+ object: {
343
+ text: JSON.stringify({
344
+ autoMergeMethod: 'rebase',
345
+ branchLabelMapping: {
346
+ '^v8.2.0$': 'option-from-remote',
347
+ },
348
+ }),
349
+ },
352
350
  },
353
351
  },
354
352
  },
355
- };
356
- }),
353
+ ]
354
+ : [],
357
355
  },
358
356
  },
359
357
  },
@@ -77,7 +77,6 @@ describe('runSequentially', () => {
77
77
  gitHostname: 'github.com',
78
78
  githubApiBaseUrlV3: 'https://api.github.com',
79
79
  githubApiBaseUrlV4: 'http://localhost/graphql',
80
- historicalBranchLabelMappings: [],
81
80
  mainline: undefined,
82
81
  maxNumber: 10,
83
82
  multipleBranches: false,
@@ -160,7 +159,7 @@ describe('runSequentially', () => {
160
159
  This will backport the following commits from \`master\` to \`7.x\`:
161
160
  - [My commit message](foo)
162
161
 
163
- <!--- Backport version: 1.2.3 -->
162
+ <!--- Backport version: 1.2.3-mocked -->
164
163
 
165
164
  ### Questions ?
166
165
  Please refer to the [Backport tool documentation](https://github.com/sqren/backport)",
@@ -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
  }
@@ -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
3
  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;
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");
@@ -269,7 +266,7 @@ async function getUnstagedFiles(options) {
269
266
  }
270
267
  exports.getUnstagedFiles = getUnstagedFiles;
271
268
  async function setCommitAuthor(options, author) {
272
- const spinner = (0, ora_1.default)(`Changing author to "${author}"`).start();
269
+ const spinner = (0, ora_1.ora)(options.ci, `Changing author to "${author}"`).start();
273
270
  try {
274
271
  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
272
  spinner.succeed();
@@ -285,7 +282,7 @@ exports.setCommitAuthor = setCommitAuthor;
285
282
  // ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
286
283
  // master -> backport/7.x/pr-1234 -> 7.x
287
284
  async function createBackportBranch({ options, targetBranch, backportBranch, }) {
288
- const spinner = (0, ora_1.default)('Pulling latest changes').start();
285
+ const spinner = (0, ora_1.ora)(options.ci, 'Pulling latest changes').start();
289
286
  try {
290
287
  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
288
  spinner.succeed();
@@ -303,7 +300,7 @@ async function createBackportBranch({ options, targetBranch, backportBranch, })
303
300
  }
304
301
  exports.createBackportBranch = createBackportBranch;
305
302
  async function deleteBackportBranch({ options, backportBranch, }) {
306
- const spinner = (0, ora_1.default)().start();
303
+ const spinner = (0, ora_1.ora)(options.ci).start();
307
304
  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
305
  spinner.stop();
309
306
  }
@@ -317,7 +314,7 @@ function getRepoForkOwner(options) {
317
314
  exports.getRepoForkOwner = getRepoForkOwner;
318
315
  async function pushBackportBranch({ options, backportBranch, }) {
319
316
  const repoForkOwner = getRepoForkOwner(options);
320
- const spinner = (0, ora_1.default)(`Pushing branch "${repoForkOwner}:${backportBranch}"`).start();
317
+ const spinner = (0, ora_1.ora)(options.ci, `Pushing branch "${repoForkOwner}:${backportBranch}"`).start();
321
318
  try {
322
319
  const res = await (0, child_process_promisified_1.exec)(`git push ${repoForkOwner} ${backportBranch}:${backportBranch} --force`, { cwd: (0, env_1.getRepoPath)(options) });
323
320
  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,