backport 7.3.5 → 8.0.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 (87) hide show
  1. package/README.md +13 -18
  2. package/dist/backportRun.d.ts +14 -3
  3. package/dist/backportRun.js +59 -37
  4. package/dist/entrypoint.cli.js +1 -1
  5. package/dist/entrypoint.module.d.ts +8 -3
  6. package/dist/entrypoint.module.js +6 -10
  7. package/dist/entrypoint.module.private.test.js +129 -330
  8. package/dist/options/ConfigOptions.d.ts +2 -2
  9. package/dist/options/cliArgs.d.ts +10 -6
  10. package/dist/options/cliArgs.js +32 -21
  11. package/dist/options/cliArgs.test.js +3 -3
  12. package/dist/options/config/config.d.ts +2 -2
  13. package/dist/options/config/config.js +2 -2
  14. package/dist/options/config/globalConfig.d.ts +2 -2
  15. package/dist/options/config/globalConfig.js +13 -10
  16. package/dist/options/config/projectConfig.d.ts +2 -2
  17. package/dist/options/config/projectConfig.js +3 -3
  18. package/dist/options/config/projectConfig.test.js +19 -7
  19. package/dist/options/config/readConfigFile.d.ts +4 -4
  20. package/dist/options/options.d.ts +4 -5
  21. package/dist/options/options.js +2 -3
  22. package/dist/options/options.test.js +7 -4
  23. package/dist/runSequentially.d.ts +5 -1
  24. package/dist/runSequentially.js +23 -8
  25. package/dist/scripts/postinstall.js +1 -0
  26. package/dist/scripts/postinstall.test.js +5 -1
  27. package/dist/services/HandledError.d.ts +6 -2
  28. package/dist/services/HandledError.js +8 -8
  29. package/dist/services/child-process-promisified.d.ts +19 -3
  30. package/dist/services/child-process-promisified.js +46 -17
  31. package/dist/services/git.d.ts +6 -7
  32. package/dist/services/git.integration.test.js +381 -65
  33. package/dist/services/git.js +188 -126
  34. package/dist/services/git.private.test.d.ts +1 -0
  35. package/dist/services/git.private.test.js +618 -0
  36. package/dist/services/git.test.js +167 -158
  37. package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
  38. package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
  39. package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
  40. package/dist/services/github/v3/createPullRequest.js +3 -1
  41. package/dist/services/github/v3/createStatusComment.js +16 -16
  42. package/dist/services/github/v3/createStatusComment.test.js +17 -5
  43. package/dist/services/github/v4/apiRequestV4.js +6 -9
  44. package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
  45. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
  46. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +5 -6
  47. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -0
  48. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +10 -9
  49. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -0
  50. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +10 -9
  51. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +1 -0
  52. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +9 -8
  53. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +3 -6
  54. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +1 -0
  55. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -6
  56. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +4 -7
  57. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -2
  58. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -7
  59. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +9 -8
  60. package/dist/services/logger.d.ts +1 -4
  61. package/dist/services/logger.js +14 -19
  62. package/dist/services/test.d.ts +1 -0
  63. package/dist/services/test.js +23 -0
  64. package/dist/test/e2e/cli/entrypoint.cli.private.test.d.ts +1 -0
  65. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +401 -0
  66. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +17 -16
  67. package/dist/test/e2e/cli/runBackportViaCli.d.ts +2 -1
  68. package/dist/test/e2e/cli/runBackportViaCli.js +10 -2
  69. package/dist/test/e2e/module/entrypoint.module.mutation.test.d.ts +1 -0
  70. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +376 -0
  71. package/dist/test/handleUnbackportedPullRequests.private.test.js +11 -10
  72. package/dist/test/sandbox.js +5 -1
  73. package/dist/test/setupFiles/automatic-mocks.js +16 -12
  74. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +8 -4
  75. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
  76. package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
  77. package/dist/ui/getGitConfigAuthor.js +1 -1
  78. package/dist/ui/getTargetBranches.test.js +5 -1
  79. package/dist/ui/ora.d.ts +1 -8
  80. package/dist/ui/setupRepo.js +1 -1
  81. package/dist/ui/setupRepo.test.js +98 -61
  82. package/dist/utils/isErrnoError.d.ts +2 -0
  83. package/dist/utils/isErrnoError.js +7 -0
  84. package/dist/utils/packageVersion.d.ts +1 -1
  85. package/dist/utils/packageVersion.js +1 -1
  86. package/package.json +13 -13
  87. package/yarn.lock +414 -695
