backport 5.6.6 → 6.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/README.md +186 -50
  2. package/dist/entrypoint.cli.js +3 -1
  3. package/dist/entrypoint.module.d.ts +18 -5
  4. package/dist/entrypoint.module.js +42 -12
  5. package/dist/entrypoint.module.private.test.d.ts +1 -0
  6. package/dist/entrypoint.module.private.test.js +34 -0
  7. package/dist/ink.d.ts +1 -0
  8. package/dist/ink.js +49 -0
  9. package/dist/main.d.ts +11 -6
  10. package/dist/main.js +40 -25
  11. package/dist/options/ConfigOptions.d.ts +28 -13
  12. package/dist/options/cliArgs.d.ts +36 -35
  13. package/dist/options/cliArgs.js +91 -52
  14. package/dist/options/cliArgs.test.js +35 -43
  15. package/dist/options/config/config.d.ts +35 -57
  16. package/dist/options/config/config.js +5 -39
  17. package/dist/options/config/config.test.js +11 -27
  18. package/dist/options/config/getOptionsFromGit.d.ts +3 -2
  19. package/dist/options/config/getOptionsFromGit.js +1 -3
  20. package/dist/options/config/globalConfig.d.ts +2 -51
  21. package/dist/options/config/globalConfig.js +9 -12
  22. package/dist/options/config/globalConfig.test.js +7 -5
  23. package/dist/options/config/projectConfig.d.ts +2 -51
  24. package/dist/options/config/projectConfig.js +2 -2
  25. package/dist/options/config/projectConfig.test.js +53 -16
  26. package/dist/options/config/readConfigFile.d.ts +44 -41
  27. package/dist/options/config/readConfigFile.js +30 -4
  28. package/dist/options/options.d.ts +59 -31
  29. package/dist/options/options.js +103 -10
  30. package/dist/options/options.test.js +266 -79
  31. package/dist/options/parseRequiredOptions.d.ts +19 -14
  32. package/dist/options/parseRequiredOptions.js +9 -15
  33. package/dist/options/parseRequiredOptions.test.js +30 -26
  34. package/dist/runSequentially.d.ts +20 -0
  35. package/dist/runSequentially.js +41 -0
  36. package/dist/runSequentially.test.d.ts +1 -0
  37. package/dist/runSequentially.test.js +196 -0
  38. package/dist/runWithOptions.js +7 -14
  39. package/dist/runWithOptions.test.js +138 -17
  40. package/dist/scripts/generate-gql.d.ts +1 -0
  41. package/dist/scripts/generate-gql.js +15 -0
  42. package/dist/scripts/postinstall.js +4 -4
  43. package/dist/scripts/postinstall.test.js +9 -2
  44. package/dist/scripts/runPostinstall.js +1 -1
  45. package/dist/services/HandledError.d.ts +11 -1
  46. package/dist/services/HandledError.js +2 -1
  47. package/dist/services/child-process-promisified.d.ts +1 -1
  48. package/dist/services/child-process-promisified.js +1 -1
  49. package/dist/services/env.js +5 -5
  50. package/dist/services/env.test.js +11 -4
  51. package/dist/services/fs-promisified.js +4 -4
  52. package/dist/services/getExpectedTarget.d.ts +9 -0
  53. package/dist/services/getExpectedTarget.js +77 -0
  54. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  55. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  56. package/dist/services/git.d.ts +20 -6
  57. package/dist/services/git.integration.test.d.ts +1 -0
  58. package/dist/services/git.integration.test.js +168 -0
  59. package/dist/services/git.js +93 -67
  60. package/dist/services/git.test.js +68 -68
  61. package/dist/services/github/commitFormatters.d.ts +3 -7
  62. package/dist/services/github/commitFormatters.js +10 -19
  63. package/dist/services/github/commitFormatters.test.js +2 -24
  64. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  65. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -8
  66. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +6 -8
  67. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  68. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  69. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  70. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  71. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  72. package/dist/services/github/v3/createPullRequest.js +31 -25
  73. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  74. package/dist/services/github/v3/createPullRequest.test.js +110 -0
  75. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  76. package/dist/services/github/v3/createStatusComment.js +95 -0
  77. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  78. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  79. package/dist/services/github/v4/FetchPullRequestId.js +1 -1
  80. package/dist/services/github/v4/apiRequestV4.d.ts +2 -2
  81. package/dist/services/github/v4/apiRequestV4.js +6 -8
  82. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  83. package/dist/services/github/v4/disablePullRequestAutoMerge.js +3 -4
  84. package/dist/services/github/v4/enablePullRequestAutoMerge.js +9 -8
  85. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +93 -33
  86. package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
  87. package/dist/services/github/v4/fetchAuthorId.js +6 -7
  88. package/dist/services/github/v4/fetchAuthorId.private.test.js +6 -9
  89. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  90. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +4 -4
  91. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  92. package/dist/services/github/v4/fetchCommitBySha.private.test.js +4 -4
  93. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +12 -0
  94. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  95. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  96. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +70 -0
  97. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +12 -0
  98. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +27 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +88 -0
  103. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  104. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +128 -0
  105. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  106. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +125 -0
  107. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  108. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  109. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
  110. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
  111. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  112. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  113. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  114. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +77 -0
  115. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  116. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  117. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +2 -1
  118. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  119. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +78 -5
  120. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  121. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  122. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  123. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -5
  124. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +18 -19
  125. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -69
  126. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  127. package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
  128. package/dist/services/github/v4/fetchProjectConfig.js +56 -0
  129. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
  130. package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
  131. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
  132. package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
  133. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +2 -3
  134. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  135. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +3 -3
  136. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  137. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  138. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  139. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +67 -0
  140. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
  141. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  142. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
  143. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +19 -11
  144. package/dist/services/github/v4/getOptionsFromGithub/index.js +52 -22
  145. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +46 -7
  146. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +16 -16
  147. package/dist/services/github/v4/getOptionsFromGithub/query.js +16 -15
  148. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  149. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  150. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  151. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  152. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  153. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +1 -1
  154. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  155. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +1 -1
  156. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +2 -0
  157. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  158. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  159. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  160. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  161. package/dist/services/logger.d.ts +3 -3
  162. package/dist/services/logger.js +16 -15
  163. package/dist/services/prompt.test.d.ts +1 -0
  164. package/dist/services/prompt.test.js +87 -0
  165. package/dist/services/prompts.d.ts +10 -4
  166. package/dist/services/prompts.js +85 -22
  167. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  168. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  169. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  170. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +413 -0
  171. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  172. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  173. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  174. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  175. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  176. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  177. package/dist/services/sourceCommit/parseSourceCommit.d.ts +82 -0
  178. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  179. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  180. package/dist/services/sourceCommit/parseSourceCommit.test.js +229 -0
  181. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  182. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  183. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  184. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  185. package/dist/services/sourceCommit.d.ts +78 -0
  186. package/dist/services/sourceCommit.js +86 -0
  187. package/dist/services/sourceCommit.test.d.ts +1 -0
  188. package/dist/services/sourceCommit.test.js +280 -0
  189. package/dist/test/inquirer.private.test.js +55 -51
  190. package/dist/test/integration/createSpies.js +6 -6
  191. package/dist/test/integration/envConstants.js +5 -6
  192. package/dist/test/integration/helpers.js +1 -1
  193. package/dist/test/integration/integration.private.test.d.ts +1 -0
  194. package/dist/test/integration/integration.private.test.js +327 -0
  195. package/dist/test/integration/integration.test.js +28 -29
  196. package/dist/test/mockConfigFiles.d.ts +5 -0
  197. package/dist/test/mockConfigFiles.js +37 -0
  198. package/dist/test/nockHelpers.d.ts +1 -1
  199. package/dist/test/nockHelpers.js +7 -11
  200. package/dist/test/private/getDevAccessToken.js +1 -1
  201. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  202. package/dist/test/setupFiles/automatic-mocks.js +1 -51
  203. package/dist/types/Commit.d.ts +85 -0
  204. package/dist/types/Commit.js +139 -0
  205. package/dist/types/commitNode.d.ts +89 -0
  206. package/dist/types/commitNode.js +139 -0
  207. package/dist/types/commitNode.test.d.ts +1 -0
  208. package/dist/types/commitNode.test.js +255 -0
  209. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  210. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  211. package/dist/ui/cherrypickAndCreatePullRequest.test.js +346 -76
  212. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +2 -1
  213. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +95 -67
  214. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  215. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  216. package/dist/ui/getCommits.d.ts +1 -1
  217. package/dist/ui/getCommits.js +55 -25
  218. package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
  219. package/dist/ui/getCommitsWithoutBackports.js +53 -0
  220. package/dist/ui/getTargetBranches.d.ts +3 -2
  221. package/dist/ui/getTargetBranches.js +33 -18
  222. package/dist/ui/getTargetBranches.test.js +75 -99
  223. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  224. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  225. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  226. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  227. package/dist/ui/maybeSetupRepo.js +11 -10
  228. package/dist/ui/maybeSetupRepo.test.js +54 -4
  229. package/dist/utils/excludeUndefined.d.ts +6 -0
  230. package/dist/utils/excludeUndefined.js +7 -0
  231. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  232. package/dist/utils/excludeUndefined.test.js +24 -0
  233. package/package.json +37 -51
  234. package/yarn.lock +2414 -2993
