backport 6.0.0 → 6.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 (98) hide show
  1. package/README.md +158 -42
  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 +33 -0
  7. package/dist/main.js +1 -2
  8. package/dist/options/ConfigOptions.d.ts +15 -6
  9. package/dist/options/cliArgs.d.ts +33 -34
  10. package/dist/options/cliArgs.js +19 -19
  11. package/dist/options/cliArgs.test.js +8 -5
  12. package/dist/options/config/config.d.ts +27 -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 +1 -4
  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 +51 -0
  21. package/dist/options/config/readConfigFile.js +28 -2
  22. package/dist/options/options.d.ts +52 -33
  23. package/dist/options/options.js +98 -7
  24. package/dist/options/options.test.js +180 -73
  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 +35 -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 +78 -0
  38. package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
  39. package/dist/services/github/v4/apiRequestV4.js +1 -1
  40. package/dist/services/github/v4/enablePullRequestAutoMerge.js +1 -1
  41. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -1
  42. package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
  43. package/dist/services/github/v4/fetchAuthorId.js +5 -6
  44. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
  45. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +8 -1
  46. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  47. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +6 -3
  48. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +8 -1
  49. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -1
  50. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -3
  51. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +12 -1
  52. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +6 -8
  53. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +10 -12
  54. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -7
  55. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
  56. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
  57. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +5 -5
  58. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -6
  59. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -2
  60. package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
  61. package/dist/services/github/v4/fetchProjectConfig.js +56 -0
  62. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
  63. package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
  64. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
  65. package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
  66. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +66 -0
  67. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
  68. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  69. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
  70. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +3 -1
  71. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +22 -1
  72. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +4 -1
  73. package/dist/services/github/v4/getOptionsFromGithub/query.js +3 -0
  74. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +15 -15
  75. package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -1
  76. package/dist/services/sourceCommit/parseSourceCommit.js +2 -2
  77. package/dist/services/sourceCommit/parseSourceCommit.test.js +120 -5
  78. package/dist/test/inquirer.private.test.js +42 -34
  79. package/dist/test/integration/integration.private.test.js +104 -95
  80. package/dist/test/mockConfigFiles.d.ts +5 -0
  81. package/dist/test/mockConfigFiles.js +37 -0
  82. package/dist/test/nockHelpers.d.ts +1 -1
  83. package/dist/test/nockHelpers.js +4 -4
  84. package/dist/test/private/getDevAccessToken.js +1 -1
  85. package/dist/test/setupFiles/automatic-mocks.js +1 -29
  86. package/dist/ui/cherrypickAndCreatePullRequest.test.js +67 -28
  87. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +6 -3
  88. package/dist/ui/getCommits.d.ts +1 -1
  89. package/dist/ui/getTargetBranches.d.ts +2 -1
  90. package/dist/ui/getTargetBranches.js +17 -1
  91. package/dist/ui/maybeSetupRepo.js +4 -3
  92. package/dist/ui/maybeSetupRepo.test.js +49 -3
  93. package/dist/utils/excludeUndefined.d.ts +6 -0
  94. package/dist/utils/excludeUndefined.js +7 -0
  95. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  96. package/dist/utils/excludeUndefined.test.js +24 -0
  97. package/package.json +9 -8
  98. package/yarn.lock +98 -77
@@ -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,40 @@ 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
+ cherrypickRef?: boolean | undefined;
23
+ ci?: boolean | undefined;
52
24
  commitPaths?: string[] | undefined;
53
- details: boolean;
25
+ details?: boolean | undefined;
54
26
  editor?: string | undefined;
55
- forceLocalConfig?: boolean | undefined;
56
- fork: boolean;
57
- gitHostname: string;
58
- githubApiBaseUrlV3: string;
59
- githubApiBaseUrlV4: string;
60
- maxNumber: number;
27
+ fork?: boolean | undefined;
28
+ gitHostname?: string | undefined;
29
+ githubApiBaseUrlV3?: string | undefined;
30
+ githubApiBaseUrlV4?: string | undefined;
31
+ maxNumber?: number | undefined;
61
32
  multiple?: boolean | undefined;
62
- multipleBranches: boolean;
63
- multipleCommits: boolean;
64
- noVerify: boolean;
33
+ multipleBranches?: boolean | undefined;
34
+ multipleCommits?: boolean | undefined;
35
+ noVerify?: boolean | undefined;
65
36
  prDescription?: string | undefined;
