backport 5.6.3 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/README.md +48 -39
  2. package/dist/entrypoint.cli.js +1 -1
  3. package/dist/entrypoint.module.d.ts +6 -5
  4. package/dist/entrypoint.module.js +8 -6
  5. package/dist/ink.d.ts +1 -0
  6. package/dist/ink.js +49 -0
  7. package/dist/main.d.ts +11 -6
  8. package/dist/main.js +40 -24
  9. package/dist/options/ConfigOptions.d.ts +47 -39
  10. package/dist/options/cliArgs.d.ts +28 -34
  11. package/dist/options/cliArgs.js +113 -94
  12. package/dist/options/cliArgs.test.js +103 -119
  13. package/dist/options/config/config.d.ts +81 -2
  14. package/dist/options/config/config.js +46 -6
  15. package/dist/options/config/config.test.js +24 -2
  16. package/dist/options/config/getOptionsFromGit.d.ts +3 -0
  17. package/dist/options/config/getOptionsFromGit.js +10 -0
  18. package/dist/options/config/globalConfig.d.ts +2 -1
  19. package/dist/options/config/globalConfig.js +8 -8
  20. package/dist/options/config/globalConfig.test.js +7 -3
  21. package/dist/options/config/projectConfig.d.ts +2 -1
  22. package/dist/options/config/projectConfig.js +3 -3
  23. package/dist/options/config/projectConfig.test.js +4 -4
  24. package/dist/options/config/readConfigFile.d.ts +2 -2
  25. package/dist/options/config/readConfigFile.js +3 -3
  26. package/dist/options/options.d.ts +40 -27
  27. package/dist/options/options.js +8 -16
  28. package/dist/options/options.test.js +66 -26
  29. package/dist/options/parseRequiredOptions.d.ts +71 -0
  30. package/dist/options/parseRequiredOptions.js +70 -0
  31. package/dist/options/parseRequiredOptions.test.d.ts +1 -0
  32. package/dist/options/parseRequiredOptions.test.js +127 -0
  33. package/dist/runSequentially.d.ts +20 -0
  34. package/dist/runSequentially.js +41 -0
  35. package/dist/runSequentially.test.d.ts +1 -0
  36. package/dist/runSequentially.test.js +235 -0
  37. package/dist/runWithOptions.js +7 -14
  38. package/dist/runWithOptions.test.js +142 -16
  39. package/dist/scripts/generate-gql.d.ts +1 -0
  40. package/dist/scripts/generate-gql.js +15 -0
  41. package/dist/scripts/postinstall.js +4 -4
  42. package/dist/scripts/postinstall.test.js +9 -2
  43. package/dist/scripts/runPostinstall.js +1 -1
  44. package/dist/services/HandledError.d.ts +11 -1
  45. package/dist/services/HandledError.js +2 -1
  46. package/dist/services/child-process-promisified.d.ts +1 -1
  47. package/dist/services/child-process-promisified.js +2 -2
  48. package/dist/services/env.js +5 -5
  49. package/dist/services/env.test.js +11 -4
  50. package/dist/services/fs-promisified.js +4 -4
  51. package/dist/services/getExpectedTarget.d.ts +9 -0
  52. package/dist/services/getExpectedTarget.js +77 -0
  53. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  54. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  55. package/dist/services/git.d.ts +19 -4
  56. package/dist/services/git.integration.test.d.ts +1 -0
  57. package/dist/services/git.integration.test.js +168 -0
  58. package/dist/services/git.js +129 -57
  59. package/dist/services/git.test.js +155 -51
  60. package/dist/services/github/commitFormatters.d.ts +3 -7
  61. package/dist/services/github/commitFormatters.js +10 -19
  62. package/dist/services/github/commitFormatters.test.js +2 -24
  63. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  64. package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -6
  65. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +2 -3
  66. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  67. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  68. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  69. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  70. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  71. package/dist/services/github/v3/createPullRequest.js +33 -24
  72. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  73. package/dist/services/github/v3/createStatusComment.js +97 -0
  74. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  75. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  76. package/dist/services/github/v4/FetchPullRequestId.d.ts +9 -0
  77. package/dist/services/github/v4/FetchPullRequestId.js +32 -0
  78. package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
  79. package/dist/services/github/v4/apiRequestV4.js +8 -10
  80. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  81. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +9 -0
  82. package/dist/services/github/v4/disablePullRequestAutoMerge.js +28 -0
  83. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +9 -0
  84. package/dist/services/github/v4/enablePullRequestAutoMerge.js +51 -0
  85. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  86. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +113 -0
  87. package/dist/services/github/v4/fetchAuthorId.d.ts +5 -0
  88. package/dist/services/github/v4/fetchAuthorId.js +1 -1
  89. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -3
  90. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  91. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +6 -6
  92. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  93. package/dist/services/github/v4/fetchCommitBySha.private.test.js +7 -5
  94. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +5 -0
  95. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  96. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  97. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +67 -0
  98. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +5 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +16 -0
  103. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +90 -0
  104. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  105. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +130 -0
  106. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  107. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +127 -0
  108. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  109. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  110. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  111. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  112. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  113. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +81 -0
  114. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  115. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  116. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +3 -2
  117. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  118. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +81 -8
  119. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  120. package/dist/services/github/v4/fetchDefaultBranch.d.ts +1 -1
  121. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  122. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +4 -0
  123. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +52 -0
  124. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +1 -0
  125. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +32 -0
  126. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +4 -0
  127. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +72 -0
  128. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +1 -0
  129. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +34 -0
  130. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +40 -0
  131. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +72 -0
  132. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  133. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -3
  134. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +19 -20
  135. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -68
  136. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  137. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
  138. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
  139. package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +1 -1
  140. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  141. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +8 -6
  142. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  143. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  144. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  145. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +61 -0
  146. package/dist/services/github/v4/getOptionsFromGithub/index.js +139 -0
  147. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +1 -0
  148. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +126 -0
  149. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +34 -0
  150. package/dist/services/github/v4/getOptionsFromGithub/query.js +44 -0
  151. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  152. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  153. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  154. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  155. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  156. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +2 -2
  157. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  158. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +2 -2
  159. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +4 -1
  160. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  161. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  162. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
  163. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  164. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  165. package/dist/services/logger.d.ts +3 -3
  166. package/dist/services/logger.js +24 -24
  167. package/dist/services/prompt.test.d.ts +1 -0
  168. package/dist/services/prompt.test.js +87 -0
  169. package/dist/services/prompts.d.ts +10 -4
  170. package/dist/services/prompts.js +85 -22
  171. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  172. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  173. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  174. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
  175. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  176. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  177. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  178. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  179. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  180. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  181. package/dist/services/sourceCommit/parseSourceCommit.d.ts +78 -0
  182. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  183. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  184. package/dist/services/sourceCommit/parseSourceCommit.test.js +114 -0
  185. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  186. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  187. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  188. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  189. package/dist/services/sourceCommit.d.ts +78 -0
  190. package/dist/services/sourceCommit.js +86 -0
  191. package/dist/services/sourceCommit.test.d.ts +1 -0
  192. package/dist/services/sourceCommit.test.js +280 -0
  193. package/dist/test/inquirer.private.test.js +81 -45
  194. package/dist/test/integration/createSpies.d.ts +1 -1
  195. package/dist/test/integration/createSpies.js +21 -9
  196. package/dist/test/integration/envConstants.js +5 -6
  197. package/dist/test/integration/helpers.js +1 -1
  198. package/dist/test/integration/integration.private.test.d.ts +1 -0
  199. package/dist/test/integration/integration.private.test.js +308 -0
  200. package/dist/test/integration/integration.test.js +30 -31
  201. package/dist/test/nockHelpers.d.ts +2 -2
  202. package/dist/test/nockHelpers.js +3 -7
  203. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  204. package/dist/test/setupFiles/automatic-mocks.js +0 -22
  205. package/dist/types/Commit.d.ts +85 -0
  206. package/dist/types/Commit.js +139 -0
  207. package/dist/types/commitNode.d.ts +89 -0
  208. package/dist/types/commitNode.js +139 -0
  209. package/dist/types/commitNode.test.d.ts +1 -0
  210. package/dist/types/commitNode.test.js +255 -0
  211. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  212. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  213. package/dist/ui/cherrypickAndCreatePullRequest.test.js +277 -59
  214. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
  215. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +135 -67
  216. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  217. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  218. package/dist/ui/getCommits.d.ts +1 -1
  219. package/dist/ui/getCommits.js +55 -25
  220. package/dist/ui/getTargetBranches.d.ts +2 -2
  221. package/dist/ui/getTargetBranches.js +16 -17
  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 +9 -9
  228. package/dist/ui/maybeSetupRepo.test.js +5 -1
  229. package/package.json +36 -51
  230. package/yarn.lock +2387 -2979