@@ -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
- const fileContents = await fs_promisified_1.readFile(filepath, 'utf8');
12
- const configWithoutComments = strip_json_comments_1.default(fileContents);
12
+ const fileContents = await (0, fs_promisified_1.readFile)(filepath, 'utf8');
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,44 +1,69 @@
1
- import { PromiseReturnType } from '../types/PromiseReturnType';
2
- import { ConfigOptions } from './ConfigOptions';
3
- export declare type ValidConfigOptions = Readonly<PromiseReturnType<typeof getOptions>>;
4
- export declare function getOptions(argv: string[], optionsFromModule?: ConfigOptions): Promise<{
5
- targetBranchChoices: import("./ConfigOptions").BranchChoice[];
6
- accessToken: string;
7
- username: string;
8
- repoName: string;
9
- repoOwner: string;
1
+ import { ConfigFileOptions, TargetBranchChoiceOrString } from './ConfigOptions';
2
+ export declare type ValidConfigOptions = Readonly<Awaited<ReturnType<typeof getOptions>>>;
3
+ export declare const defaultConfigOptions: {
10
4
  assignees: string[];
11
- author: string;
12
- all: boolean;
5
+ autoAssign: boolean;
6
+ autoMerge: boolean;
7
+ autoMergeMethod: string;
8
+ backportBinary: string;
9
+ cherrypickRef: boolean;
10
+ ci: boolean;
11
+ commitPaths: string[];
12
+ details: boolean;
13
+ fork: boolean;
14
+ maxNumber: number;
13
15
  multipleBranches: boolean;
14
16
  multipleCommits: boolean;
15
17
  noVerify: boolean;
18
+ resetAuthor: boolean;
19
+ reviewers: string[];
20
+ sourcePRLabels: string[];
21
+ targetBranchChoices: TargetBranchChoiceOrString[];
22
+ targetBranches: string[];
23
+ targetPRLabels: string[];
24
+ verbose: boolean;
25
+ };
26
+ export declare function getOptions(argv: string[], optionsFromModule?: ConfigFileOptions): Promise<{
27
+ accessToken: string;
28
+ repoName: string;
29
+ repoOwner: string;
30
+ fork: boolean;
31
+ verbose: boolean;
32
+ assignees: string[];
33
+ author: string | null;
16
34
  autoAssign: boolean;
17
35
  autoMerge: boolean;
18
36
  autoMergeMethod: string;
37
+ cherrypickRef: boolean;
19
38
  ci: boolean;
20
- dryRun: boolean;
21
- editor: string | undefined;
22
- forceLocalConfig: boolean | undefined;
23
- fork: boolean;
24
- gitHostname: string;
25
- githubApiBaseUrlV3: string;
26
- githubApiBaseUrlV4: string;
27
- mainline: number | undefined;
39
+ commitPaths: string[];
40
+ details: boolean;
41
+ editor?: string | undefined;
42
+ gitHostname?: string | undefined;
43
+ githubApiBaseUrlV3?: string | undefined;
44
+ githubApiBaseUrlV4?: string | undefined;
28
45
  maxNumber: number;
29
- path: string | undefined;
30
- prTitle: string;
31
- prDescription: string | undefined;
32
- prFilter: string | undefined;
33
- pullNumber: number | undefined;
46
+ multipleBranches: boolean;
47
+ multipleCommits: boolean;
48
+ noVerify: boolean;
49
+ prDescription?: string | undefined;
50
+ prFilter?: string | undefined;
51
+ prTitle?: string | undefined;
52
+ pullNumber?: number | undefined;
34
53
  resetAuthor: boolean;
35
- sha: string | undefined;
54
+ reviewers: string[];
55
+ sha?: string | undefined;
56
+ skipRemoteConfig?: boolean | undefined;
36
57
  sourceBranch: string;
37
- sourcePRLabels: string[] | (string[] & never[]);
38
- targetBranches: string[] | (string[] & never[]);
58
+ sourcePRLabels: string[];
59
+ targetBranchChoices: string[] | TargetBranchChoiceOrString[];
60
+ targetBranches: string[];
39
61
  targetPRLabels: string[];
40
- upstream: string | undefined;
41
- verbose: boolean;
62
+ mainline?: number | undefined;
63
+ historicalBranchLabelMappings: {
64
+ branchLabelMapping: Record<string, string>;
65
+ committedDate: string;
66
+ }[];
42
67
  autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
43
68
  files: string[];
44
69
  directory: string;
@@ -51,8 +76,11 @@ export declare function getOptions(argv: string[], optionsFromModule?: ConfigOpt
51
76
  };
52
77
  targetBranch: string;
53
78
  }) => boolean | Promise<boolean>) | undefined;
