backport 6.0.0 → 6.1.3

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 (106) hide show
  1. package/README.md +179 -52
  2. package/dist/entrypoint.cli.js +2 -0
  3. package/dist/entrypoint.module.d.ts +16 -4
  4. package/dist/entrypoint.module.js +41 -13
  5. package/dist/entrypoint.module.private.test.d.ts +1 -0
  6. package/dist/entrypoint.module.private.test.js +34 -0
  7. package/dist/main.js +1 -2
  8. package/dist/options/ConfigOptions.d.ts +16 -6
  9. package/dist/options/cliArgs.d.ts +36 -37
  10. package/dist/options/cliArgs.js +25 -24
  11. package/dist/options/cliArgs.test.js +6 -10
  12. package/dist/options/config/config.d.ts +28 -52
  13. package/dist/options/config/config.js +2 -36
  14. package/dist/options/config/config.test.js +10 -27
  15. package/dist/options/config/getOptionsFromGit.d.ts +3 -2
  16. package/dist/options/config/getOptionsFromGit.js +1 -3
  17. package/dist/options/config/globalConfig.js +2 -5
  18. package/dist/options/config/globalConfig.test.js +0 -2
  19. package/dist/options/config/projectConfig.test.js +51 -14
  20. package/dist/options/config/readConfigFile.d.ts +52 -0
  21. package/dist/options/config/readConfigFile.js +28 -2
  22. package/dist/options/options.d.ts +55 -32
  23. package/dist/options/options.js +101 -7
  24. package/dist/options/options.test.js +248 -97
  25. package/dist/options/parseRequiredOptions.d.ts +3 -3
  26. package/dist/options/parseRequiredOptions.js +2 -4
  27. package/dist/options/parseRequiredOptions.test.js +6 -11
  28. package/dist/runSequentially.test.js +40 -78
  29. package/dist/services/git.d.ts +5 -2
  30. package/dist/services/git.js +11 -10
  31. package/dist/services/git.test.js +12 -9
  32. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  33. package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -3
  34. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +4 -5
  35. package/dist/services/github/v3/createPullRequest.js +10 -13
  36. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  37. package/dist/services/github/v3/createPullRequest.test.js +110 -0
  38. package/dist/services/github/v3/createStatusComment.js +12 -14
  39. package/dist/services/github/v3/createStatusComment.test.js +58 -29
  40. package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
  41. package/dist/services/github/v4/apiRequestV4.js +1 -1
  42. package/dist/services/github/v4/enablePullRequestAutoMerge.js +1 -1
  43. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -1
  44. package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
  45. package/dist/services/github/v4/fetchAuthorId.js +5 -6
  46. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
  47. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +8 -1
  48. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  49. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +6 -3
  50. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +8 -1
  51. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -1
  52. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -3
  53. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +12 -1
  54. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +6 -8
  55. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +10 -12
  56. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -7
  57. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
  58. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
  59. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +5 -5
  60. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -6
  61. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -2
  62. package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
  63. package/dist/services/github/v4/fetchProjectConfig.js +56 -0
  64. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
  65. package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
  66. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
  67. package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
  68. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +67 -0
  69. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
  70. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  71. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
  72. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +3 -1
  73. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +22 -1
  74. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +4 -1
  75. package/dist/services/github/v4/getOptionsFromGithub/query.js +3 -0
  76. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +32 -15
  77. package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -1
  78. package/dist/services/sourceCommit/parseSourceCommit.js +2 -2
  79. package/dist/services/sourceCommit/parseSourceCommit.test.js +120 -5
  80. package/dist/test/inquirer.private.test.js +33 -36
  81. package/dist/test/integration/integration.private.test.js +114 -95
  82. package/dist/test/mockConfigFiles.d.ts +5 -0
  83. package/dist/test/mockConfigFiles.js +37 -0
  84. package/dist/test/nockHelpers.d.ts +1 -1
  85. package/dist/test/nockHelpers.js +4 -4
  86. package/dist/test/private/getDevAccessToken.js +1 -1
  87. package/dist/test/setupFiles/automatic-mocks.js +1 -29
  88. package/dist/ui/cherrypickAndCreatePullRequest.test.js +80 -28
  89. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -9
  90. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +13 -48
  91. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +222 -260
  92. package/dist/ui/getCommits.d.ts +1 -1
  93. package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
  94. package/dist/ui/getCommitsWithoutBackports.js +53 -0
  95. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  96. package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
  97. package/dist/ui/getTargetBranches.d.ts +2 -1
  98. package/dist/ui/getTargetBranches.js +17 -1
  99. package/dist/ui/maybeSetupRepo.js +4 -3
  100. package/dist/ui/maybeSetupRepo.test.js +49 -3
  101. package/dist/utils/excludeUndefined.d.ts +6 -0
  102. package/dist/utils/excludeUndefined.js +7 -0
  103. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  104. package/dist/utils/excludeUndefined.test.js +24 -0
  105. package/package.json +9 -8
  106. package/yarn.lock +98 -77
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getOptionsFromCliArgs = void 0;
7
7
  const yargs_1 = __importDefault(require("yargs"));