66
37
  prFilter?: string | undefined;
67
- prTitle: string;
38
+ prTitle?: string | undefined;
68
39
  pullNumber?: number | undefined;
69
- resetAuthor: boolean;
40
+ repoName?: string | undefined;
41
+ repoOwner?: string | undefined;
42
+ resetAuthor?: boolean | undefined;
70
43
  reviewers?: string[] | undefined;
71
44
  sha?: string | undefined;
45
+ skipRemoteConfig?: boolean | undefined;
72
46
  sourceBranch?: string | undefined;
73
- sourcePRLabels: string[] | never[];
74
- targetBranches: string[] | never[];
75
- upstream: string | undefined;
76
- username?: string | undefined;
77
- verbose: boolean;
47
+ sourcePRLabels?: string[] | undefined;
48
+ targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
49
+ targetBranches?: string[] | undefined;
50
+ targetPRLabels?: string[] | undefined;
51
+ verbose?: boolean | undefined;
78
52
  branchLabelMapping?: Record<string, string> | undefined;
53
+ upstream?: string | undefined;
79
54
  branches?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
80
55
  labels?: string[] | undefined;
81
56
  }>;
@@ -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;
@@ -52,9 +52,6 @@ function getConfigTemplate() {
52
52
  return `{
53
53
  // Github personal access token. Must be created here: https://github.com/settings/tokens/new
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,53 @@
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
+ cherrypickRef?: boolean | undefined;
25
+ ci?: boolean | undefined;
26
+ commitPaths?: string[] | undefined;
27
+ details?: boolean | undefined;
28
+ editor?: string | undefined;
29
+ gitHostname?: string | undefined;
30
+ githubApiBaseUrlV3?: string | undefined;
31
+ githubApiBaseUrlV4?: string | undefined;
32
+ maxNumber?: number | undefined;
33
+ multiple?: boolean | undefined;
34
+ multipleBranches?: boolean | undefined;
35
+ multipleCommits?: boolean | undefined;
36
+ noVerify?: boolean | undefined;
37
+ prDescription?: string | undefined;
38
+ prFilter?: string | undefined;
39
+ prTitle?: string | undefined;
40
+ pullNumber?: number | undefined;
41
+ repoName?: string | undefined;
42
+ repoOwner?: string | undefined;
43
+ resetAuthor?: boolean | undefined;
44
+ reviewers?: string[] | undefined;
45
+ sha?: string | undefined;
46
+ skipRemoteConfig?: boolean | undefined;
47
+ sourceBranch?: string | undefined;
48
+ sourcePRLabels?: string[] | undefined;
49
+ targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
50
+ targetBranches?: string[] | undefined;
51
+ targetPRLabels?: string[] | undefined;
52
+ branchLabelMapping?: Record<string, string> | undefined;
53
+ };
@@ -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
+ }
@@ -1,45 +1,66 @@
1
- import { ConfigFileOptions } from './ConfigOptions';
1
+ import { ConfigFileOptions, TargetBranchChoiceOrString } from './ConfigOptions';
2
2
  export declare type ValidConfigOptions = Readonly<Awaited<ReturnType<typeof getOptions>>>;
3
- export declare function getOptions(argv: string[], optionsFromModule?: ConfigFileOptions): Promise<{
4
- targetBranchChoices: import("./ConfigOptions").TargetBranchChoice[];
5
- accessToken: string;
6
- username: string;
7
- repoName: string;
8
- repoOwner: string;
3
+ export declare const defaultConfigOptions: {
9
4
  assignees: string[];
10
- author: string;
11
- all: boolean;
5
+ autoAssign: boolean;
6
+ autoMerge: boolean;
7
+ autoMergeMethod: string;
8
+ cherrypickRef: boolean;
9
+ ci: boolean;
10
+ details: boolean;
11
+ fork: boolean;
12
+ maxNumber: number;
12
13
  multipleBranches: boolean;
13
14
  multipleCommits: boolean;
14
- commitPaths: string[];
15
- reviewers: string[];
16
- sourcePRLabels: (string[] | undefined) & (string[] | never[]);
17
- targetBranches: (string[] | undefined) & (string[] | never[]);
15
+ noVerify: boolean;
16
+ resetAuthor: boolean;
17
+ sourcePRLabels: string[];
18
+ targetBranchChoices: TargetBranchChoiceOrString[];
19
+ targetBranches: string[];
18
20
  targetPRLabels: string[];
19
- cherrypickRef: boolean;
21
+ verbose: boolean;
22
+ };
23
+ export declare function getOptions(argv: string[], optionsFromModule?: ConfigFileOptions): Promise<{
24
+ accessToken: string;
25
+ repoName: string;
26
+ repoOwner: string;
20
27
  fork: boolean;
21
- noVerify: boolean;
28
+ verbose: boolean;
29
+ assignees: string[];
30
+ author: string | null;
22
31
  autoAssign: boolean;
23
32
  autoMerge: boolean;
24
33
  autoMergeMethod: string;
34
+ cherrypickRef: boolean;
25
35
  ci: boolean;
36
+ commitPaths: string[];
26
37
  details: boolean;
27
- editor: string | undefined;
28
- forceLocalConfig: boolean | undefined;
29
- gitHostname: string;
30
- githubApiBaseUrlV3: string;
31
- githubApiBaseUrlV4: string;
32
- mainline: number | undefined;
38
+ editor?: string | undefined;
39
+ gitHostname?: string | undefined;
40
+ githubApiBaseUrlV3?: string | undefined;
41
+ githubApiBaseUrlV4?: string | undefined;
33
42
  maxNumber: number;
34
- prDescription: string | undefined;
35
- prTitle: string;
36
- prFilter: string | undefined;
37
- pullNumber: number | undefined;
43
+ multipleBranches: boolean;
44
+ multipleCommits: boolean;
45
+ noVerify: boolean;
46
+ prDescription?: string | undefined;
47
+ prFilter?: string | undefined;
48
+ prTitle?: string | undefined;
49
+ pullNumber?: number | undefined;
38
50
  resetAuthor: boolean;
39
- sha: string | undefined;
51
+ reviewers: string[];
52
+ sha?: string | undefined;
53
+ skipRemoteConfig?: boolean | undefined;
40
54
  sourceBranch: string;
41
- upstream: string | undefined;
42
- verbose: boolean;
55
+ sourcePRLabels: string[];
56
+ targetBranchChoices: string[] | TargetBranchChoiceOrString[];
57
+ targetBranches: string[];
58
+ targetPRLabels: string[];
59
+ mainline?: number | undefined;
60
+ historicalBranchLabelMappings: {
61
+ branchLabelMapping: Record<string, string>;
62
+ committedDate: string;
63
+ }[];
43
64
  autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
44
65
  files: string[];
45
66
  directory: string;
@@ -54,10 +75,8 @@ export declare function getOptions(argv: string[], optionsFromModule?: ConfigFil
54
75
  }) => boolean | Promise<boolean>) | undefined;
55
76
  multiple?: boolean | undefined;
56
77
  branchLabelMapping?: Record<string, string> | undefined;
57
- branches?: import("./ConfigOptions").TargetBranchChoiceOrString[] | undefined;
78
+ upstream?: string | undefined;
79
+ branches?: TargetBranchChoiceOrString[] | undefined;
58
80
  labels?: string[] | undefined;
59
- historicalBranchLabelMappings: {
60
- branchLabelMapping: Record<string, string>;
61
- committedDate: string;
62
- }[];
81
+ authenticatedUsername: string;
63
82
  }>;
@@ -1,18 +1,109 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOptions = void 0;
4
- const getOptionsFromGithub_1 = require("../services/github/v4/getOptionsFromGithub");
3
+ exports.getOptions = exports.defaultConfigOptions = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const HandledError_1 = require("../services/HandledError");
6
+ const env_1 = require("../services/env");
7
+ const getOptionsFromGithub_1 = require("../services/github/v4/getOptionsFromGithub/getOptionsFromGithub");
5
8
  const logger_1 = require("./../services/logger");
6
9
  const cliArgs_1 = require("./cliArgs");
7
10
  const config_1 = require("./config/config");
8
- const parseRequiredOptions_1 = require("./parseRequiredOptions");
11
+ const PROJECT_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson';
12
+ const GLOBAL_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson';
13
+ exports.defaultConfigOptions = {
14
+ assignees: [],
15
+ autoAssign: false,
16
+ autoMerge: false,
17
+ autoMergeMethod: 'merge',
18
+ cherrypickRef: true,
19
+ ci: false,
20
+ details: false,
21
+ fork: true,
22
+ maxNumber: 10,
23
+ multipleBranches: true,
24
+ multipleCommits: false,
25
+ noVerify: true,
26
+ resetAuthor: false,
27
+ sourcePRLabels: [],
28
+ targetBranchChoices: [],
29
+ targetBranches: [],
30
+ targetPRLabels: [],
31
+ verbose: false,
32
+ };
9
33
  async function getOptions(argv, optionsFromModule) {
10
34
  const optionsFromConfigFiles = await (0, config_1.getOptionsFromConfigFiles)(optionsFromModule);
11
35
  const optionsFromCliArgs = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
36
+ // combined options from cli and config files
37
+ const combined = getCombinedOptions({
38
+ optionsFromConfigFiles,
39
+ optionsFromCliArgs,
40
+ });
12
41
  // update logger
13
- (0, logger_1.updateLogger)({ ...optionsFromConfigFiles, ...optionsFromCliArgs });
14
- const optionsFromGithub = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs);
15
- const parsedOptions = (0, parseRequiredOptions_1.parseRequiredOptions)(optionsFromConfigFiles, optionsFromCliArgs, optionsFromGithub);
16
- return parsedOptions;
42
+ (0, logger_1.updateLogger)(combined);
43
+ // required
44
+ const accessToken = requireAccessToken(combined);
45
+ const repoName = requireRepoName(combined);
46
+ const repoOwner = requireRepoOwner(combined);
47
+ const optionsFromGithub = await (0, getOptionsFromGithub_1.getOptionsFromGithub)({
48
+ ...combined,
49
+ // required props
50
+ accessToken,
51
+ repoName,
52
+ repoOwner,
53
+ });
54
+ const res = {
55
+ // default author
56
+ author: optionsFromGithub.authenticatedUsername,
57
+ // default values have lowest precedence
58
+ ...exports.defaultConfigOptions,
59
+ // local config options override default options
60
+ ...optionsFromConfigFiles,
61
+ // remote config options override local config options
62
+ ...optionsFromGithub,
63
+ // cli args override the above
64
+ ...optionsFromCliArgs,
65
+ // required properties
66
+ accessToken,
67
+ repoName,
68
+ repoOwner,
69
+ };
70
+ requireTargetBranch(res);
71
+ return res;
17
72
  }
18
73
  exports.getOptions = getOptions;
74
+ function getCombinedOptions({ optionsFromConfigFiles, optionsFromCliArgs, }) {
75
+ return {
76
+ ...exports.defaultConfigOptions,
77
+ ...optionsFromConfigFiles,
78
+ ...optionsFromCliArgs,
79
+ };
80
+ }
81
+ function requireAccessToken(combinedOptions) {
82
+ // accessToken must be supplied in config or via cli args
83
+ if (!combinedOptions.accessToken) {
84
+ const globalConfigPath = (0, env_1.getGlobalConfigPath)();
85
+ throw new HandledError_1.HandledError(`Please update your config file: ${globalConfigPath}.\nIt must contain a valid "accessToken".\n\nRead more: ${GLOBAL_CONFIG_DOCS_LINK}`);
86
+ }
87
+ return combinedOptions.accessToken;
88
+ }
89
+ function requireRepoName(combinedOptions) {
90
+ if (!combinedOptions.repoName) {
91
+ throw new HandledError_1.HandledError(`Please specify a repo name: "--repo-name kibana". \n\nRead more: ${PROJECT_CONFIG_DOCS_LINK}`);
92
+ }
93
+ return combinedOptions.repoName;
94
+ }
95
+ function requireRepoOwner(combinedOptions) {
96
+ if (!combinedOptions.repoOwner) {
97
+ throw new HandledError_1.HandledError(`Please specify a repo owner: "--repo-owner elastic". \n\nRead more: ${PROJECT_CONFIG_DOCS_LINK}`);
98
+ }
99
+ return combinedOptions.repoOwner;
100
+ }
101
+ function requireTargetBranch(config) {
102
+ // ensure `targetBranches` or `targetBranchChoices` are given
103
+ if ((0, lodash_1.isEmpty)(config.targetBranches) &&
104
+ (0, lodash_1.isEmpty)(config.targetBranchChoices) &&
105
+ // this is primarily necessary on CI where `targetBranches` and `targetBranchChoices` and not given
106
+ (0, lodash_1.isEmpty)(config.branchLabelMapping)) {
107
+ throw new HandledError_1.HandledError(`Please specify a target branch: "--branch 6.1". \n\n Read more: ${PROJECT_CONFIG_DOCS_LINK}`);
108
+ }
109
+ }