@@ -91,7 +91,7 @@ describe('getOptionsFromCliArgs', () => {
91
91
  });
92
92
  it('should conflict when using both', () => {
93
93
  const argv = ['--multiple', '--multiple-branches', 'false'];
94
- expect(() => (0, cliArgs_1.getOptionsFromCliArgs)(argv, { exitOnError: false })).toThrow('Arguments multiple and multipleBranches are mutually exclusive');
94
+ expect(() => (0, cliArgs_1.getOptionsFromCliArgs)(argv)).toThrow('Arguments multiple and multipleBranches are mutually exclusive');
95
95
  });
96
96
  });
97
97
  describe('noVerify', () => {
@@ -129,7 +129,7 @@ describe('getOptionsFromCliArgs', () => {
129
129
  });
130
130
  it('should throw on invalid values', () => {
131
131
  const argv = ['--mainline', 'foo'];
132
- expect(() => (0, cliArgs_1.getOptionsFromCliArgs)(argv, { exitOnError: false })).toThrowError('--mainline must be an integer. Received: NaN');
132
+ expect(() => (0, cliArgs_1.getOptionsFromCliArgs)(argv)).toThrowError('--mainline must be an integer. Received: NaN');
133
133
  });
134
134
  });
135
135
  describe('targetBranches', () => {
@@ -148,7 +148,7 @@ describe('getOptionsFromCliArgs', () => {
148
148
  });
149
149
  it('throw if both --repo and --repo-name is given', () => {
150
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');
151
+ expect(() => (0, cliArgs_1.getOptionsFromCliArgs)(argv)).toThrowError('Arguments repo and repoName are mutually exclusive');
152
152
  });
153
153
  });