54
- branchLabelMapping?: Record<string, string> | undefined;
79
+ backportBinary: string;
55
80
  multiple?: boolean | undefined;
56
- branches?: import("./ConfigOptions").BranchChoiceRaw[] | undefined;
81
+ branchLabelMapping?: Record<string, string> | undefined;
82
+ upstream?: string | undefined;
83
+ branches?: TargetBranchChoiceOrString[] | undefined;
57
84
  labels?: string[] | undefined;
85
+ authenticatedUsername: string;
58
86
  }>;
@@ -1,19 +1,112 @@
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
+ backportBinary: 'backport',
19
+ cherrypickRef: true,
20
+ ci: false,
21
+ commitPaths: [],
22
+ details: false,
23
+ fork: true,
24
+ maxNumber: 10,
25
+ multipleBranches: true,
26
+ multipleCommits: false,
27
+ noVerify: true,
28
+ resetAuthor: false,
29
+ reviewers: [],
30
+ sourcePRLabels: [],
31
+ targetBranchChoices: [],
32
+ targetBranches: [],
33
+ targetPRLabels: [],
34
+ verbose: false,
35
+ };
9
36
  async function getOptions(argv, optionsFromModule) {
10
- const optionsFromConfigFiles = await config_1.getOptionsFromConfigFiles(optionsFromModule);
11
- const optionsFromCliArgs = cliArgs_1.getOptionsFromCliArgs(argv);
37
+ const optionsFromConfigFiles = await (0, config_1.getOptionsFromConfigFiles)(optionsFromModule);
38
+ const optionsFromCliArgs = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
39
+ // combined options from cli and config files
40
+ const combined = getCombinedOptions({
41
+ optionsFromConfigFiles,
42
+ optionsFromCliArgs,
43
+ });
12
44
  // update logger
13
- logger_1.updateLogger({ ...optionsFromConfigFiles, ...optionsFromCliArgs });
14
- // TODO: make `username` optional by defaulting to `currentUsername`
15
- const optionsFromGithub = await getOptionsFromGithub_1.getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs);
16
- const parsedOptions = parseRequiredOptions_1.parseRequiredOptions(optionsFromConfigFiles, optionsFromCliArgs, optionsFromGithub);
17
- return parsedOptions;
45
+ (0, logger_1.updateLogger)(combined);
46
+ // required
47
+ const accessToken = requireAccessToken(combined);
48
+ const repoName = requireRepoName(combined);
49
+ const repoOwner = requireRepoOwner(combined);
50
+ const optionsFromGithub = await (0, getOptionsFromGithub_1.getOptionsFromGithub)({
51
+ ...combined,
52
+ // required props
53
+ accessToken,
54
+ repoName,
55
+ repoOwner,
56
+ });
57
+ const res = {
58
+ // default author
59
+ author: optionsFromGithub.authenticatedUsername,
60
+ // default values have lowest precedence
61
+ ...exports.defaultConfigOptions,
62
+ // local config options override default options
63
+ ...optionsFromConfigFiles,
64
+ // remote config options override local config options
65
+ ...optionsFromGithub,
66
+ // cli args override the above
67
+ ...optionsFromCliArgs,
68
+ // required properties
69
+ accessToken,
70
+ repoName,
71
+ repoOwner,
72
+ };
73
+ requireTargetBranch(res);
74
+ return res;
18
75
  }