@@ -0,0 +1,71 @@
1
+ import { OptionsFromGithub } from '../services/github/v4/getOptionsFromGithub';
2
+ import { TargetBranchChoiceOrString, TargetBranchChoice, ConfigFileOptions } from './ConfigOptions';
3
+ import { OptionsFromCliArgs } from './cliArgs';
4
+ import { OptionsFromConfigFiles } from './config/config';
5
+ export declare function parseRequiredOptions(optionsFromConfigFiles: OptionsFromConfigFiles, optionsFromCliArgs: OptionsFromCliArgs, optionsFromGithub: OptionsFromGithub): {
6
+ targetBranchChoices: TargetBranchChoice[];
7
+ accessToken: string;
8
+ username: string;
9
+ repoName: string;
10
+ repoOwner: string;
11
+ assignees: string[];
12
+ author: string;
13
+ all: boolean;
14
+ multipleBranches: boolean;
15
+ multipleCommits: boolean;
16
+ commitPaths: string[];
17
+ reviewers: string[];
18
+ sourcePRLabels: (string[] | undefined) & (string[] | never[]);
19
+ targetBranches: (string[] | undefined) & (string[] | never[]);
20
+ targetPRLabels: string[];
21
+ cherrypickRef: boolean;
22
+ fork: boolean;
23
+ noVerify: boolean;
24
+ autoAssign: boolean;
25
+ autoMerge: boolean;
26
+ autoMergeMethod: string;
27
+ ci: boolean;
28
+ details: boolean;
29
+ editor: string | undefined;
30
+ forceLocalConfig: boolean | undefined;
31
+ gitHostname: string;
32
+ githubApiBaseUrlV3: string;
33
+ githubApiBaseUrlV4: string;
34
+ mainline: number | undefined;
35
+ maxNumber: number;
36
+ prDescription: string | undefined;
37
+ prTitle: string;
38
+ prFilter: string | undefined;
39
+ pullNumber: number | undefined;
40
+ resetAuthor: boolean;
41
+ sha: string | undefined;
42
+ sourceBranch: string;
43
+ upstream: string | undefined;
44
+ verbose: boolean;
45
+ autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
46
+ files: string[];
47
+ directory: string;
48
+ logger: {
49
+ error: (message: string, meta?: unknown) => void;
50
+ warn: (message: string, meta?: unknown) => void;
51
+ info: (message: string, meta?: unknown) => void;
52
+ verbose: (message: string, meta?: unknown) => void;
53
+ debug: (message: string, meta?: unknown) => void;
54
+ };
55
+ targetBranch: string;
56
+ }) => boolean | Promise<boolean>) | undefined;
57
+ multiple?: boolean | undefined;
58
+ branchLabelMapping?: Record<string, string> | undefined;
59
+ branches?: TargetBranchChoiceOrString[] | undefined;
60
+ labels?: string[] | undefined;
61
+ historicalBranchLabelMappings: {
62
+ branchLabelMapping: Record<string, string>;
63
+ committedDate: string;
64
+ }[];
65
+ };
66
+ export declare function getRequiredOptions({ accessToken, username, upstream, }: ConfigFileOptions): {
67
+ accessToken: string;
68
+ username: string;
69
+ repoOwner: string;
70
+ repoName: string;
71
+ };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRequiredOptions = exports.parseRequiredOptions = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const HandledError_1 = require("../services/HandledError");
6
+ const env_1 = require("../services/env");
7
+ const PROJECT_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/e119d71d6dc03cd061f6ad9b9a8b1cd995f98961/docs/configuration.md#project-config-backportrcjson';
8
+ const GLOBAL_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/e119d71d6dc03cd061f6ad9b9a8b1cd995f98961/docs/configuration.md#global-config-backportconfigjson';
9
+ function parseRequiredOptions(optionsFromConfigFiles, optionsFromCliArgs, optionsFromGithub) {
10
+ const options = {
11
+ // local config files have lowest precedence
12
+ ...optionsFromConfigFiles,
13
+ // remote config options override local config options
14
+ ...optionsFromGithub,
15
+ // cli args override both of the above
16
+ ...optionsFromCliArgs,
17
+ };
18
+ // ensure `targetBranches` or `targetBranchChoices` are given
19
+ if ((0, lodash_1.isEmpty)(options.targetBranches) &&
20
+ (0, lodash_1.isEmpty)(options.targetBranchChoices) &&
21
+ // this is primarily necessary on CI where `targetBranches` and `targetBranchChoices` and not given
22
+ (0, lodash_1.isEmpty)(options.branchLabelMapping)) {
23
+ throw new HandledError_1.HandledError(`You must specify a target branch\n\nYou can specify it via either:\n - Config file (recommended): ".backportrc.json". Read more: ${PROJECT_CONFIG_DOCS_LINK}\n - CLI: "--branch 6.1"`);
24
+ }
25
+ const { accessToken, username, repoName, repoOwner } = getRequiredOptions(options);
26
+ return {
27
+ ...options,
28
+ // convert from array of primitives to array of object
29
+ targetBranchChoices: getTargetBranchChoicesAsObject(options.targetBranchChoices),
30
+ // required options
31
+ accessToken,
32
+ username,
33
+ repoName,
34
+ repoOwner,
35
+ // auto-assign the current user or default to the specified assignees
36
+ assignees: options.autoAssign && options.username
37
+ ? [options.username]
38
+ : options.assignees,
39
+ author: options.author || username,
40
+ all: options.author ? false : options.all,
41
+ };
42
+ }
43
+ exports.parseRequiredOptions = parseRequiredOptions;
44
+ // `branches` can either be a string or an object.
45
+ // It must be transformed so it is always treated as an object troughout the application
46
+ function getTargetBranchChoicesAsObject(targetBranchChoices) {
47
+ return targetBranchChoices.map((choice) => {
48
+ if ((0, lodash_1.isString)(choice)) {
49
+ return {
50
+ name: choice,
51
+ checked: false,
52
+ };
53
+ }
54
+ return choice;
55
+ });
56
+ }
57
+ function getRequiredOptions({ accessToken, username, upstream, }) {
58
+ // accessToken and username must be supplied in config or via cli args
59
+ if (!accessToken || !username) {
60
+ const globalConfigPath = (0, env_1.getGlobalConfigPath)();
61
+ throw new HandledError_1.HandledError(`Please update your config file: ${globalConfigPath}.\nIt must contain a valid "username" and "accessToken".\n\nRead more: ${GLOBAL_CONFIG_DOCS_LINK}`);
62
+ }
63
+ // upstream must be specified via config or cli args
64
+ const [repoOwner, repoName] = (upstream ?? '').split('/');
65
+ if (!repoOwner || !repoName) {
66
+ throw new HandledError_1.HandledError(`You must specify a valid Github repository\n\nYou can specify it via either:\n - Config file (recommended): ".backportrc.json". Read more: ${PROJECT_CONFIG_DOCS_LINK}\n - CLI: "--upstream elastic/kibana"`);
67
+ }
68
+ return { accessToken, username, repoOwner, repoName };
69
+ }
70
+ exports.getRequiredOptions = getRequiredOptions;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const os_1 = __importDefault(require("os"));
7
+ const config_1 = require("./config/config");
8
+ const parseRequiredOptions_1 = require("./parseRequiredOptions");
9
+ describe('parseRequiredOptions', () => {
10
+ beforeEach(() => {
11
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
12
+ });
13
+ const optionsFromConfigFiles = {
14
+ ...config_1.defaultConfigOptions,
15
+ accessToken: 'myAccessToken',
16
+ username: 'sqren',
17
+ upstream: 'elastic/kibana',
18
+ targetBranches: ['branchA', 'branchB'],
19
+ };
20
+ const optionsFromCliArgs = {};
21
+ const optionsFromGithub = {
22
+ sourceBranch: 'source-branch-from-github',
23
+ };
24
+ describe('should not throw', () => {
25
+ it('when all options are valid and `branches` is given', () => {
26
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)(optionsFromConfigFiles, optionsFromCliArgs, optionsFromGithub)).not.toThrow();
27
+ });
28
+ it('when `targetBranchChoices` is given instead of `targetBranches`', () => {
29
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
30
+ ...optionsFromConfigFiles,
31
+ targetBranchChoices: [{ name: 'branchA' }],
32
+ targetBranches: [],
33
+ }, optionsFromCliArgs, optionsFromGithub)).not.toThrow();
34
+ });
35
+ describe('autoAssign/assignees', () => {
36
+ it('should set `assignees` to current user if `autoAssign` is true', () => {
37
+ const options = (0, parseRequiredOptions_1.parseRequiredOptions)({ ...optionsFromConfigFiles, assignees: ['john'] }, { autoAssign: true }, optionsFromGithub);
38
+ expect(options.assignees).toEqual(['sqren']);
39
+ });
40
+ it('should set `assignees` to specified value if `autoAssign` is false', () => {
41
+ const options = (0, parseRequiredOptions_1.parseRequiredOptions)({ ...optionsFromConfigFiles, assignees: ['john'] }, { autoAssign: false }, optionsFromGithub);
42
+ expect(options.assignees).toEqual(['john']);
43
+ });
44
+ it('should set `assignees` to empty if neither `assignees` or `autoAssign` is specified', () => {
45
+ const options = (0, parseRequiredOptions_1.parseRequiredOptions)({ ...optionsFromConfigFiles, assignees: [] }, { autoAssign: false }, optionsFromGithub);
46
+ expect(options.assignees).toEqual([]);
47
+ });
48
+ });
49
+ describe('targetBranchChoices', () => {
50
+ it('should convert primitives', () => {
51
+ const options = (0, parseRequiredOptions_1.parseRequiredOptions)({
52
+ ...optionsFromConfigFiles,
53
+ targetBranchChoices: ['choice 1', 'choice 2'],
54
+ }, optionsFromCliArgs, optionsFromGithub);
55
+ expect(options.targetBranchChoices).toEqual([
56
+ { name: 'choice 1', checked: false },
57
+ { name: 'choice 2', checked: false },
58
+ ]);
59
+ });
60
+ it('should preserve objects as-is', () => {
61
+ const options = (0, parseRequiredOptions_1.parseRequiredOptions)({
62
+ ...optionsFromConfigFiles,
63
+ targetBranchChoices: [
64
+ { name: 'choice 1', checked: false },
65
+ { name: 'choice 2', checked: true },
66
+ ],
67
+ }, optionsFromCliArgs, optionsFromGithub);
68
+ expect(options.targetBranchChoices).toEqual([
69
+ { name: 'choice 1', checked: false },
70
+ { name: 'choice 2', checked: true },
71
+ ]);
72
+ });
73
+ });
74
+ });
75
+ describe('should throw', () => {
76
+ it('when accessToken is missing', () => {
77
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
78
+ ...optionsFromConfigFiles,
79
+ accessToken: undefined,
80
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
81
+ });
82
+ it('when accessToken is empty', () => {
83
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
84
+ ...optionsFromConfigFiles,
85
+ accessToken: '',
86
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
87
+ });
88
+ it('when `targetBranches`, `targetBranchChoices` and `branchLabelMapping` are all empty', () => {
89
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
90
+ ...optionsFromConfigFiles,
91
+ targetBranchChoices: [],
92
+ targetBranches: [],
93
+ branchLabelMapping: {},
94
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
95
+ });
96
+ it('when upstream is missing', () => {
97
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
98
+ ...optionsFromConfigFiles,
99
+ upstream: undefined,
100
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
101
+ });
102
+ it('when upstream is empty', () => {
103
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
104
+ ...optionsFromConfigFiles,
105
+ upstream: '',
106
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
107
+ });
108
+ it('when upstream is invalid', () => {
109
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
110
+ ...optionsFromConfigFiles,
111
+ upstream: 'foobar',
112
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
113
+ });
114
+ it('when username is missing', () => {
115
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
116
+ ...optionsFromConfigFiles,
117
+ username: undefined,
118
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
119
+ });
120
+ it('when username is empty', () => {
121
+ expect(() => (0, parseRequiredOptions_1.parseRequiredOptions)({
122
+ ...optionsFromConfigFiles,
123
+ username: '',
124
+ }, optionsFromCliArgs, optionsFromGithub)).toThrowErrorMatchingSnapshot();
125
+ });
126
+ });
127
+ });
@@ -0,0 +1,20 @@
1
+ import { ValidConfigOptions } from './options/options';
2
+ import { HandledError } from './services/HandledError';
3
+ import { Commit } from './services/sourceCommit/parseSourceCommit';
4
+ export declare type Result = {
5
+ status: 'success';
6
+ didUpdate: boolean;
7
+ targetBranch: string;
8
+ pullRequestUrl: string;
9
+ pullRequestNumber: number;
10
+ } | {
11
+ status: 'failure';
12
+ targetBranch: string;
13
+ errorMessage: string;
14
+ error: HandledError;
15
+ };
16
+ export declare function runSequentially({ options, commits, targetBranches, }: {
17
+ options: ValidConfigOptions;
18
+ commits: Commit[];
19
+ targetBranches: string[];
20
+ }): Promise<Result[]>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runSequentially = void 0;
4
+ const logger_1 = require("./services/logger");
5
+ const sequentially_1 = require("./services/sequentially");
6
+ const cherrypickAndCreateTargetPullRequest_1 = require("./ui/cherrypickAndCreateTargetPullRequest");
7
+ const maybeSetupRepo_1 = require("./ui/maybeSetupRepo");
8
+ async function runSequentially({ options, commits, targetBranches, }) {
9
+ logger_1.logger.verbose('Backport options', options);
10
+ await (0, maybeSetupRepo_1.maybeSetupRepo)(options);
11
+ const results = [];
12
+ await (0, sequentially_1.sequentially)(targetBranches, async (targetBranch) => {
13
+ logger_1.logger.info(`Backporting ${JSON.stringify(commits)} to ${targetBranch}`);
14
+ try {
15
+ const { number, url, didUpdate } = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
16
+ options,
17
+ commits,
18
+ targetBranch,
19
+ });
20
+ results.push({
21
+ targetBranch,
22
+ status: 'success',
23
+ didUpdate,
24
+ pullRequestUrl: url,
25
+ pullRequestNumber: number,
26
+ });
27
+ }
28
+ catch (e) {
29
+ results.push({
30
+ targetBranch,
31
+ status: 'failure',
32
+ errorMessage: e.message,
33
+ error: e,
34
+ });
35
+ (0, logger_1.consoleLog)(e.message);
36
+ }
37
+ });
38
+ // return the results for consumers to programatically read
39
+ return results;
40
+ }
41
+ exports.runSequentially = runSequentially;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const os_1 = __importDefault(require("os"));
26
+ const lodash_1 = require("lodash");
27
+ const nock_1 = __importDefault(require("nock"));
28
+ const runSequentially_1 = require("./runSequentially");
29
+ const childProcess = __importStar(require("./services/child-process-promisified"));
30
+ const nockHelpers_1 = require("./test/nockHelpers");
31
+ jest.mock('./services/child-process-promisified', () => {
32
+ return {
33
+ exec: jest.fn(async (cmd) => {
34
+ throw new Error(`Mock required for exec with cmd: "${cmd}"`);
35
+ }),
36
+ execAsCallback: jest.fn((...args) => {
37
+ (0, lodash_1.last)(args)();
38
+ return {
39
+ stderr: {
40
+ on: () => null,
41
+ },
42
+ };
43
+ }),
44
+ };
45
+ });
46
+ describe('runSequentially', () => {
47
+ let rpcExecMock;
48
+ let rpcExecOriginalMock;
49
+ let res;
50
+ let createPullRequestCalls;
51
+ afterEach(() => {
52
+ jest.clearAllMocks();
53
+ nock_1.default.cleanAll();
54
+ });
55
+ beforeEach(async () => {
56
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
57
+ const options = {
58
+ accessToken: 'myAccessToken',
59
+ all: false,
60
+ assignees: [],
61
+ author: 'sqren',
62
+ autoAssign: false,
63
+ autoFixConflicts: undefined,
64
+ autoMerge: false,
65
+ autoMergeMethod: 'merge',
66
+ branchLabelMapping: undefined,
67
+ historicalBranchLabelMappings: [],
68
+ cherrypickRef: true,
69
+ ci: false,
70
+ commitPaths: [],
71
+ details: false,
72
+ editor: 'code',
73
+ forceLocalConfig: undefined,
74
+ fork: true,
75
+ gitHostname: 'github.com',
76
+ githubApiBaseUrlV3: 'https://api.github.com',
77
+ githubApiBaseUrlV4: 'http://localhost/graphql',
78
+ mainline: undefined,
79
+ maxNumber: 10,
80
+ multipleBranches: false,
81
+ multipleCommits: false,
82
+ noVerify: true,
83
+ prDescription: 'myPrDescription',
84
+ prFilter: undefined,
85
+ prTitle: 'myPrTitle {targetBranch} {commitMessages}',
86
+ pullNumber: undefined,
87
+ repoName: 'kibana',
88
+ repoOwner: 'elastic',
89
+ resetAuthor: false,
90
+ reviewers: [],
91
+ sha: undefined,
92
+ sourceBranch: 'my-source-branch-from-options',
93
+ sourcePRLabels: [],
94
+ targetBranches: [],
95
+ upstream: 'elastic/kibana',
96
+ targetBranchChoices: [
97
+ { name: '6.x' },
98
+ { name: '6.0' },
99
+ { name: '5.6' },
100
+ { name: '5.5' },
101
+ { name: '5.4' },
102
+ ],
103
+ targetPRLabels: [],
104
+ username: 'sqren',
105
+ verbose: false,
106
+ };
107
+ rpcExecMock = jest
108
+ .spyOn(childProcess, 'exec')
109
+ .mockResolvedValue({ stdout: 'success', stderr: '' });
110
+ rpcExecOriginalMock = jest.spyOn(childProcess, 'execAsCallback');
111
+ const scope = (0, nock_1.default)('https://api.github.com')
112
+ .post('/repos/elastic/kibana/pulls')
113
+ .reply(200, {
114
+ number: 1337,
115
+ html_url: 'myHtmlUrl',
116
+ });
117
+ createPullRequestCalls = (0, nockHelpers_1.getNockCallsForScope)(scope);
118
+ const commits = [
119
+ {
120
+ sha: 'abcd',
121
+ committedDate: '1',
122
+ expectedTargetPullRequests: [],
123
+ originalMessage: 'My commit message',
124
+ sourceBranch: 'master',
125
+ pullNumber: 55,
126
+ },
127
+ ];
128
+ const targetBranches = ['7.x'];
129
+ res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
130
+ scope.done();
131
+ });
132
+ it('returns pull request', () => {
133
+ expect(res).toEqual([
134
+ {
135
+ didUpdate: false,
136
+ pullRequestNumber: 1337,
137
+ pullRequestUrl: 'myHtmlUrl',
138
+ status: 'success',
139
+ targetBranch: '7.x',
140
+ },
141
+ ]);
142
+ });
143
+ it('creates pull request', () => {
144
+ expect(createPullRequestCalls).toEqual([
145
+ {
146
+ base: '7.x',
147
+ body: 'Backports the following commits to 7.x:\n - #55\n\nmyPrDescription',
148
+ head: 'sqren:backport/7.x/pr-55',
149
+ title: 'myPrTitle 7.x My commit message',
150
+ },
151
+ ]);
152
+ });
153
+ it('exec should be called with correct args', () => {
154
+ expect(rpcExecMock).toHaveBeenCalledTimes(10);
155
+ expect(rpcExecMock.mock.calls).toMatchInlineSnapshot(`
156
+ Array [
157
+ Array [
158
+ "git remote rm origin",
159
+ Object {
160
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
161
+ },
162
+ ],
163
+ Array [
164
+ "git remote rm sqren",
165
+ Object {
166
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
167
+ },
168
+ ],
169
+ Array [
170
+ "git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git",
171
+ Object {
172
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
173
+ },
174
+ ],
175
+ Array [
176
+ "git remote rm elastic",
177
+ Object {
178
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
179
+ },
180
+ ],
181
+ Array [
182
+ "git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git",
183
+ Object {
184
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
185
+ },
186
+ ],
187
+ Array [
188
+ "git reset --hard && git clean -d --force && git fetch elastic 7.x && git checkout -B backport/7.x/pr-55 elastic/7.x --no-track",
189
+ Object {
190
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
191
+ },
192
+ ],
193
+ Array [
194
+ "git fetch elastic master:master --force",
195
+ Object {
196
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
197
+ },
198
+ ],
199
+ Array [
200
+ "git cherry-pick -x abcd",
201
+ Object {
202
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
203
+ },
204
+ ],
205
+ Array [
206
+ "git push sqren backport/7.x/pr-55:backport/7.x/pr-55 --force",
207
+ Object {
208
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
209
+ },
210
+ ],
211
+ Array [
212
+ "git reset --hard && git checkout my-source-branch-from-options && git branch -D backport/7.x/pr-55",
213
+ Object {
214
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
215
+ },
216
+ ],
217
+ ]
218
+ `);
219
+ });
220
+ it('git clone should be called with correct args', () => {
221
+ expect(rpcExecOriginalMock).toHaveBeenCalledTimes(1);
222
+ expect(rpcExecOriginalMock.mock.calls).toMatchInlineSnapshot(`
223
+ Array [
224
+ Array [
225
+ "git clone https://x-access-token:myAccessToken@github.com/elastic/kibana.git --progress",
226
+ Object {
227
+ "cwd": "/myHomeDir/.backport/repositories/elastic",
228
+ "maxBuffer": 104857600,
229
+ },
230
+ [Function],
231
+ ],
232
+ ]
233
+ `);
234
+ });
235
+ });
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.runWithOptions = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
8
4
  const HandledError_1 = require("./services/HandledError");