8
+ const excludeUndefined_1 = require("../utils/excludeUndefined");
8
9
  function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
9
10
  const yargsInstance = (0, yargs_1.default)(argv)
10
11
  .parserConfiguration({
@@ -24,6 +25,7 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
24
25
  description: 'List all commits',
25
26
  alias: 'a',
26
27
  type: 'boolean',
28
+ conflicts: 'author',
27
29
  })
28
30
  .option('assignee', {
29
31
  description: 'Add assignees to the target pull request',
@@ -31,10 +33,6 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
31
33
  type: 'array',
32
34
  string: true,
33
35
  conflicts: ['autoAssign'],
34
- })
35
- .option('author', {
36
- description: 'Show commits by specific author',
37
- type: 'string',
38
36
  })
39
37
  .option('autoAssign', {
40
38
  description: 'Auto assign the target pull request to yourself',
@@ -67,11 +65,11 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
67
65
  description: 'Editor to be opened during conflict resolution',
68
66
  type: 'string',
69
67
  })
70
- .option('forceLocalConfig', {
68
+ .option('skipRemoteConfig', {
71
69
  description: 'Use local .backportrc.json config instead of loading from Github',
72
70
  type: 'boolean',
73
71
  })
74
- // push target branch to {username}/{repoName}
72
+ // push target branch to {authenticatedUsername}/{repoName}
75
73
  .option('fork', {
76
74
  description: 'Create backports in fork or origin repo',
77
75
  type: 'boolean',
@@ -96,9 +94,10 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
96
94
  description: 'Parent id of merge commit. Defaults to 1 when supplied without arguments',
97
95
  type: 'number',
98
96
  coerce: (mainline) => {
99
- // `--mainline` (default to 1 when no parent is given)
100
97
  if (mainline === undefined) {
101
- return 1;
98
+ // return 1 if `--mainline` is given without a value
99
+ // return undefined if --mainline is not supplied at all
100
+ return argv.includes('--mainline') ? 1 : undefined;
102
101
  }
103
102
  // use specified mainline parent
104
103
  if (Number.isInteger(mainline)) {
@@ -181,6 +180,14 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
181
180
  description: 'Add reviewer to the target PR',
182
181
  type: 'array',
183
182
  string: true,
183
+ })
184
+ .option('repoOwner', {
185
+ description: 'Repository owner',
186
+ type: 'string',
187
+ })
188
+ .option('repoName', {
189
+ description: 'Repository name',
190
+ type: 'string',
184
191
  })
185
192
  .option('sha', {
186
193
  conflicts: ['pullNumber', 'prFilter'],
@@ -215,14 +222,11 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
215
222
  type: 'array',
216
223
  string: true,
217
224
  })
218
- .option('upstream', {
219
- description: 'Name of repository',
220
- alias: 'up',
221
- type: 'string',
222
- })
223
- .option('username', {
224
- description: 'Github username',
225
+ .option('author', {
226
+ description: 'Show commits by a specific user',
227
+ alias: 'author',
225
228
  type: 'string',
229
+ conflicts: 'all',
226
230
  })
227
231
  .option('verbose', {
228
232
  description: 'Show additional debug information',
@@ -252,20 +256,21 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
252
256
  /* eslint-disable @typescript-eslint/no-unused-vars */
253
257
  $0, _,
254
258
  /* eslint-enable @typescript-eslint/no-unused-vars */
255
- multiple, multipleBranches, multipleCommits,
259
+ multiple, multipleBranches, multipleCommits, all, author,
256
260
  // negations
257
261
  verify, noVerify, noCherrypickRef, noFork,
258
262
  // array types (should be renamed to plural form)
259
263
  assignee, path, reviewer, sourcePRLabel, targetBranch, targetBranchChoice, targetPRLabel, ...restOptions } = yargsInstance.parseSync();
260
- return excludeUndefined({
264
+ return (0, excludeUndefined_1.excludeUndefined)({
261
265
  ...restOptions,
266
+ author: all ? null : author,
262
267
  // `multiple` is a cli-only flag to override `multipleBranches` and `multipleCommits`
263
268
  multipleBranches: multiple ?? multipleBranches,
264
269
  multipleCommits: multiple ?? multipleCommits,
265
270
  // rename array types to plural
266
- assignees: assignee ?? [],
267
- commitPaths: path ?? [],
268
- reviewers: reviewer ?? [],
271
+ assignees: assignee,
272
+ commitPaths: path,
273
+ reviewers: reviewer,
269
274
  sourcePRLabels: sourcePRLabel,
270
275
  targetBranchChoices: targetBranchChoice,
271
276
  targetBranches: targetBranch,
@@ -277,7 +282,3 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
277
282
  });
278
283
  }
279
284
  exports.getOptionsFromCliArgs = getOptionsFromCliArgs;
280
- function excludeUndefined(obj) {
281
- Object.keys(obj).forEach((key) => obj[key] === undefined && delete obj[key]);
282
- return obj;
283
- }
@@ -20,20 +20,16 @@ describe('getOptionsFromCliArgs', () => {
20
20
  const argv = [
21
21
  '--access-token',
22
22
  'my access token',
23
- '--username',
24
- 'sqren',
25
- '--upstream',
26
- 'elastic/kibana',
23
+ '--repo-owner',
24
+ 'elastic',
25
+ '--repo-name',
26
+ 'kibana',
27
27
  ];
28
28
  const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
29
29
  expect(res).toEqual({
30
30
  accessToken: 'my access token',
31
- upstream: 'elastic/kibana',
32
- username: 'sqren',
33
- mainline: 1,
34
- reviewers: [],
35
- assignees: [],
36
- commitPaths: [],
31
+ repoOwner: 'elastic',
32
+ repoName: 'kibana',
37
33
  });
38
34
  });
39
35
  });
@@ -1,38 +1,10 @@
1
1
  import { ConfigFileOptions } from '../ConfigOptions';
2
- export declare const defaultConfigOptions: {
3
- all: boolean;
4
- assignees: string[];
5
- autoAssign: boolean;
6
- autoMerge: boolean;
7
- autoMergeMethod: string;
8
- ci: boolean;
9
- cherrypickRef: boolean;
10
- details: boolean;
11
- fork: boolean;
12
- gitHostname: string;
13
- githubApiBaseUrlV3: string;
14
- githubApiBaseUrlV4: string;
15
- maxNumber: number;
16
- multipleBranches: boolean;
17
- multipleCommits: boolean;
18
- noVerify: boolean;
19
- prTitle: string;
20
- resetAuthor: boolean;
21
- sourcePRLabels: never[];
22
- targetBranchChoices: never[];
23
- targetBranches: never[];
24
- targetPRLabels: never[];
25
- verbose: boolean;
26
- };
27
2
  export declare type OptionsFromConfigFiles = Awaited<ReturnType<typeof getOptionsFromConfigFiles>>;
28
3
  export declare function getOptionsFromConfigFiles(optionsFromModule?: ConfigFileOptions): Promise<{
29
- targetPRLabels: string[];
30
- targetBranchChoices: import("../ConfigOptions").TargetBranchChoiceOrString[];
31
4
  accessToken?: string | undefined;
32
- all: boolean;
33
- assignees: string[];
34
- author?: string | undefined;
35
- autoAssign: boolean;
5
+ assignees?: string[] | undefined;
6
+ author?: string | null | undefined;
7
+ autoAssign?: boolean | undefined;
36
8
  autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
37
9
  files: string[];
38
10
  directory: string;
@@ -45,37 +17,41 @@ export declare function getOptionsFromConfigFiles(optionsFromModule?: ConfigFile
45
17
  };
46
18
  targetBranch: string;
47
19
  }) => boolean | Promise<boolean>) | undefined;
48
- autoMerge: boolean;
49
- autoMergeMethod: string;
50
- ci: boolean;
51
- cherrypickRef: boolean;
20
+ autoMerge?: boolean | undefined;
21
+ autoMergeMethod?: string | undefined;
22
+ backportBinary?: string | undefined;
23
+ cherrypickRef?: boolean | undefined;
24
+ ci?: boolean | undefined;
52
25
  commitPaths?: string[] | undefined;
53
- details: boolean;
26
+ details?: boolean | undefined;
54
27
  editor?: string | undefined;
55
- forceLocalConfig?: boolean | undefined;
56
- fork: boolean;
57
- gitHostname: string;
58
- githubApiBaseUrlV3: string;
59
- githubApiBaseUrlV4: string;
60
- maxNumber: number;
28
+ fork?: boolean | undefined;
29
+ gitHostname?: string | undefined;
30
+ githubApiBaseUrlV3?: string | undefined;
31
+ githubApiBaseUrlV4?: string | undefined;
32
+ maxNumber?: number | undefined;
61
33
  multiple?: boolean | undefined;
62
- multipleBranches: boolean;
63
- multipleCommits: boolean;
64
- noVerify: boolean;
34
+ multipleBranches?: boolean | undefined;
35
+ multipleCommits?: boolean | undefined;
36
+ noVerify?: boolean | undefined;
65
37
  prDescription?: string | undefined;
66
38
  prFilter?: string | undefined;
67
- prTitle: string;
39
+ prTitle?: string | undefined;
68
40
  pullNumber?: number | undefined;
69
- resetAuthor: boolean;
41
+ repoName?: string | undefined;
42
+ repoOwner?: string | undefined;
43
+ resetAuthor?: boolean | undefined;
70
44
  reviewers?: string[] | undefined;
71
45
  sha?: string | undefined;
46
+ skipRemoteConfig?: boolean | undefined;
72
47
  sourceBranch?: string | undefined;
73
- sourcePRLabels: string[] | never[];
74
- targetBranches: string[] | never[];
75
- upstream: string | undefined;
76
- username?: string | undefined;
77
- verbose: boolean;
48
+ sourcePRLabels?: string[] | undefined;
49
+ targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
50
+ targetBranches?: string[] | undefined;
51
+ targetPRLabels?: string[] | undefined;
52
+ verbose?: boolean | undefined;
78
53
  branchLabelMapping?: Record<string, string> | undefined;
54
+ upstream?: string | undefined;
79
55
  branches?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
80
56
  labels?: string[] | undefined;
81
57
  }>;
@@ -1,54 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOptionsFromConfigFiles = exports.defaultConfigOptions = void 0;
3
+ exports.getOptionsFromConfigFiles = void 0;
4
4
  const getOptionsFromGit_1 = require("./getOptionsFromGit");
5
5
  const globalConfig_1 = require("./globalConfig");
6
6
  const projectConfig_1 = require("./projectConfig");
7
- exports.defaultConfigOptions = {
8
- all: false,
9
- assignees: [],
10
- autoAssign: false,
11
- autoMerge: false,
12
- autoMergeMethod: 'merge',
13
- ci: false,
14
- cherrypickRef: true,
15
- details: false,
16
- fork: true,
17
- gitHostname: 'github.com',
18
- githubApiBaseUrlV3: 'https://api.github.com',
19
- githubApiBaseUrlV4: 'https://api.github.com/graphql',
20
- maxNumber: 10,
21
- multipleBranches: true,
22
- multipleCommits: false,
23
- noVerify: true,
24
- prTitle: '[{targetBranch}] {commitMessages}',
25
- resetAuthor: false,
26
- sourcePRLabels: [],
27
- targetBranchChoices: [],
28
- targetBranches: [],
29
- targetPRLabels: [],
30
- verbose: false,
31
- };
32
7
  async function getOptionsFromConfigFiles(optionsFromModule) {
33
8
  const [gitConfig, projectConfig, globalConfig] = await Promise.all([
34
9
  (0, getOptionsFromGit_1.getOptionsFromGit)(),
35
10
  (0, projectConfig_1.getProjectConfig)(),
36
11
  (0, globalConfig_1.getGlobalConfig)(optionsFromModule?.ci),
37
12
  ]);
38
- // global and project config combined
39
- const combinedConfig = {
13
+ return {
40
14
  ...gitConfig,
41
15
  ...globalConfig,
42
16
  ...projectConfig,
43
17
  ...optionsFromModule,
44
18
  };
45
- return {
46
- ...exports.defaultConfigOptions,
47
- ...combinedConfig,
48
- // backwards-compatability: `labels` was renamed `targetPRLabels`
49
- targetPRLabels: combinedConfig.targetPRLabels ?? combinedConfig.labels ?? [],
50
- // backwards-compatability: `branches` was renamed `targetBranchChoices`
51
- targetBranchChoices: combinedConfig.targetBranchChoices ?? combinedConfig.branches ?? [],
52
- };
53
19
  }
54
20
  exports.getOptionsFromConfigFiles = getOptionsFromConfigFiles;
@@ -1,39 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mockConfigFiles_1 = require("../../test/mockConfigFiles");
3
4
  const config_1 = require("./config");
4
5
  describe('getOptionsFromConfigFiles', () => {
5
6
  let res;
6
7
  beforeEach(async () => {
8
+ (0, mockConfigFiles_1.mockConfigFiles)({
9
+ globalConfig: { accessToken: 'abc', editor: 'vim' },
10
+ projectConfig: { repoName: 'kibana', repoOwner: 'elastic' },
11
+ });
7
12
  res = await (0, config_1.getOptionsFromConfigFiles)();
8
13
  });
9
- it('should return values from (mock) config files incl. default values', () => {
14
+ it('should return values from config files', () => {
10
15
  expect(res).toEqual({
11
- accessToken: 'myAccessToken',
12
- all: false,
13
- assignees: [],
14
- autoAssign: false,
15
- autoMerge: false,
16
- autoMergeMethod: 'merge',
17
- ci: false,
18
- cherrypickRef: true,
19
- details: false,
20
- fork: true,
21
- gitHostname: 'github.com',
22
- githubApiBaseUrlV3: 'https://api.github.com',
23
- githubApiBaseUrlV4: 'https://api.github.com/graphql',
24
- maxNumber: 10,
25
- multipleBranches: true,
26
- multipleCommits: false,
27
- noVerify: true,
28
- prTitle: '[{targetBranch}] {commitMessages}',
29
- resetAuthor: false,
30
- sourcePRLabels: [],
31
- targetBranchChoices: ['6.0', '5.9'],
32
- targetBranches: [],
33
- targetPRLabels: [],
34
- upstream: 'backport-org/backport-demo',
35
- username: 'sqren',
36
- verbose: false,
16
+ accessToken: 'abc',
17
+ editor: 'vim',
18
+ repoName: 'kibana',
19
+ repoOwner: 'elastic',
37
20
  });
38
21
  });
39
22
  });
@@ -1,3 +1,4 @@
1
1
  export declare function getOptionsFromGit(): Promise<{
2
- upstream: string | undefined;
3
- }>;
2
+ repoOwner: string;
3
+ repoName: string;
4
+ } | undefined>;
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getOptionsFromGit = void 0;
4
4
  const git_1 = require("../../services/git");
5
5
  async function getOptionsFromGit() {
6
- return {
7
- upstream: await (0, git_1.getUpstreamFromGitRemote)(),
8
- };
6
+ return (0, git_1.getRepoOwnerAndNameFromGitRemote)();
9
7
  }
10
8
  exports.getOptionsFromGit = getOptionsFromGit;
@@ -50,11 +50,8 @@ async function createGlobalConfigIfNotExist(globalConfigPath, configTemplate) {
50
50
  exports.createGlobalConfigIfNotExist = createGlobalConfigIfNotExist;
51
51
  function getConfigTemplate() {
52
52
  return `{
53
- // Github personal access token. Must be created here: https://github.com/settings/tokens/new
53
+ // Github personal access token. Must be created here: https://github.com/settings/tokens
54
54
  // Must have "Repo: Full control of private repositories"
55
- "accessToken": "",
56
-
57
- // Github username, eg. kimchy
58
- "username": ""
55
+ "accessToken": ""
59
56
  }`;
60
57
  }
@@ -38,7 +38,6 @@ describe('config', () => {
38
38
  jest.spyOn(fs, 'writeFile').mockResolvedValueOnce();
39
39
  jest.spyOn(fs, 'readFile').mockResolvedValueOnce(JSON.stringify({
40
40
  accessToken: 'myAccessToken',
41
- username: 'sqren',
42
41
  }));
43
42
  res = await (0, globalConfig_1.getGlobalConfig)();
44
43
  });
@@ -54,7 +53,6 @@ describe('config', () => {
54
53
  it('should return config', () => {
55
54
  expect(res).toEqual({
56
55
  accessToken: 'myAccessToken',
57
- username: 'sqren',
58
56
  });
59
57
  });
60
58
  });
@@ -27,21 +27,58 @@ const fs = __importStar(require("../../services/fs-promisified"));
27
27
  const projectConfig_1 = require("./projectConfig");
28
28
  describe('getProjectConfig', () => {
29
29
  afterEach(() => jest.clearAllMocks());
30
- describe('when projectConfig is valid', () => {
31
- let projectConfig;
32
- beforeEach(async () => {
33
- jest
34
- .spyOn(fs, 'readFile')
35
- .mockResolvedValueOnce(JSON.stringify({ upstream: 'elastic/kibana', branches: ['6.x'] }));
36
- projectConfig = await (0, projectConfig_1.getProjectConfig)();
30
+ describe('deprecations', () => {
31
+ describe('when specifying deprecated `branches`', () => {
32
+ it('is returned as `targetBranchChoices`', async () => {
33
+ jest.spyOn(fs, 'readFile').mockResolvedValueOnce(JSON.stringify({
34
+ repoName: 'kibana',
35
+ repoOwner: 'elastic',
36
+ branches: ['6.x'],
37
+ }));
38
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)();
39
+ expect(projectConfig?.targetBranchChoices).toEqual(['6.x']);
40
+ });
41
+ });
42
+ describe('when specifying deprecated `labels`', () => {
43
+ it('is returned as `targetPRLabels`', async () => {
44
+ jest.spyOn(fs, 'readFile').mockResolvedValueOnce(JSON.stringify({
45
+ labels: ['backport'],
46
+ }));
47
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)();
48
+ expect(projectConfig?.targetPRLabels).toEqual(['backport']);
49
+ });
37
50
  });
38
- it('should call findUp', () => {
39
- expect(find_up_1.default).toHaveBeenCalledWith('.backportrc.json');
51
+ describe('when specifying deprecated `upstream`', () => {
52
+ it('is split into `repoOwner` and `repoName`', async () => {
53
+ jest.spyOn(fs, 'readFile').mockResolvedValueOnce(JSON.stringify({
54
+ upstream: 'elastic/kibana',
55
+ }));
56
+ const projectConfig = await (0, projectConfig_1.getProjectConfig)();
57
+ expect(projectConfig?.repoOwner).toEqual('elastic');
58
+ expect(projectConfig?.repoName).toEqual('kibana');
59
+ });
40
60
  });
41
- it('should return config with branches', () => {
42
- expect(projectConfig).toEqual({
43
- branches: ['6.x'],
44
- upstream: 'elastic/kibana',
61
+ describe('when projectConfig is valid', () => {
62
+ let projectConfig;
63
+ beforeEach(async () => {
64
+ jest.spyOn(fs, 'readFile').mockResolvedValueOnce(JSON.stringify({
65
+ repoName: 'kibana',
66
+ repoOwner: 'elastic',
67
+ targetBranchChoices: ['6.x'],
68
+ targetPRLabels: ['backport'],
69
+ }));
70
+ projectConfig = await (0, projectConfig_1.getProjectConfig)();
71
+ });
72
+ it('should call findUp', () => {
73
+ expect(find_up_1.default).toHaveBeenCalledWith('.backportrc.json');
74
+ });
75
+ it('should return config', () => {
76
+ expect(projectConfig).toEqual({
77
+ repoName: 'kibana',
78
+ repoOwner: 'elastic',
79
+ targetBranchChoices: ['6.x'],
80
+ targetPRLabels: ['backport'],
81
+ });
45
82
  });
46
83
  });
47
84
  });
@@ -49,7 +86,7 @@ describe('getProjectConfig', () => {
49
86
  it('should return empty config', async () => {
50
87
  jest.spyOn(fs, 'readFile').mockResolvedValueOnce('{}');
51
88
  const projectConfig = await (0, projectConfig_1.getProjectConfig)();
52
- expect(projectConfig).toEqual({ targetBranchChoices: undefined });
89
+ expect(projectConfig).toEqual({});
53
90
  });
54
91
  });
55
92
  describe('when projectConfig is missing', () => {
@@ -1,2 +1,54 @@
1
1
  import { ConfigFileOptions } from '../ConfigOptions';
2
2
  export declare function readConfigFile(filepath: string): Promise<ConfigFileOptions>;
3
+ export declare function withConfigMigrations({ upstream, labels, branches, ...config }: ConfigFileOptions): {
4
+ fork?: boolean | undefined;
5
+ verbose?: boolean | undefined;
6
+ accessToken?: string | undefined;
7
+ assignees?: string[] | undefined;
8
+ author?: string | null | undefined;
9
+ autoAssign?: boolean | undefined;
10
+ autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
11
+ files: string[];
12
+ directory: string;
13
+ logger: {
14
+ error: (message: string, meta?: unknown) => void;
15
+ warn: (message: string, meta?: unknown) => void;
16
+ info: (message: string, meta?: unknown) => void;
17
+ verbose: (message: string, meta?: unknown) => void;
18
+ debug: (message: string, meta?: unknown) => void;
19
+ };
20
+ targetBranch: string;
21
+ }) => boolean | Promise<boolean>) | undefined;
22
+ autoMerge?: boolean | undefined;
23
+ autoMergeMethod?: string | undefined;
24
+ backportBinary?: string | undefined;
25
+ cherrypickRef?: boolean | undefined;
26
+ ci?: boolean | undefined;
27
+ commitPaths?: string[] | undefined;
28
+ details?: boolean | undefined;
29
+ editor?: string | undefined;
30
+ gitHostname?: string | undefined;
31
+ githubApiBaseUrlV3?: string | undefined;
32
+ githubApiBaseUrlV4?: string | undefined;
33
+ maxNumber?: number | undefined;
34
+ multiple?: boolean | undefined;
35
+ multipleBranches?: boolean | undefined;
36
+ multipleCommits?: boolean | undefined;
37
+ noVerify?: boolean | undefined;
38
+ prDescription?: string | undefined;
39
+ prFilter?: string | undefined;
40
+ prTitle?: string | undefined;
41
+ pullNumber?: number | undefined;
42
+ repoName?: string | undefined;
43
+ repoOwner?: string | undefined;
44
+ resetAuthor?: boolean | undefined;
45
+ reviewers?: string[] | undefined;
46
+ sha?: string | undefined;
47
+ skipRemoteConfig?: boolean | undefined;
48
+ sourceBranch?: string | undefined;
49
+ sourcePRLabels?: string[] | undefined;
50
+ targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
51
+ targetBranches?: string[] | undefined;
52
+ targetPRLabels?: string[] | undefined;
53
+ branchLabelMapping?: Record<string, string> | undefined;
54
+ };
@@ -3,18 +3,44 @@ 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.readConfigFile = void 0;
6
+ exports.withConfigMigrations = exports.readConfigFile = void 0;
7
7
  const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
8
8
  const HandledError_1 = require("../../services/HandledError");
9
9
  const fs_promisified_1 = require("../../services/fs-promisified");
10
+ const excludeUndefined_1 = require("../../utils/excludeUndefined");
10
11
  async function readConfigFile(filepath) {
11
12
  const fileContents = await (0, fs_promisified_1.readFile)(filepath, 'utf8');
12
13
  const configWithoutComments = (0, strip_json_comments_1.default)(fileContents);
13
14
  try {
14
- return JSON.parse(configWithoutComments);
15
+ return withConfigMigrations(JSON.parse(configWithoutComments));
15
16
  }
16
17
  catch (e) {
17
18
  throw new HandledError_1.HandledError(`"${filepath}" contains invalid JSON:\n\n${fileContents}`);
18
19
  }
19
20
  }
20
21
  exports.readConfigFile = readConfigFile;
22
+ // ensure backwards compatability when config options are renamed
23
+ function withConfigMigrations({ upstream, labels, branches, ...config }) {
24
+ const { repoName, repoOwner } = parseUpstream(upstream, config);
25
+ return (0, excludeUndefined_1.excludeUndefined)({
26
+ ...config,
27
+ // `branches` was renamed `targetBranchChoices`
28
+ targetBranchChoices: config.targetBranchChoices ?? branches,
29
+ // `upstream` has been renamed to `repoOwner`/`repoName`
30
+ repoName,
31
+ repoOwner,
32
+ // `labels` was renamed `targetPRLabels`
33
+ targetPRLabels: config.targetPRLabels ?? labels,
34
+ });
35
+ }
36
+ exports.withConfigMigrations = withConfigMigrations;
37
+ function parseUpstream(upstream, config) {
38
+ if (upstream) {
39
+ const [repoOwner, repoName] = upstream.split('/');
40
+ return { repoOwner, repoName };
41
+ }
42
+ return {
43
+ repoOwner: config.repoOwner,
44
+ repoName: config.repoName,
45
+ };
46
+ }