19
76
  exports.getOptions = getOptions;
77
+ function getCombinedOptions({ optionsFromConfigFiles, optionsFromCliArgs, }) {
78
+ return {
79
+ ...exports.defaultConfigOptions,
80
+ ...optionsFromConfigFiles,
81
+ ...optionsFromCliArgs,
82
+ };
83
+ }
84
+ function requireAccessToken(combinedOptions) {
85
+ // accessToken must be supplied in config or via cli args
86
+ if (!combinedOptions.accessToken) {
87
+ const globalConfigPath = (0, env_1.getGlobalConfigPath)();
88
+ throw new HandledError_1.HandledError(`Please update your config file: ${globalConfigPath}.\nIt must contain a valid "accessToken".\n\nRead more: ${GLOBAL_CONFIG_DOCS_LINK}`);
89
+ }
90
+ return combinedOptions.accessToken;
91
+ }
92
+ function requireRepoName(combinedOptions) {
93
+ if (!combinedOptions.repoName) {
94
+ throw new HandledError_1.HandledError(`Please specify a repo name: "--repo-name kibana".\n\nRead more: ${PROJECT_CONFIG_DOCS_LINK}`);
95
+ }
96
+ return combinedOptions.repoName;
97
+ }
98
+ function requireRepoOwner(combinedOptions) {
99
+ if (!combinedOptions.repoOwner) {
100
+ throw new HandledError_1.HandledError(`Please specify a repo owner: "--repo-owner elastic".\n\nRead more: ${PROJECT_CONFIG_DOCS_LINK}`);
101
+ }
102
+ return combinedOptions.repoOwner;
103
+ }
104
+ function requireTargetBranch(config) {
105
+ // ensure `targetBranches` or `targetBranchChoices` are given
106
+ if ((0, lodash_1.isEmpty)(config.targetBranches) &&
107
+ (0, lodash_1.isEmpty)(config.targetBranchChoices) &&
108
+ // this is primarily necessary on CI where `targetBranches` and `targetBranchChoices` and not given
109
+ (0, lodash_1.isEmpty)(config.branchLabelMapping)) {
110
+ throw new HandledError_1.HandledError(`Please specify a target branch: "--branch 6.1".\n\nRead more: ${PROJECT_CONFIG_DOCS_LINK}`);
111
+ }
112
+ }
@@ -24,122 +24,309 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  const nock_1 = __importDefault(require("nock"));
26
26
  const logger = __importStar(require("../services/logger"));