154
154
  describe('since/until', () => {
@@ -22,9 +22,9 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
22
22
  cherrypickRef?: boolean | undefined;
23
23
  ci?: boolean | undefined;
24
24
  commitPaths?: string[] | undefined;
25
- configFile?: string | undefined;
26
25
  details?: boolean | undefined;
27
26
  dir?: string | undefined;
27
+ dryRun?: boolean | undefined;
28
28
  editor?: string | undefined;
29
29
  fork?: boolean | undefined;
30
30
  gitAuthorEmail?: string | undefined;
@@ -41,6 +41,7 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
41
41
  noVerify?: boolean | undefined;
42
42
  prDescription?: string | undefined;
43
43
  prFilter?: string | undefined;
44
+ projectConfigFile?: string | undefined;
44
45
  prTitle?: string | undefined;
45
46
  publishStatusComment?: boolean | undefined;
46
47
  pullNumber?: number | undefined;
@@ -56,7 +57,6 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
56
57
  targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
57
58
  targetBranches?: string[] | undefined;
58
59
  targetPRLabels?: string[] | undefined;
59
- verbose?: boolean | undefined;
60
60
  help?: boolean | undefined;
61
61
  version?: boolean | undefined;
62
62
  v?: boolean | undefined;
@@ -7,9 +7,9 @@ async function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsFromModule
7
7
  // ci: cli and module only flag
8
8
  const ci = optionsFromCliArgs.ci ?? optionsFromModule.ci ?? defaultConfigOptions.ci;
9
9
  // ci: cli and module only flag
10
- const configFile = optionsFromCliArgs.configFile ?? optionsFromModule.configFile;
10
+ const projectConfigFile = optionsFromCliArgs.projectConfigFile ?? optionsFromModule.projectConfigFile;
11
11
  const [projectConfig, globalConfig] = await Promise.all([
12
- (0, projectConfig_1.getProjectConfig)({ configFile }),
12
+ (0, projectConfig_1.getProjectConfig)({ projectConfigFile }),
13
13
  ci ? undefined : (0, globalConfig_1.getGlobalConfig)(),
14
14
  ]);
15
15
  return {
@@ -1,4 +1,4 @@
1
1
  import { ConfigFileOptions } from '../ConfigOptions';
2
2
  export declare function getGlobalConfig(): Promise<ConfigFileOptions>;
3
- export declare function createGlobalConfigAndFolderIfNotExist(globalConfigPath: string): Promise<boolean>;
4
- export declare function createGlobalConfigIfNotExist(globalConfigPath: string, configTemplate: string): Promise<boolean>;
3
+ export declare function createGlobalConfigAndFolderIfNotExist(globalConfigPath: string): Promise<boolean | undefined>;
4
+ export declare function createGlobalConfigIfNotExist(globalConfigPath: string, configTemplate: string): Promise<boolean | undefined>;
@@ -8,6 +8,7 @@ const promises_1 = require("fs/promises");
8
8
  const make_dir_1 = __importDefault(require("make-dir"));
9
9
  const HandledError_1 = require("../../services/HandledError");
10
10
  const env_1 = require("../../services/env");
11
+ const isErrnoError_1 = require("../../utils/isErrnoError");
11
12
  const readConfigFile_1 = require("./readConfigFile");
12
13
  async function getGlobalConfig() {
13
14
  const globalConfigPath = (0, env_1.getGlobalConfigPath)();
@@ -36,17 +37,19 @@ async function createGlobalConfigIfNotExist(globalConfigPath, configTemplate) {
36
37
  return true;
37
38
  }
38
39
  catch (e) {
39
- // ignore error if file already exists
40
- const FILE_ALREADY_EXISTS = 'EEXIST';
41
- if (e.code === FILE_ALREADY_EXISTS) {
42
- return false;
40
+ if ((0, isErrnoError_1.isErrnoError)(e)) {
41
+ // ignore error if file already exists
42
+ const FILE_ALREADY_EXISTS = 'EEXIST';
43
+ if (e.code === FILE_ALREADY_EXISTS) {
44
+ return false;
45
+ }
46
+ // handle error if folder does not exist
47
+ const FOLDER_NOT_EXISTS = 'ENOENT';
48
+ if (e.code === FOLDER_NOT_EXISTS) {
49
+ throw new HandledError_1.HandledError(`The .backport folder (${globalConfigPath}) does not exist. `);
50
+ }
51
+ throw e;
43
52
  }
44
- // handle error if folder does not exist
45
- const FOLDER_NOT_EXISTS = 'ENOENT';
46
- if (e.code === FOLDER_NOT_EXISTS) {
47
- throw new HandledError_1.HandledError(`The .backport folder (${globalConfigPath}) does not exist. `);
48
- }
49
- throw e;
50
53
  }
51
54
  }
52
55
  exports.createGlobalConfigIfNotExist = createGlobalConfigIfNotExist;
@@ -1,4 +1,4 @@
1
1
  import { ConfigFileOptions } from '../ConfigOptions';
2
- export declare function getProjectConfig({ configFile, }: {
3
- configFile: string | undefined;
2
+ export declare function getProjectConfig({ projectConfigFile, }: {
3
+ projectConfigFile: string | undefined;
4
4
  }): Promise<ConfigFileOptions | undefined>;
@@ -7,9 +7,9 @@ exports.getProjectConfig = void 0;
7
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
- async function getProjectConfig({ configFile, }) {
11
- const filepath = configFile
12
- ? path_1.default.resolve(configFile)
10
+ async function getProjectConfig({ projectConfigFile, }) {
11
+ const filepath = projectConfigFile
12
+ ? path_1.default.resolve(projectConfigFile)
13
13
  : await (0, find_up_1.default)('.backportrc.json');
14
14
  if (!filepath) {
15
15
  return;
@@ -16,7 +16,9 @@ describe('getProjectConfig', () => {
16
16
  repoOwner: 'elastic',
17
17
  branches: ['6.x'],
18
18
  }));
19
- const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
19
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({
20
+ projectConfigFile: undefined,
21
+ });
20
22
  expect(projectConfig?.targetBranchChoices).toEqual(['6.x']);
21
23
  });
22
24
  });
@@ -25,7 +27,9 @@ describe('getProjectConfig', () => {
25
27
  jest.spyOn(promises_1.default, 'readFile').mockResolvedValueOnce(JSON.stringify({
26
28
  labels: ['backport'],
27
29
  }));
28
- const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
30
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({
31
+ projectConfigFile: undefined,
32
+ });
29
33
  expect(projectConfig?.targetPRLabels).toEqual(['backport']);
30
34
  });
31
35
  });
@@ -34,7 +38,9 @@ describe('getProjectConfig', () => {
34
38
  jest.spyOn(promises_1.default, 'readFile').mockResolvedValueOnce(JSON.stringify({
35
39
  upstream: 'elastic/kibana',
36
40
  }));
37
- const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
41
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({
42
+ projectConfigFile: undefined,
43
+ });
38
44
  expect(projectConfig?.repoOwner).toEqual('elastic');
39
45
  expect(projectConfig?.repoName).toEqual('kibana');
40
46
  });
@@ -48,7 +54,9 @@ describe('getProjectConfig', () => {
48
54
  targetBranchChoices: ['6.x'],
49
55
  targetPRLabels: ['backport'],
50
56
  }));
51
- projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
57
+ projectConfig = await (0, projectConfig_1.getProjectConfig)({
58
+ projectConfigFile: undefined,
59
+ });
52
60
  });