9
5
  const logger_1 = require("./services/logger");
10
6
  const sequentially_1 = require("./services/sequentially");
@@ -14,17 +10,14 @@ const getTargetBranches_1 = require("./ui/getTargetBranches");
14
10
  const maybeSetupRepo_1 = require("./ui/maybeSetupRepo");
15
11
  async function runWithOptions(options) {
16
12
  logger_1.logger.verbose('Backport options', options);
17
- if (options.dryRun) {
18
- logger_1.consoleLog(chalk_1.default.red('Dry run: Nothing will be pushed to Github\n'));
19
- }
20
- const commits = await getCommits_1.getCommits(options);
21
- const targetBranches = await getTargetBranches_1.getTargetBranches(options, commits);
22
- await maybeSetupRepo_1.maybeSetupRepo(options);
13
+ const commits = await (0, getCommits_1.getCommits)(options);
14
+ const targetBranches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
15
+ await (0, maybeSetupRepo_1.maybeSetupRepo)(options);
23
16
  const results = [];
24
- await sequentially_1.sequentially(targetBranches, async (targetBranch) => {
17
+ await (0, sequentially_1.sequentially)(targetBranches, async (targetBranch) => {
25
18
  logger_1.logger.info(`Backporting ${JSON.stringify(commits)} to ${targetBranch}`);
26
19
  try {
27
- const pullRequest = await cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest({
20
+ const pullRequest = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
28
21
  options,
29
22
  commits,
30
23
  targetBranch,
@@ -38,10 +31,10 @@ async function runWithOptions(options) {
38
31
  catch (e) {
39
32
  const isHandledError = e instanceof HandledError_1.HandledError;
40
33
  const errorMessage = isHandledError
41
- ? logger_1.redact(e.message)
34
+ ? (0, logger_1.redact)(e.message)
42
35
  : 'An unhandled error occurred. Please consult the logs';
43
36
  results.push({ targetBranch, success: false, errorMessage, error: e });
44
- logger_1.consoleLog(errorMessage);
37
+ (0, logger_1.consoleLog)(errorMessage);
45
38
  }
46
39
  });
47
40
  // return the results for consumers to programatically read