27
+ const mockConfigFiles_1 = require("../test/mockConfigFiles");
27
28
  const nockHelpers_1 = require("../test/nockHelpers");
28
29
  const options_1 = require("./options");
29
- function mockGetGithubConfigOptions({ defaultBranch, refName, }) {
30
- return nockHelpers_1.mockGqlRequest({
31
- name: 'GithubConfigOptions',
32
- statusCode: 200,
33
- body: {
34
- data: {
35
- repository: {
36
- isFork: false,
37
- parent: null,
38
- ref: refName ? { name: refName } : null,
39
- defaultBranchRef: {
40
- name: defaultBranch,
41
- target: { jsonConfigFile: { edges: [] } },
42
- },
43
- },
44
- },
45
- },
46
- });
47
- }
48
- describe('getOptions', () => {
49
- const defaultArgs = [
50
- '--branch',
51
- '6.0',
52
- '--branch',
53
- '6.1',
54
- '--upstream',
55
- 'elastic/kibana',
30
+ jest.unmock('../services/fs-promisified');
31
+ const defaultConfigs = {
32
+ projectConfig: {
56
33
  // use localhost to avoid CORS issues with nock
57
- '--github-api-base-url-v4',
58
- 'http://localhost/graphql',
59
- ];
34
+ githubApiBaseUrlV4: 'http://localhost/graphql',
35
+ repoOwner: 'elastic',
36
+ repoName: 'kibana',
37
+ targetBranchChoices: ['7.9', '8.0'],
38
+ },
39
+ globalConfig: { accessToken: 'abc', editor: 'code' },
40
+ };
41
+ describe('getOptions', () => {
60
42
  afterEach(() => {
61
43
  jest.clearAllMocks();
62
44
  nock_1.default.cleanAll();
63
45
  });
64
- it('should use the default repository branch as sourceBranch', async () => {
65
- const mockCalls = mockGetGithubConfigOptions({
66
- defaultBranch: 'my-default-branch',
67
- });
68
- const options = await options_1.getOptions(defaultArgs);
69
- expect(mockCalls.length).toBe(1);
70
- expect(options.sourceBranch).toBe('my-default-branch');
46
+ beforeEach(() => {
47
+ (0, mockConfigFiles_1.mockConfigFiles)(defaultConfigs);
71
48
  });
72
- it('should use explicit sourceBranch instead of defaultBranch', async () => {
73
- const argv = [
74
- '--branch',
75
- '6.0',
76
- '--branch',
77
- '6.1',
78
- '--upstream',
79
- 'elastic/kibana',
80
- '--source-branch',
81
- 'my-source-branch',
82
- '--github-api-base-url-v4',
83
- 'http://localhost/graphql',
84
- ];
85
- mockGetGithubConfigOptions({ defaultBranch: 'my-default-branch' });
86
- const options = await options_1.getOptions(argv);
87
- expect(options.sourceBranch).toBe('my-source-branch');
49
+ describe('should throw', () => {
50
+ beforeEach(() => {
51
+ mockGithubConfigOptions({});
52
+ });
53
+ it('when accessToken is missing', async () => {
54
+ (0, mockConfigFiles_1.mockConfigFiles)({
55
+ projectConfig: defaultConfigs.projectConfig,
56
+ globalConfig: { accessToken: undefined },
57
+ });
58
+ await expect(() => (0, options_1.getOptions)([])).rejects
59
+ .toThrowErrorMatchingInlineSnapshot(`
60
+ "Please update your config file: /Users/sqren/.backport/config.json.
61
+ It must contain a valid \\"accessToken\\".
62
+
63
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson"
64
+ `);
65
+ });
66
+ it('when `targetBranches`, `targetBranchChoices` and `branchLabelMapping` are all empty', async () => {
67
+ mockProjectConfig({
68
+ targetBranches: undefined,
69
+ targetBranchChoices: undefined,
70
+ branchLabelMapping: undefined,
71
+ });
72
+ await expect(() => (0, options_1.getOptions)([])).rejects
73
+ .toThrowErrorMatchingInlineSnapshot(`
74
+ "Please specify a target branch: \\"--branch 6.1\\".
75
+
76
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
77
+ `);
78
+ });
79
+ it('when repoName is missing', async () => {
80
+ mockProjectConfig({ repoName: '' });
81
+ await expect(() => (0, options_1.getOptions)([])).rejects
82
+ .toThrowErrorMatchingInlineSnapshot(`
83
+ "Please specify a repo name: \\"--repo-name kibana\\".
84
+
85
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
86
+ `);
87
+ });
88
+ it('when repoOwner is missing', async () => {
89
+ mockProjectConfig({ repoOwner: '' });
90
+ await expect(() => (0, options_1.getOptions)([])).rejects
91
+ .toThrowErrorMatchingInlineSnapshot(`
92
+ "Please specify a repo owner: \\"--repo-owner elastic\\".
93
+
94
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
95
+ `);
96
+ });
88
97
  });
89
98
  it('should ensure that "backport" branch does not exist', async () => {
90
- mockGetGithubConfigOptions({
91
- defaultBranch: 'my-default-branch',
92
- refName: 'backport',
93
- });
94
- await expect(options_1.getOptions(defaultArgs)).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
99
+ mockGithubConfigOptions({ refName: 'backport' });
100
+ await expect((0, options_1.getOptions)([])).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
95
101
  });
96
102
  it('should merge config options and module options', async () => {
97
- mockGetGithubConfigOptions({ defaultBranch: 'my-default-branch' });
103
+ mockGithubConfigOptions({});
98
104
  const myFn = async () => true;
99
- const options = await options_1.getOptions(defaultArgs, { autoFixConflicts: myFn });
105
+ const options = await (0, options_1.getOptions)([], { autoFixConflicts: myFn });
100
106
  expect(options.autoFixConflicts).toBe(myFn);
101
107
  });
102
108
  it('should call updateLogger', async () => {
103
- mockGetGithubConfigOptions({ defaultBranch: 'my-default-branch' });
104
- await options_1.getOptions(defaultArgs);
109
+ mockGithubConfigOptions({});
110
+ await (0, options_1.getOptions)([]);
105
111
  expect(logger.updateLogger).toHaveBeenCalledTimes(1);
106
112
  });
107
113
  it('should return options', async () => {
108
- mockGetGithubConfigOptions({ defaultBranch: 'some-branch-name' });
109
- const options = await options_1.getOptions(defaultArgs);
114
+ mockGithubConfigOptions({
115
+ viewerLogin: 'john.diller',
116
+ defaultBranchRef: 'default-branch-from-github',
117
+ historicalMappings: [
118
+ {
119
+ committedDate: '2022-01-02T20:52:45.173Z',
120
+ branchLabelMapping: { foo: 'bar' },
121
+ },
122
+ ],
123
+ });
124
+ const options = await (0, options_1.getOptions)([]);
110
125
  expect(options).toEqual({
111
- accessToken: 'myAccessToken',
112
- all: false,
126
+ accessToken: 'abc',
113
127
  assignees: [],
114
- author: 'sqren',
115
128
  autoAssign: false,
116
129
  autoMerge: false,
117
130
  autoMergeMethod: 'merge',
131
+ authenticatedUsername: 'john.diller',
132
+ branchLabelMapping: {
133
+ foo: 'bar',
134
+ },
135
+ cherrypickRef: true,
118
136
  ci: false,
119
- dryRun: false,
137
+ commitPaths: [],
138
+ details: false,
139
+ editor: 'code',
120
140
  fork: true,
121
- gitHostname: 'github.com',
122
- githubApiBaseUrlV3: 'https://api.github.com',
123
141
  githubApiBaseUrlV4: 'http://localhost/graphql',
142
+ historicalBranchLabelMappings: [
143
+ {
144
+ branchLabelMapping: { foo: 'bar' },
145
+ committedDate: '2022-01-02T20:52:45.173Z',
146
+ },
147
+ ],
124
148
  maxNumber: 10,
125
149
  multipleBranches: true,
126
150
  multipleCommits: false,
127
151
  noVerify: true,
128
- prTitle: '[{targetBranch}] {commitMessages}',
129
152
  repoName: 'kibana',
130
153
  repoOwner: 'elastic',
131
154
  resetAuthor: false,
132
- sourceBranch: 'some-branch-name',
155
+ reviewers: [],
156
+ sourceBranch: 'default-branch-from-github',
133
157
  sourcePRLabels: [],
134
- targetBranchChoices: [
135
- { checked: false, name: '6.0' },
136
- { checked: false, name: '5.9' },
137
- ],
138
- targetBranches: ['6.0', '6.1'],
158
+ targetBranchChoices: ['7.9', '8.0'],
159
+ targetBranches: [],
139
160
  targetPRLabels: [],
140
- upstream: 'elastic/kibana',
141
- username: 'sqren',
161
+ author: 'john.diller',
142
162
  verbose: false,
143
163
  });
144
164
  });
165
+ describe('sourceBranch', () => {
166
+ beforeEach(() => {
167
+ mockGithubConfigOptions({ defaultBranchRef: 'some-default-branch' });
168
+ });
169
+ it('uses the `defaultBranchRef` as default', async () => {
170
+ const options = await (0, options_1.getOptions)([]);
171
+ expect(options.sourceBranch).toBe('some-default-branch');
172
+ });
173
+ it('uses the sourceBranch given via cli instead of `defaultBranchRef`', async () => {
174
+ const options = await (0, options_1.getOptions)([
175
+ '--source-branch',
176
+ 'cli-source-branch',
177
+ ]);
178
+ expect(options.sourceBranch).toBe('cli-source-branch');
179
+ });
180
+ });
181
+ describe('fork', () => {
182
+ beforeEach(() => {
183
+ mockGithubConfigOptions({});
184
+ });
185
+ it('is enabled by default', async () => {
186
+ const { fork } = await (0, options_1.getOptions)([]);
187
+ expect(fork).toBe(true);
188
+ });
189
+ it('can be disabled via `--no-fork` flag', async () => {
190
+ const { fork } = await (0, options_1.getOptions)(['--no-fork']);
191
+ expect(fork).toBe(false);
192
+ });
193
+ it('can be disabled via config file', async () => {
194
+ mockProjectConfig({ fork: false });
195
+ const { fork } = await (0, options_1.getOptions)([]);
196
+ expect(fork).toBe(false);
197
+ });
198
+ });
199
+ describe('reviewers', () => {
200
+ beforeEach(() => {
201
+ mockGithubConfigOptions({});
202
+ });
203
+ it('can be set via `--reviewer` flag', async () => {
204
+ const { reviewers } = await (0, options_1.getOptions)(['--reviewer', 'peter']);
205
+ expect(reviewers).toEqual(['peter']);
206
+ });
207
+ it('can be set via config file', async () => {
208
+ mockProjectConfig({ reviewers: ['john'] });
209
+ const { reviewers } = await (0, options_1.getOptions)([]);
210
+ expect(reviewers).toEqual(['john']);
211
+ });
212
+ });
213
+ describe('mainline', () => {
214
+ beforeEach(() => {
215
+ mockGithubConfigOptions({});
216
+ });
217
+ it('is not enabled by default', async () => {
218
+ const { mainline } = await (0, options_1.getOptions)([]);
219
+ expect(mainline).toBe(undefined);
220
+ });
221
+ it('can be set via `--mainline` flag', async () => {
222
+ const { mainline } = await (0, options_1.getOptions)(['--mainline']);
223
+ expect(mainline).toBe(1);
224
+ });
225
+ it('accepts numeric values', async () => {
226
+ const { mainline } = await (0, options_1.getOptions)(['--mainline', '2']);
227
+ expect(mainline).toBe(2);
228
+ });
229
+ });
230
+ describe('author', () => {
231
+ beforeEach(() => {
232
+ mockGithubConfigOptions({ viewerLogin: 'billy.bob' });
233
+ });
234
+ it('defaults to authenticated user', async () => {
235
+ const { author } = await (0, options_1.getOptions)([]);
236
+ expect(author).toBe('billy.bob');
237
+ });
238
+ it('can be overridden via `--author` flag', async () => {
239
+ const { author } = await (0, options_1.getOptions)(['--author', 'john.doe']);
240
+ expect(author).toBe('john.doe');
241
+ });
242
+ it('can be reset via `--all` flag', async () => {
243
+ const { author } = await (0, options_1.getOptions)(['--all']);
244
+ expect(author).toBe(null);
245
+ });
246
+ it('can be reset via config file (similar to `--all` flag)', async () => {
247
+ mockProjectConfig({ author: null });
248
+ const { author } = await (0, options_1.getOptions)([]);
249
+ expect(author).toBe(null);
250
+ });
251
+ it('can be overridden via config file', async () => {
252
+ mockProjectConfig({ author: 'jane.doe' });
253
+ const { author } = await (0, options_1.getOptions)([]);
254
+ expect(author).toBe('jane.doe');
255
+ });
256
+ });
257
+ describe('cherrypickRef', () => {
258
+ beforeEach(() => {
259
+ mockGithubConfigOptions({});
260
+ });
261
+ it('should default to true', async () => {
262
+ const { cherrypickRef } = await (0, options_1.getOptions)([]);
263
+ expect(cherrypickRef).toBe(true);
264
+ });
265
+ it('should negate with `noCherrypickRef` cli arg', async () => {
266
+ const { cherrypickRef } = await (0, options_1.getOptions)(['--no-cherrypick-ref']);
267
+ expect(cherrypickRef).toBe(false);
268
+ });
269
+ it('should be settable via config file', async () => {
270
+ mockProjectConfig({ cherrypickRef: false });
271
+ const { cherrypickRef } = await (0, options_1.getOptions)([]);
272
+ expect(cherrypickRef).toBe(false);
273
+ });
274
+ it('cli args overwrites config', async () => {
275
+ mockProjectConfig({ cherrypickRef: false });
276
+ const { cherrypickRef } = await (0, options_1.getOptions)(['--cherrypick-ref']);
277
+ expect(cherrypickRef).toBe(true);
278
+ });
279
+ });
145
280
  });
281
+ function mockProjectConfig(projectConfig) {
282
+ return (0, mockConfigFiles_1.mockConfigFiles)({
283
+ globalConfig: { accessToken: 'abc' },
284
+ projectConfig: {
285
+ // use localhost to avoid CORS issues with nock
286
+ githubApiBaseUrlV4: 'http://localhost/graphql',
287
+ repoOwner: 'elastic',
288
+ repoName: 'kibana',
289
+ targetBranchChoices: ['7.9', '8.0'],
290
+ ...projectConfig,
291
+ },
292
+ });
293
+ }
294
+ function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBranchRef = 'DO_NOT_USE-default-branch-name', refName, historicalMappings = [], }) {
295
+ return (0, nockHelpers_1.mockGqlRequest)({
296
+ name: 'GithubConfigOptions',
297
+ statusCode: 200,
298
+ body: {
299
+ data: {
300
+ viewer: {
301
+ login: viewerLogin,
302
+ },
303
+ repository: {
304
+ isFork: false,
305
+ parent: null,
306
+ ref: refName ? { name: refName } : null,
307
+ defaultBranchRef: {
308
+ name: defaultBranchRef,
309
+ target: {
310
+ history: {
311
+ edges: historicalMappings.map(({ committedDate, branchLabelMapping }) => {
312
+ return {
313
+ remoteConfig: {
314
+ committedDate,
315
+ file: {
316
+ object: {
317
+ text: JSON.stringify({
318
+ branchLabelMapping,
319
+ }),
320
+ },
321
+ },
322
+ },
323
+ };
324
+ }),
325
+ },
326
+ },
327
+ },
328
+ },
329
+ },
330
+ },
331
+ });
332
+ }