53
61
  it('should call findUp', () => {
54
62
  expect(find_up_1.default).toHaveBeenCalledWith('.backportrc.json');
@@ -73,7 +81,7 @@ describe('getProjectConfig', () => {
73
81
  targetPRLabels: ['backport'],
74
82
  }));
75
83
  projectConfig = await (0, projectConfig_1.getProjectConfig)({
76
- configFile: '/custom/path/to/project/.backportrc.json',
84
+ projectConfigFile: '/custom/path/to/project/.backportrc.json',
77
85
  });
78
86
  });
79
87
  it('should not call findUp', () => {
@@ -95,14 +103,18 @@ describe('getProjectConfig', () => {
95
103
  describe('when projectConfig is empty', () => {
96
104
  it('should return empty config', async () => {
97
105
  jest.spyOn(promises_1.default, 'readFile').mockResolvedValueOnce('{}');
98
- const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
106
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({
107
+ projectConfigFile: undefined,
108
+ });
99
109
  expect(projectConfig).toEqual({});
100
110
  });
101
111
  });
102
112
  describe('when projectConfig is missing', () => {
103
113
  it('should return empty config', async () => {
104
114
  find_up_1.default.mockReturnValueOnce(undefined);
105
- const projectConfig = await (0, projectConfig_1.getProjectConfig)({ configFile: undefined });
115
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)({
116
+ projectConfigFile: undefined,
117
+ });
106
118
  expect(projectConfig).toEqual(undefined);
107
119
  });
108
120
  });
@@ -4,8 +4,7 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
4
4
  fork?: boolean | undefined;
5
5
  dir?: string | undefined;
6
6
  help?: boolean | undefined;
7
- verbose?: boolean | undefined;
8
- logFilePath?: string | undefined;
7
+ v?: boolean | undefined;
9
8
  accessToken?: string | undefined;
10
9
  author?: string | null | undefined;
11
10
  autoAssign?: boolean | undefined;
@@ -14,8 +13,9 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
14
13
  autoMergeMethod?: string | undefined;
15
14
  ci?: boolean | undefined;
16
15
  cherrypickRef?: boolean | undefined;
17
- configFile?: string | undefined;
16
+ projectConfigFile?: string | undefined;
18
17
  details?: boolean | undefined;
18
+ dryRun?: boolean | undefined;
19
19
  editor?: string | undefined;
20
20
  skipRemoteConfig?: boolean | undefined;
21
21
  gitHostname?: string | undefined;
@@ -23,6 +23,7 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
23
23
  githubApiBaseUrlV4?: string | undefined;
24
24
  gitAuthorName?: string | undefined;
25
25
  gitAuthorEmail?: string | undefined;
26
+ logFilePath?: string | undefined;
26
27
  ls?: boolean | undefined;
27
28
  maxNumber?: number | undefined;
28
29
  multiple?: boolean | undefined;
@@ -40,7 +41,6 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
40
41
  repoName?: string | undefined;
41
42
  sourceBranch?: string | undefined;
42
43
  version?: boolean | undefined;
43
- v?: boolean | undefined;
44
44
  commitPaths?: string[] | undefined;
45
45
  reviewers?: string[] | undefined;
46
46
  sourcePRLabels?: string[] | undefined;
@@ -4,10 +4,9 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
4
4
  accessToken: string;
5
5
  repoName: string;
6
6
  repoOwner: string;
7
+ cwd: string;
7
8
  fork: boolean;
8
9
  dir?: string | undefined;
9
- verbose: boolean;
10
- logFilePath?: string | undefined;
11
10
  author: string | null;
12
11
  autoAssign: boolean;
13
12
  assignees: string[];
@@ -15,7 +14,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
15
14
  autoMergeMethod: string;
16
15
  ci: boolean;
17
16
  cherrypickRef: boolean;
18
- configFile?: string | undefined;
17
+ projectConfigFile?: string | undefined;
19
18
  details: boolean;
20
19
  dryRun?: boolean | undefined;
21
20
  editor?: string | undefined;
@@ -25,6 +24,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
25
24
  githubApiBaseUrlV4?: string | undefined;
26
25
  gitAuthorName?: string | undefined;
27
26
  gitAuthorEmail?: string | undefined;
27
+ logFilePath?: string | undefined;
28
28
  ls?: boolean | undefined;
29
29
  mainline?: number | undefined;
30
30
  maxNumber: number;
@@ -45,7 +45,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
45
45
  commitPaths: string[];
46
46
  reviewers: string[];
47
47
  sourcePRLabels: string[];
48
- targetBranchChoices: string[] | TargetBranchChoiceOrString[];
48
+ targetBranchChoices: TargetBranchChoiceOrString[];
49
49
  targetBranches: string[];
50
50
  targetPRLabels: string[];
51
51
  publishStatusComment: boolean;
@@ -65,5 +65,4 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
65
65
  branches?: TargetBranchChoiceOrString[] | undefined;
66
66
  labels?: string[] | undefined;
67
67
  authenticatedUsername: string;
68
- cwd: string;
69
68
  }>;
@@ -37,7 +37,6 @@ const defaultConfigOptions = {
37
37
  targetBranchChoices: [],
38
38
  targetBranches: [],
39
39
  targetPRLabels: [],
40
- verbose: false,
41
40
  };
42
41
  async function getOptions(processArgs, optionsFromModule) {
43
42
  const optionsFromCliArgs = (0, cliArgs_1.getOptionsFromCliArgs)(processArgs);
@@ -53,7 +52,7 @@ async function getOptions(processArgs, optionsFromModule) {
53
52
  });
54
53
  const { accessToken, repoName, repoOwner } = await getRequiredOptions(combined);
55
54
  // update logger
56
- (0, logger_1.updateLogger)({ accessToken, verbose: combined.verbose });
55
+ (0, logger_1.setAccessToken)(accessToken);
57
56
  const optionsFromGithub = await (0, getOptionsFromGithub_1.getOptionsFromGithub)({
58
57
  ...combined,
59
58
  // required options
@@ -124,7 +123,6 @@ function throwForRequiredOptions(options) {
124
123
  'author',
125
124
  'autoMergeMethod',
126
125
  'backportBinary',
127
- 'configFile',
128
126
  'dir',
129
127
  'editor',
130
128
  'gitHostname',
@@ -133,6 +131,7 @@ function throwForRequiredOptions(options) {
133
131
  'logFilePath',
134
132
  'prDescription',
135
133
  'prFilter',
134
+ 'projectConfigFile',
136
135
  'prTitle',
137
136
  'repoForkOwner',
138
137
  'repoName',
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -151,10 +155,10 @@ describe('getOptions', () => {
151
155
  const options = await (0, options_1.getOptions)([], { autoFixConflicts: myFn });
152
156
  expect(options.autoFixConflicts).toBe(myFn);
153
157
  });
154
- it('should call updateLogger', async () => {
158
+ it('should call setAccessToken', async () => {
155
159
  mockGithubConfigOptions({});
156
160
  await (0, options_1.getOptions)([], {});
157
- expect(logger.updateLogger).toHaveBeenCalledTimes(1);
161
+ expect(logger.setAccessToken).toHaveBeenCalledTimes(1);
158
162
  });
159
163
  it('should return options', async () => {
160
164
  mockGithubConfigOptions({
@@ -197,7 +201,6 @@ describe('getOptions', () => {
197
201
  targetBranchChoices: ['7.9', '8.0'],
198
202
  targetBranches: [],
199
203
  targetPRLabels: [],
200
- verbose: false,
201
204
  });
202
205
  });
203
206
  describe('sourceBranch', () => {
@@ -9,9 +9,13 @@ export declare type Result = {
9
9
  pullRequestUrl: string;
10
10
  pullRequestNumber: number;
11
11
  } | {
12
- status: 'failure';
12
+ status: 'handled-error';
13
13
  targetBranch: string;
14
14
  error: HandledError;
15
+ } | {
16
+ status: 'unhandled-error';
17
+ targetBranch: string;
18
+ error: Error;
15
19
  };
16
20
  export declare function runSequentially({ options, commits, targetBranches, gitConfigAuthor, }: {
17
21
  options: ValidConfigOptions;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runSequentially = void 0;
4
+ const HandledError_1 = require("./services/HandledError");
4
5
  const logger_1 = require("./services/logger");
5
6
  const sequentially_1 = require("./services/sequentially");
6
7
  const cherrypickAndCreateTargetPullRequest_1 = require("./ui/cherrypickAndCreateTargetPullRequest");
@@ -25,14 +26,28 @@ async function runSequentially({ options, commits, targetBranches, gitConfigAuth
25
26
  });
26
27
  }
27
28
  catch (e) {
28
- process.exitCode = 1;
29
- results.push({
30
- targetBranch,
31
- status: 'failure',
32
- error: e,
33
- });
34
- (0, logger_1.consoleLog)(e.message);
35
- logger_1.logger.error('Could not backport commit', e);
29
+ const isHandledError = e instanceof HandledError_1.HandledError;
30
+ if (isHandledError) {
31
+ results.push({
32
+ targetBranch,
33
+ status: 'handled-error',
34
+ error: e,
35
+ });
36
+ }
37
+ else if (e instanceof Error) {
38
+ results.push({
39
+ targetBranch,
40
+ status: 'unhandled-error',
41
+ error: e,
42
+ });
43
+ }
44
+ else {
45
+ throw e;
46
+ }
47
+ (0, logger_1.consoleLog)(isHandledError
48
+ ? e.message
49
+ : 'An error occurred while backporting commit. Please see the logs for details');
50
+ logger_1.logger.error('runSequentially failed', e);
36
51
  }
37
52
  });
38
53
  // return the results for consumers to programatically read
@@ -13,6 +13,7 @@ async function postinstall() {
13
13
  }
14
14
  }
15
15
  catch (e) {
16
+ // @ts-expect-error
16
17
  (0, logger_1.consoleLog)(`Global config could not be created:\n${e.stack}`);
17
18
  }
18
19
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,15 +1,19 @@
1
1
  import { Commit } from './sourceCommit/parseSourceCommit';
2
2
  declare type ErrorContext = {
3
3
  code: 'merge-conflict-exception';
4
+ conflictingFiles: string[];
4
5
  commitsWithoutBackports: {
5
6
  formatted: string;
6
7
  commit: Commit;
7
8
  }[];
9
+ } | {
10
+ code: 'message-only-exception';
11
+ message: string;
8
12
  } | {
9
13
  code: 'no-branches-exception' | 'abort-exception';
10
14
  };
11
15
  export declare class HandledError extends Error {
12
- errorContext?: ErrorContext;
13
- constructor(errorContext: ErrorContext | string);
16
+ errorContext: ErrorContext;
17
+ constructor(errorContextOrString: ErrorContext | string);
14
18
  }
15
19
  export {};
@@ -2,28 +2,28 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HandledError = void 0;
4
4
  function getMessage(errorContext) {
5
- if (typeof errorContext === 'string') {
6
- return errorContext;
7
- }
8
5
  switch (errorContext.code) {
9
6
  case 'merge-conflict-exception':
10
- return `Commit could not be cherrypicked due to conflicts`;
7
+ return `Commit could not be cherrypicked due to conflicts in: ${errorContext.conflictingFiles.join(',')}`;
11
8
  case 'no-branches-exception':
12
9
  return 'There are no branches to backport to. Aborting.';
13
10
  case 'abort-exception':
14
11
  return 'Aborted';
12
+ case 'message-only-exception':
13
+ return errorContext.message;
15
14
  }
16
15
  }
17
16
  class HandledError extends Error {
18
- constructor(errorContext) {
17
+ constructor(errorContextOrString) {
18
+ const errorContext = typeof errorContextOrString === 'string'
19
+ ? { code: 'message-only-exception', message: errorContextOrString }
20
+ : errorContextOrString;
19
21
  const message = getMessage(errorContext);
20
22
  super(message);
21
23
  Error.captureStackTrace(this, HandledError);
22
24
  this.name = 'HandledError';
23
25
  this.message = message;
24
- if (typeof errorContext !== 'string') {
25
- this.errorContext = errorContext;
26
- }
26
+ this.errorContext = errorContext;
27
27
  }
28
28
  }
29
29
  exports.HandledError = HandledError;
@@ -1,9 +1,25 @@
1
1
  /// <reference types="node" />
2
- import child_process from 'child_process';
3
- export declare function exec(cmd: string, options: child_process.ExecOptions & {
2
+ import childProcess from 'child_process';
3
+ export declare function exec(cmd: string, options: childProcess.ExecOptions & {
4
4
  cwd: string;
5
5
  }): Promise<{
6
6
  stdout: string;
7
7
  stderr: string;
8
8
  }>;
9
- export declare const execAsCallback: (command: string, options: (import("fs").ObjectEncodingOptions & child_process.ExecOptions) | null | undefined, callback?: ((error: child_process.ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined) => child_process.ChildProcess;
9
+ export declare function spawnPromise(cmd: string, cmdArgs: string[], cwd: string): Promise<{
10
+ cmdArgs: string[];
11
+ code: number | null;
12
+ stderr: string;
13
+ stdout: string;
14
+ }>;
15
+ export declare const spawnOriginal: typeof childProcess.spawn;
16
+ export declare type SpawnErrorContext = {
17
+ cmdArgs: string[];
18
+ code: number;
19
+ stderr: string;
20
+ stdout: string;
21
+ };
22
+ export declare class SpawnError extends Error {
23
+ context: SpawnErrorContext;
24
+ constructor(context: SpawnErrorContext);
25
+ }
@@ -3,27 +3,56 @@ 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.execAsCallback = exports.exec = void 0;
6
+ exports.SpawnError = exports.spawnOriginal = exports.spawnPromise = exports.exec = void 0;
7
7
  const child_process_1 = __importDefault(require("child_process"));
8
8
  const util_1 = require("util");
9
9
  const logger_1 = require("./logger");
10
+ const execPromisified = (0, util_1.promisify)(child_process_1.default.exec);
10
11
  async function exec(cmd, options) {
11
- const execPromisified = (0, util_1.promisify)(child_process_1.default.exec);
12
- try {
13
- const res = await execPromisified(cmd, {
14
- maxBuffer: 100 * 1024 * 1024,
15
- ...options,
12
+ const res = await execPromisified(cmd, {
13
+ maxBuffer: 100 * 1024 * 1024,
14
+ ...options,
15
+ });
16
+ return res;
17
+ }
18
+ exports.exec = exec;
19
+ async function spawnPromise(cmd, cmdArgs, cwd) {
20
+ return new Promise(function (resolve, reject) {
21
+ const subprocess = child_process_1.default.spawn(cmd, cmdArgs, { cwd });
22
+ let stderr = '';
23
+ let stdout = '';
24
+ subprocess.stdout.on('data', (data) => {
25
+ stdout += data;
16
26
  });
17
- logger_1.logger.verbose(`exec success '${cmd}':`, res);
18
- return res;
19
- }
20
- catch (e) {
21
- logger_1.logger.info(`exec error '${cmd}': ${JSON.stringify(e, null, 2)}`);
22
- throw e;
27
+ subprocess.stderr.on('data', (data) => {
28
+ stderr += data;
29
+ });
30
+ subprocess.on('close', (code) => {
31
+ if (code === 0 || code === null) {
32
+ logger_1.logger.verbose(`spawn success "${cmdArgs}"`);
33
+ resolve({ cmdArgs, code, stderr, stdout });
34
+ }
35
+ else {
36
+ const err = new SpawnError({ cmdArgs, code, stderr, stdout });
37
+ logger_1.logger.info('spawn error', err);
38
+ reject(err);
39
+ }
40
+ });
41
+ subprocess.on('error', (err) => {
42
+ reject(err);
43
+ });
44
+ });
45
+ }
46
+ exports.spawnPromise = spawnPromise;
47
+ exports.spawnOriginal = child_process_1.default.spawn;
48
+ class SpawnError extends Error {
49
+ constructor(context) {
50
+ const message = `Code: ${context.code}; Args: ${JSON.stringify(context.cmdArgs)}; ${context.stderr.trim()}`;
51
+ super(message);
52
+ Error.captureStackTrace(this, SpawnError);
53
+ this.name = 'SpawnError';
54
+ this.message = message;
55
+ this.context = context;
23
56
  }
24
57
  }
25
- exports.exec = exec;
26
- const execAsCallback = (...args) => {
27
- return child_process_1.default.exec(...args);
28
- };
29
- exports.execAsCallback = execAsCallback;
58
+ exports.SpawnError = SpawnError;
@@ -14,7 +14,7 @@ export declare function isLocalConfigFileUntracked({ cwd }: {
14
14
  }): Promise<boolean | undefined>;
15
15
  export declare function isLocalConfigFileModified({ cwd }: {
16
16
  cwd: string;
17
- }): Promise<boolean | undefined>;
17
+ }): Promise<boolean>;
18
18
  export declare function getRepoInfoFromGitRemotes({ cwd }: {
19
19
  cwd: string;
20
20
  }): Promise<{
@@ -59,10 +59,7 @@ export declare function createBackportBranch({ options, targetBranch, backportBr
59
59
  options: ValidConfigOptions;
60
60
  targetBranch: string;
61
61
  backportBranch: string;
62
- }): Promise<{
63
- stdout: string;
64
- stderr: string;
65
- }>;
62
+ }): Promise<void>;
66
63
  export declare function deleteBackportBranch({ options, backportBranch, }: {
67
64
  options: ValidConfigOptions;
68
65
  backportBranch: string;
@@ -72,7 +69,9 @@ export declare function pushBackportBranch({ options, backportBranch, }: {
72
69
  options: ValidConfigOptions;
73
70
  backportBranch: string;
74
71
  }): Promise<{
75
- stdout: string;
72
+ cmdArgs: string[];
73
+ code: number | null;
76
74
  stderr: string;
75
+ stdout: string;
77
76
  }>;
78
- export declare function getLocalRepoPath(options: ValidConfigOptions): Promise<string | undefined>;
77
+ export declare function getLocalSourceRepoPath(options: ValidConfigOptions): Promise<string | undefined>;