backport 8.0.0 → 8.3.0-beta.1

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 (217) hide show
  1. package/README.md +4 -4
  2. package/dist/backportRun.d.ts +5 -4
  3. package/dist/backportRun.js +42 -48
  4. package/dist/entrypoint.cli.js +3 -7
  5. package/dist/entrypoint.module.d.ts +7 -5
  6. package/dist/entrypoint.module.js +11 -9
  7. package/dist/entrypoint.module.private.test.js +25 -4
  8. package/dist/errors/BackportError.d.ts +19 -0
  9. package/dist/errors/BackportError.js +29 -0
  10. package/dist/lib/BackportError.d.ts +19 -0
  11. package/dist/lib/BackportError.js +29 -0
  12. package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +11 -0
  13. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +242 -0
  14. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  15. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +321 -0
  16. package/dist/lib/child-process-promisified.d.ts +25 -0
  17. package/dist/lib/child-process-promisified.js +60 -0
  18. package/dist/lib/env.d.ts +9 -0
  19. package/dist/lib/env.js +33 -0
  20. package/dist/lib/env.test.d.ts +1 -0
  21. package/dist/lib/env.test.js +26 -0
  22. package/dist/lib/getCommits.d.ts +2 -0
  23. package/dist/lib/getCommits.js +75 -0
  24. package/dist/lib/getCommitsWithoutBackports.d.ts +11 -0
  25. package/dist/lib/getCommitsWithoutBackports.js +68 -0
  26. package/dist/lib/getCommitsWithoutBackports.test.d.ts +1 -0
  27. package/dist/lib/getCommitsWithoutBackports.test.js +335 -0
  28. package/dist/lib/getGitConfigAuthor.d.ts +6 -0
  29. package/dist/lib/getGitConfigAuthor.js +15 -0
  30. package/dist/lib/getTargetBranches.d.ts +5 -0
  31. package/dist/lib/getTargetBranches.js +67 -0
  32. package/dist/lib/getTargetBranches.test.d.ts +1 -0
  33. package/dist/lib/getTargetBranches.test.js +210 -0
  34. package/dist/lib/git.d.ts +77 -0
  35. package/dist/lib/git.js +439 -0
  36. package/dist/lib/git.private.test.d.ts +1 -0
  37. package/dist/lib/git.private.test.js +618 -0
  38. package/dist/lib/git.test.d.ts +1 -0
  39. package/dist/lib/git.test.js +580 -0
  40. package/dist/lib/github/commitFormatters.d.ts +3 -0
  41. package/dist/lib/github/commitFormatters.js +17 -0
  42. package/dist/lib/github/commitFormatters.test.d.ts +1 -0
  43. package/dist/lib/github/commitFormatters.test.js +11 -0
  44. package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +2 -0
  45. package/dist/lib/github/v3/addAssigneesToPullRequest.js +32 -0
  46. package/dist/lib/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  47. package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +27 -0
  48. package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +2 -0
  49. package/dist/lib/github/v3/addLabelsToPullRequest.js +30 -0
  50. package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +2 -0
  51. package/dist/lib/github/v3/addReviewersToPullRequest.js +32 -0
  52. package/dist/lib/github/v3/createPullRequest.d.ts +29 -0
  53. package/dist/lib/github/v3/createPullRequest.js +91 -0
  54. package/dist/lib/github/v3/createPullRequest.test.d.ts +1 -0
  55. package/dist/lib/github/v3/createPullRequest.test.js +377 -0
  56. package/dist/lib/github/v3/createStatusComment.d.ts +11 -0
  57. package/dist/lib/github/v3/createStatusComment.js +138 -0
  58. package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
  59. package/dist/lib/github/v3/createStatusComment.test.js +566 -0
  60. package/dist/lib/github/v3/getGithubV3ErrorMessage.d.ts +14 -0
  61. package/dist/lib/github/v3/getGithubV3ErrorMessage.js +16 -0
  62. package/dist/lib/github/v4/FetchPullRequestId.d.ts +2 -0
  63. package/dist/lib/github/v4/FetchPullRequestId.js +36 -0
  64. package/dist/lib/github/v4/apiRequestV4.d.ts +31 -0
  65. package/dist/lib/github/v4/apiRequestV4.js +71 -0
  66. package/dist/lib/github/v4/apiRequestV4.test.d.ts +1 -0
  67. package/dist/lib/github/v4/apiRequestV4.test.js +109 -0
  68. package/dist/lib/github/v4/disablePullRequestAutoMerge.d.ts +2 -0
  69. package/dist/lib/github/v4/disablePullRequestAutoMerge.js +32 -0
  70. package/dist/lib/github/v4/enablePullRequestAutoMerge.d.ts +2 -0
  71. package/dist/lib/github/v4/enablePullRequestAutoMerge.js +50 -0
  72. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  73. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  74. package/dist/lib/github/v4/fetchAuthorId.d.ts +10 -0
  75. package/dist/lib/github/v4/fetchAuthorId.js +28 -0
  76. package/dist/lib/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  77. package/dist/lib/github/v4/fetchAuthorId.private.test.js +25 -0
  78. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  79. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
  80. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +11 -0
  81. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +58 -0
  82. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  83. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +136 -0
  84. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.d.ts +11 -0
  85. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +48 -0
  86. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  87. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +118 -0
  88. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +29 -0
  89. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +110 -0
  90. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  91. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +196 -0
  92. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  93. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
  94. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  95. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +107 -0
  96. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +12 -0
  97. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +69 -0
  98. package/dist/lib/github/v4/fetchExistingPullRequest.d.ts +9 -0
  99. package/dist/lib/github/v4/fetchExistingPullRequest.js +64 -0
  100. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  101. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.js +44 -0
  102. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.d.ts +2 -0
  103. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.js +39 -0
  104. package/dist/lib/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  105. package/dist/lib/github/v4/fetchRemoteProjectConfig.js +49 -0
  106. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  107. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.js +49 -0
  108. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +72 -0
  109. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +78 -0
  110. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  111. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +116 -0
  112. package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +16 -0
  113. package/dist/lib/github/v4/getOptionsFromGithub/query.js +29 -0
  114. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
  115. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.js +61 -0
  116. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  117. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +72 -0
  118. package/dist/lib/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  119. package/dist/lib/github/v4/mocks/commitsByAuthorMock.js +176 -0
  120. package/dist/lib/github/v4/throwOnInvalidAccessToken.d.ts +7 -0
  121. package/dist/lib/github/v4/throwOnInvalidAccessToken.js +45 -0
  122. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  123. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  124. package/dist/lib/github/v4/validateTargetBranches.d.ts +9 -0
  125. package/dist/lib/github/v4/validateTargetBranches.js +46 -0
  126. package/dist/lib/github/v4/validateTargetBranches.private.test.d.ts +1 -0
  127. package/dist/lib/github/v4/validateTargetBranches.private.test.js +51 -0
  128. package/dist/lib/logger.d.ts +11 -0
  129. package/dist/lib/logger.js +80 -0
  130. package/dist/lib/ora.d.ts +2 -0
  131. package/dist/lib/ora.js +21 -0
  132. package/dist/lib/prompt.test.d.ts +1 -0
  133. package/dist/lib/prompt.test.js +139 -0
  134. package/dist/lib/prompts.d.ts +17 -0
  135. package/dist/lib/prompts.js +132 -0
  136. package/dist/lib/remoteConfig.d.ts +20 -0
  137. package/dist/lib/remoteConfig.js +52 -0
  138. package/dist/lib/sequentially.d.ts +1 -0
  139. package/dist/lib/sequentially.js +10 -0
  140. package/dist/lib/setupRepo.d.ts +2 -0
  141. package/dist/lib/setupRepo.js +56 -0
  142. package/dist/lib/setupRepo.test.d.ts +1 -0
  143. package/dist/lib/setupRepo.test.js +278 -0
  144. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
  145. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
  146. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  147. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
  148. package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
  149. package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
  150. package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
  151. package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
  152. package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  153. package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
  154. package/dist/options/ConfigOptions.d.ts +4 -2
  155. package/dist/options/cliArgs.d.ts +12 -9
  156. package/dist/options/cliArgs.js +34 -19
  157. package/dist/options/cliArgs.test.js +126 -2
  158. package/dist/options/config/config.d.ts +5 -4
  159. package/dist/options/config/config.js +3 -5
  160. package/dist/options/config/config.test.js +0 -1
  161. package/dist/options/config/globalConfig.d.ts +3 -1
  162. package/dist/options/config/globalConfig.js +5 -5
  163. package/dist/options/config/readConfigFile.d.ts +6 -4
  164. package/dist/options/config/readConfigFile.js +2 -2
  165. package/dist/options/options.d.ts +40 -4
  166. package/dist/options/options.js +20 -24
  167. package/dist/options/options.test.js +112 -54
  168. package/dist/runSequentially.d.ts +10 -9
  169. package/dist/runSequentially.js +7 -8
  170. package/dist/scripts/postinstall.js +3 -3
  171. package/dist/scripts/postinstall.test.js +1 -1
  172. package/dist/services/BackportError.d.ts +19 -0
  173. package/dist/services/BackportError.js +29 -0
  174. package/dist/services/HandledBackportError.d.ts +19 -0
  175. package/dist/services/HandledBackportError.js +29 -0
  176. package/dist/services/HandledError.d.ts +1 -1
  177. package/dist/services/HandledError.js +5 -5
  178. package/dist/services/git.js +7 -7
  179. package/dist/services/github/v3/createPullRequest.js +2 -2
  180. package/dist/services/github/v3/createStatusComment.js +2 -2
  181. package/dist/services/github/v3/createStatusComment.test.js +5 -4
  182. package/dist/services/github/v4/apiRequestV4.js +2 -2
  183. package/dist/services/github/v4/apiRequestV4.test.js +2 -2
  184. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +3 -3
  185. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
  186. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +3 -3
  187. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +2 -2
  188. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
  189. package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
  190. package/dist/state.d.ts +0 -0
  191. package/dist/state.js +1 -0
  192. package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
  193. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +27 -25
  194. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +46 -250
  195. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.d.ts +1 -0
  196. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +80 -0
  197. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.d.ts +1 -0
  198. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +199 -0
  199. package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +1 -0
  200. package/dist/test/e2e/cli/interactive-error-handling.private.test.js +80 -0
  201. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +1 -0
  202. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +198 -0
  203. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +13 -15
  204. package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -2
  205. package/dist/test/e2e/cli/runBackportViaCli.js +42 -29
  206. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
  207. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +2 -2
  208. package/dist/test/handleUnbackportedPullRequests.private.test.js +3 -2
  209. package/dist/test/setupFiles/automatic-mocks.js +1 -1
  210. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
  211. package/dist/ui/getCommits.js +2 -2
  212. package/dist/ui/getTargetBranches.js +3 -3
  213. package/dist/ui/setupRepo.js +2 -2
  214. package/dist/utils/packageVersion.d.ts +1 -1
  215. package/dist/utils/packageVersion.js +1 -1
  216. package/package.json +14 -14
  217. package/yarn.lock +125 -73
@@ -0,0 +1,33 @@
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
+ exports.getRepoPath = exports.getGlobalConfigPath = exports.getLogfilePath = exports.getBackportDirPath = void 0;
7
+ const os_1 = require("os");
8
+ const path_1 = __importDefault(require("path"));
9
+ function getBackportDirPath() {
10
+ return path_1.default.join((0, os_1.homedir)(), '.backport');
11
+ }
12
+ exports.getBackportDirPath = getBackportDirPath;
13
+ function getLogfilePath({ logFilePath, logLevel, }) {
14
+ if (logFilePath) {
15
+ return path_1.default.resolve(logFilePath);
16
+ }
17
+ return path_1.default.join((0, os_1.homedir)(), '.backport', `backport.${logLevel}.log`);
18
+ }
19
+ exports.getLogfilePath = getLogfilePath;
20
+ function getGlobalConfigPath(globalConfigFile) {
21
+ if (globalConfigFile) {
22
+ return path_1.default.resolve(globalConfigFile);
23
+ }
24
+ return path_1.default.join((0, os_1.homedir)(), '.backport', 'config.json');
25
+ }
26
+ exports.getGlobalConfigPath = getGlobalConfigPath;
27
+ function getRepoPath({ repoOwner, repoName, dir }) {
28
+ if (dir) {
29
+ return dir;
30
+ }
31
+ return path_1.default.join((0, os_1.homedir)(), '.backport', 'repositories', repoOwner, repoName);
32
+ }
33
+ exports.getRepoPath = getRepoPath;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
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 env_1 = require("./env");
8
+ describe('env', () => {
9
+ beforeEach(() => {
10
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
11
+ });
12
+ describe('getGlobalConfigPath', () => {
13
+ it('uses homedir when no argument is given', () => {
14
+ expect((0, env_1.getGlobalConfigPath)(undefined)).toBe('/myHomeDir/.backport/config.json');
15
+ });
16
+ it('uses custom config when given', () => {
17
+ expect((0, env_1.getGlobalConfigPath)('/my/path/to/global/config.json')).toBe('/my/path/to/global/config.json');
18
+ });
19
+ });
20
+ it('getRepoPath', () => {
21
+ expect((0, env_1.getRepoPath)({
22
+ repoOwner: 'elastic',
23
+ repoName: 'kibana',
24
+ })).toBe('/myHomeDir/.backport/repositories/elastic/kibana');
25
+ });
26
+ });
@@ -0,0 +1,2 @@
1
+ import { ValidConfigOptions } from '../options/options';
2
+ export declare function getCommits(options: ValidConfigOptions): Promise<import("./sourceCommit/parseSourceCommit").Commit[]>;
@@ -0,0 +1,75 @@
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
+ exports.getCommits = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const BackportError_1 = require("./BackportError");
9
+ const commitFormatters_1 = require("./github/commitFormatters");
10
+ const fetchCommitByPullNumber_1 = require("./github/v4/fetchCommits/fetchCommitByPullNumber");
11
+ const fetchCommitBySha_1 = require("./github/v4/fetchCommits/fetchCommitBySha");
12
+ const fetchCommitsByAuthor_1 = require("./github/v4/fetchCommits/fetchCommitsByAuthor");
13
+ const fetchPullRequestsBySearchQuery_1 = require("./github/v4/fetchCommits/fetchPullRequestsBySearchQuery");
14
+ const ora_1 = require("./ora");
15
+ const prompts_1 = require("./prompts");
16
+ function getOraPersistsOption(question, answer) {
17
+ return {
18
+ symbol: chalk_1.default.green('?'),
19
+ text: `${chalk_1.default.bold(question)} ${chalk_1.default.cyan(answer)}`,
20
+ };
21
+ }
22
+ async function getCommits(options) {
23
+ const spinner = (0, ora_1.ora)(options.interactive).start();
24
+ try {
25
+ if (options.sha) {
26
+ const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
27
+ // TODO: use Intl.ListFormat to format the sha's
28
+ spinner.text = `Loading commit "${shas.map(commitFormatters_1.getShortSha)}"`;
29
+ const commits = await Promise.all(shas.map((sha) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha })));
30
+ spinner.stopAndPersist(getOraPersistsOption('Select commit', commits.map((commit) => commit.sourceCommit.message).join(', ')));
31
+ return commits;
32
+ }
33
+ if (options.pullNumber) {
34
+ spinner.text = `Loading pull request #${options.pullNumber}`;
35
+ const commit = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
36
+ ...options,
37
+ pullNumber: options.pullNumber, // must extract pullNumber to satisfy the ts gods
38
+ });
39
+ // add styles to make it look like a prompt question
40
+ spinner.stopAndPersist(getOraPersistsOption('Select pull request', (0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message)));
41
+ return [commit];
42
+ }
43
+ if (!options.interactive && !options.ls) {
44
+ throw new BackportError_1.BackportError('When "--interactive" is disabled either `--sha` or `--pr` must be specified');
45
+ }
46
+ spinner.text = options.prFilter
47
+ ? 'Loading pull requests...'
48
+ : `Loading commits from branch "${options.sourceBranch}"...`;
49
+ const commitChoices = options.prFilter
50
+ ? await (0, fetchPullRequestsBySearchQuery_1.fetchPullRequestsBySearchQuery)({
51
+ ...options,
52
+ prFilter: options.prFilter,
53
+ })
54
+ : await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(options);
55
+ spinner.stop();
56
+ if (options.ls) {
57
+ return commitChoices;
58
+ }
59
+ return (0, prompts_1.promptForCommits)({
60
+ commitChoices,
61
+ isMultipleChoice: options.multipleCommits,
62
+ showDetails: options.details,
63
+ });
64
+ }
65
+ catch (e) {
66
+ if (options.ls) {
67
+ spinner.stop();
68
+ }
69
+ else {
70
+ spinner.fail();
71
+ }
72
+ throw e;
73
+ }
74
+ }
75
+ exports.getCommits = getCommits;
@@ -0,0 +1,11 @@
1
+ import { Commit } from '../entrypoint.module';
2
+ import { ValidConfigOptions } from '../options/options';
3
+ export declare function getCommitsWithoutBackports({ options, commit, targetBranch, conflictingFiles, }: {
4
+ options: ValidConfigOptions;
5
+ commit: Commit;
6
+ targetBranch: string;
7
+ conflictingFiles: string[];
8
+ }): Promise<{
9
+ formatted: string;
10
+ commit: Commit;
11
+ }[]>;
@@ -0,0 +1,68 @@
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
+ exports.getCommitsWithoutBackports = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const git_1 = require("./git");
9
+ const commitFormatters_1 = require("./github/commitFormatters");
10
+ const fetchCommitsByAuthor_1 = require("./github/v4/fetchCommits/fetchCommitsByAuthor");
11
+ // when the user is facing a git conflict we should help them understand
12
+ // why the conflict occurs. In many cases it's because one or more commits haven't been backported yet
13
+ async function getCommitsWithoutBackports({ options,
14
+ // commit that is being backported
15
+ commit,
16
+ // branch the commit is being backported to
17
+ targetBranch,
18
+ // the files with conflicts on the target branch
19
+ conflictingFiles, }) {
20
+ // commits on the source branch that also touched the conflicting files
21
+ const commitsInConflictingPaths = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
22
+ ...options,
23
+ author: null,
24
+ dateSince: null,
25
+ dateUntil: commit.sourceCommit.committedDate,
26
+ commitPaths: conflictingFiles,
27
+ });
28
+ const promises = await Promise.all(commitsInConflictingPaths
29
+ .filter((c) => {
30
+ // exclude the commit we are currently trying to backport
31
+ if (c.sourceCommit.sha === commit.sourceCommit.sha) {
32
+ return false;
33
+ }
34
+ // exclude commits that are newer than the commit we are trying to backport
35
+ if (c.sourceCommit.committedDate > commit.sourceCommit.committedDate) {
36
+ return false;
37
+ }
38
+ // only consider commits that have an associated pull request
39
+ if (!c.sourcePullRequest?.url) {
40
+ return false;
41
+ }
42
+ // only include commit if it has an unmerged PR for the given target branch
43
+ const hasUnmergedPr = c.expectedTargetPullRequests.some((pr) => pr.branch === targetBranch && pr.state !== 'MERGED');
44
+ return hasUnmergedPr;
45
+ })
46
+ .slice(0, 10) // limit to max 10 commits
47
+ .map(async (c) => {
48
+ const results = await Promise.all(c.expectedTargetPullRequests.map(async (targetPr) => {
49
+ if (!targetPr.mergeCommit) {
50
+ return false;
51
+ }
52
+ return (0, git_1.getIsCommitInBranch)(options, targetPr.mergeCommit.sha);
53
+ }));
54
+ const isCommitInBranch = results.some((inBranch) => inBranch === true);
55
+ return { c, isCommitInBranch };
56
+ }));
57
+ return promises
58
+ .filter(({ isCommitInBranch }) => !isCommitInBranch)
59
+ .map(({ c }) => {
60
+ // get pull request for the target branch (if it exists)
61
+ const pendingBackportPr = c.expectedTargetPullRequests.find((pr) => pr.branch === targetBranch && pr.state === 'OPEN');
62
+ const formatted = pendingBackportPr
63
+ ? ` - ${(0, commitFormatters_1.getFirstLine)(c.sourceCommit.message)} ${chalk_1.default.gray('(backport pending)')}\n ${pendingBackportPr.url}`
64
+ : ` - ${(0, commitFormatters_1.getFirstLine)(c.sourceCommit.message)} ${chalk_1.default.red('(backport missing)')}\n ${c.sourcePullRequest?.url}`;
65
+ return { formatted, commit: c };
66
+ });
67
+ }
68
+ exports.getCommitsWithoutBackports = getCommitsWithoutBackports;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,335 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const strip_ansi_1 = __importDefault(require("strip-ansi"));
30
+ const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
31
+ const git = __importStar(require("./git"));
32
+ const fetchCommitsByAuthorModule = __importStar(require("./github/v4/fetchCommits/fetchCommitsByAuthor"));
33
+ describe('getCommitsWithoutBackports', () => {
34
+ afterEach(() => {
35
+ jest.restoreAllMocks();
36
+ });
37
+ describe('expectedTargetPullRequests', () => {
38
+ function setupExpectedPullRequests({ expectedTargetPullRequests, }) {
39
+ // simulate 1 unbackported commit
40
+ jest
41
+ .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
42
+ .mockResolvedValueOnce([
43
+ {
44
+ author: {
45
+ email: 'soren.louv@elastic.co',
46
+ name: 'Søren Louv-Jansen',
47
+ },
48
+ sourceCommit: {
49
+ committedDate: '10',
50
+ message: 'First commit (#1)',
51
+ sha: 'xyz',
52
+ },
53
+ sourcePullRequest: {
54
+ url: 'https://www.github.com/foo/bar/pull/123',
55
+ number: 123,
56
+ mergeCommit: {
57
+ message: 'First commit (#1)',
58
+ sha: 'xyz',
59
+ },
60
+ },
61
+ expectedTargetPullRequests,
62
+ sourceBranch: 'main',
63
+ },
64
+ ]);
65
+ // simulate commit is definitely not backported
66
+ jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
67
+ return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
68
+ options: {},
69
+ commit: {
70
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
71
+ sourceCommit: {
72
+ committedDate: '100',
73
+ message: 'Second commit (#2)',
74
+ sha: 'abc',
75
+ },
76
+ expectedTargetPullRequests: [],
77
+ sourceBranch: 'main',
78
+ },
79
+ targetBranch: '7.x',
80
+ conflictingFiles: ['/foo/bar/baz.ts'],
81
+ });
82
+ }
83
+ it('should not unbackported commits if no backports were expected', async () => {
84
+ const commitsWithoutBackports = await setupExpectedPullRequests({
85
+ expectedTargetPullRequests: [],
86
+ });
87
+ expect(commitsWithoutBackports.length).toEqual(0);
88
+ });
89
+ it('should display as missing if a backport is CLOSED', async () => {
90
+ const commitsWithoutBackports = await setupExpectedPullRequests({
91
+ expectedTargetPullRequests: [
92
+ {
93
+ state: 'CLOSED',
94
+ branch: '7.x',
95
+ number: 456,
96
+ url: 'https://www.github.com/foo/bar/pull/456',
97
+ },
98
+ ],
99
+ });
100
+ expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport missing)\n https://www.github.com/foo/bar/pull/123');
101
+ });
102
+ it('should display as missing if a backport is NOT_CREATED', async () => {
103
+ const commitsWithoutBackports = await setupExpectedPullRequests({
104
+ expectedTargetPullRequests: [{ state: 'NOT_CREATED', branch: '7.x' }],
105
+ });
106
+ expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport missing)\n https://www.github.com/foo/bar/pull/123');
107
+ });
108
+ it('should display as pending if a backport is OPEN', async () => {
109
+ const commitsWithoutBackports = await setupExpectedPullRequests({
110
+ expectedTargetPullRequests: [
111
+ {
112
+ state: 'OPEN',
113
+ branch: '7.x',
114
+ url: 'https://www.github.com/foo/bar/pull/456',
115
+ number: 456,
116
+ },
117
+ ],
118
+ });
119
+ expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
120
+ });
121
+ it('should not display commit as unbackported if a backport was MERGED', async () => {
122
+ const commitsWithoutBackports = await setupExpectedPullRequests({
123
+ expectedTargetPullRequests: [
124
+ {
125
+ state: 'MERGED',
126
+ branch: '7.x',
127
+ number: 456,
128
+ url: 'https://www.github.com/foo/bar/pull/456',
129
+ },
130
+ ],
131
+ });
132
+ expect(commitsWithoutBackports).toEqual([]);
133
+ });
134
+ });
135
+ describe('commitDate', () => {
136
+ function setupCommitDateDiff({ offendingCommitDate, currentCommitDate, }) {
137
+ // simulate 1 commit with a pending backport
138
+ jest
139
+ .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
140
+ .mockResolvedValueOnce([
141
+ {
142
+ author: {
143
+ email: 'soren.louv@elastic.co',
144
+ name: 'Søren Louv-Jansen',
145
+ },
146
+ sourceCommit: {
147
+ committedDate: offendingCommitDate,
148
+ message: 'First commit (#1)',
149
+ sha: 'xyz',
150
+ },
151
+ sourcePullRequest: {
152
+ number: 123,
153
+ url: 'https://www.github.com/foo/bar/pull/123',
154
+ mergeCommit: {
155
+ message: 'First commit (#1)',
156
+ sha: 'xyz',
157
+ },
158
+ },
159
+ sourceBranch: 'main',
160
+ expectedTargetPullRequests: [
161
+ {
162
+ state: 'OPEN',
163
+ branch: '7.x',
164
+ number: 456,
165
+ url: 'https://www.github.com/foo/bar/pull/456',
166
+ },
167
+ ],
168
+ },
169
+ ]);
170
+ // simulate commit is definitely not backported
171
+ jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
172
+ return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
173
+ options: {},
174
+ commit: {
175
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
176
+ sourceCommit: {
177
+ committedDate: currentCommitDate,
178
+ message: 'Second commit (#2)',
179
+ sha: 'abc',
180
+ },
181
+ sourcePullRequest: {
182
+ number: 123,
183
+ url: 'https://www.github.com/foo/bar/pull/123',
184
+ mergeCommit: {
185
+ message: 'Second commit (#2)',
186
+ sha: 'abc',
187
+ },
188
+ },
189
+ sourceBranch: 'main',
190
+ expectedTargetPullRequests: [],
191
+ },
192
+ targetBranch: '7.x',
193
+ conflictingFiles: ['/foo/bar/baz.ts'],
194
+ });
195
+ }
196
+ it('should not display commit as unbackport if is newer than the commit currently being backported', async () => {
197
+ const commitsWithoutBackports = await setupCommitDateDiff({
198
+ offendingCommitDate: '100',
199
+ currentCommitDate: '10',
200
+ });
201
+ expect(commitsWithoutBackports).toEqual([]);
202
+ });
203
+ it('should display commit as unbackport if is older than the commit currently being backported', async () => {
204
+ const commitsWithoutBackports = await setupCommitDateDiff({
205
+ offendingCommitDate: '10',
206
+ currentCommitDate: '100',
207
+ });
208
+ expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
209
+ });
210
+ });
211
+ describe('targetBranch', () => {
212
+ function setupTargetBranchDiff({ offendingCommitTargetBranch, currentCommitTargetBranch, }) {
213
+ // return mock commits that also touched the conflicting files
214
+ jest
215
+ .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
216
+ .mockResolvedValueOnce([
217
+ {
218
+ author: {
219
+ email: 'soren.louv@elastic.co',
220
+ name: 'Søren Louv-Jansen',
221
+ },
222
+ sourceCommit: {
223
+ committedDate: '10',
224
+ message: 'First commit (#1)',
225
+ sha: 'xyz',
226
+ },
227
+ sourcePullRequest: {
228
+ number: 123,
229
+ url: 'https://www.github.com/foo/bar/pull/123',
230
+ mergeCommit: {
231
+ message: 'First commit (#1)',
232
+ sha: 'xyz',
233
+ },
234
+ },
235
+ sourceBranch: 'main',
236
+ expectedTargetPullRequests: [
237
+ {
238
+ branch: offendingCommitTargetBranch,
239
+ state: 'OPEN',
240
+ url: 'https://www.github.com/foo/bar/pull/456',
241
+ number: 456,
242
+ },
243
+ ],
244
+ },
245
+ ]);
246
+ // simulate commit is definitely not backported
247
+ jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
248
+ return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
249
+ options: {},
250
+ // commit that is being backported
251
+ commit: {
252
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
253
+ sourceCommit: {
254
+ committedDate: '100',
255
+ message: 'Second commit (#2)',
256
+ sha: 'abc',
257
+ },
258
+ sourcePullRequest: {
259
+ url: 'https://www.github.com/foo/bar/pull/123',
260
+ number: 123,
261
+ mergeCommit: {
262
+ message: 'Second commit (#2)',
263
+ sha: 'abc',
264
+ },
265
+ },
266
+ expectedTargetPullRequests: [],
267
+ sourceBranch: 'main',
268
+ },
269
+ targetBranch: currentCommitTargetBranch,
270
+ conflictingFiles: ['/foo/bar/baz.ts'],
271
+ });
272
+ }
273
+ it('should display backport as pending if target branches match', async () => {
274
+ const commitsWithoutBackports = await setupTargetBranchDiff({
275
+ offendingCommitTargetBranch: '7.x',
276
+ currentCommitTargetBranch: '7.x',
277
+ });
278
+ expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
279
+ });
280
+ it("should not display commit if target branches don't match", async () => {
281
+ const commitsWithoutBackports = await setupTargetBranchDiff({
282
+ offendingCommitTargetBranch: '7.x',
283
+ currentCommitTargetBranch: '8.x',
284
+ });
285
+ expect(commitsWithoutBackports.length).toBe(0);
286
+ });
287
+ });
288
+ describe("when conflicting commit doesn't have an associated pull request", () => {
289
+ it('should be ignored', async () => {
290
+ jest
291
+ .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
292
+ .mockResolvedValueOnce([
293
+ {
294
+ author: {
295
+ email: 'soren.louv@elastic.co',
296
+ name: 'Søren Louv-Jansen',
297
+ },
298
+ sourceCommit: {
299
+ committedDate: '10',
300
+ sha: 'xyz',
301
+ message: 'First commit (#1)',
302
+ },
303
+ expectedTargetPullRequests: [],
304
+ sourceBranch: 'main',
305
+ },
306
+ ]);
307
+ // simulate commit is definitely not backported
308
+ jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
309
+ const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
310
+ options: {},
311
+ commit: {
312
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
313
+ sourceCommit: {
314
+ committedDate: '100',
315
+ message: 'Second commit (#2)',
316
+ sha: 'abc',
317
+ },
318
+ sourcePullRequest: {
319
+ url: 'https://www.github.com/foo/bar/pull/123',
320
+ number: 123,
321
+ mergeCommit: {
322
+ message: 'Second commit (#2)',
323
+ sha: 'abc',
324
+ },
325
+ },
326
+ expectedTargetPullRequests: [],
327
+ sourceBranch: 'main',
328
+ },
329
+ targetBranch: '7.x',
330
+ conflictingFiles: ['/foo/bar/baz.ts'],
331
+ });
332
+ expect(commitsWithoutBackports.length).toEqual(0);
333
+ });
334
+ });
335
+ });
@@ -0,0 +1,6 @@
1
+ import { ValidConfigOptions } from '../options/options';
2
+ export declare type GitConfigAuthor = {
3
+ name?: string;
4
+ email?: string;
5
+ };
6
+ export declare function getGitConfigAuthor(options: ValidConfigOptions): Promise<GitConfigAuthor | undefined>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGitConfigAuthor = void 0;
4
+ const git_1 = require("./git");
5
+ async function getGitConfigAuthor(options) {
6
+ const localRepoPath = await (0, git_1.getLocalSourceRepoPath)(options);
7
+ if (!localRepoPath) {
8
+ return;
9
+ }
10
+ return {
11
+ name: await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.name' }),
12
+ email: await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.email' }),
13
+ };
14
+ }
15
+ exports.getGitConfigAuthor = getGitConfigAuthor;
@@ -0,0 +1,5 @@
1
+ import { TargetBranchChoice } from '../options/ConfigOptions';
2
+ import { ValidConfigOptions } from '../options/options';
3
+ import { Commit } from './sourceCommit/parseSourceCommit';
4
+ export declare function getTargetBranches(options: ValidConfigOptions, commits: Commit[]): Promise<string[]>;
5
+ export declare function getTargetBranchChoices(options: ValidConfigOptions, missingTargetBranches: string[], sourceBranch: string): TargetBranchChoice[];
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTargetBranchChoices = exports.getTargetBranches = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const BackportError_1 = require("./BackportError");
6
+ const prompts_1 = require("./prompts");
7
+ async function getTargetBranches(options, commits) {
8
+ // target branches already specified (in contrast to letting the user choose from a list)
9
+ if (!(0, lodash_1.isEmpty)(options.targetBranches)) {
10
+ return options.targetBranches;
11
+ }
12
+ // target branches from the first commit
13
+ const missingTargetBranches = commits.length === 1
14
+ ? commits[0].expectedTargetPullRequests
15
+ .filter((pr) => pr.state === 'NOT_CREATED' || pr.state === 'CLOSED')
16
+ .map((pr) => pr.branch)
17
+ : [];
18
+ // require target branches to be specified when when in non-interactive mode
19
+ if (!options.interactive) {
20
+ if ((0, lodash_1.isEmpty)(missingTargetBranches)) {
21
+ throw new BackportError_1.BackportError({ code: 'no-branches-exception' });
22
+ }
23
+ return missingTargetBranches;
24
+ }
25
+ // sourceBranch should be the same for all commits, so picking `sourceBranch` from the first commit should be fine 🤞
26
+ // this is specifically needed when backporting a PR like `backport --pr 123` and the source PR was merged to a non-default (aka non-master) branch.
27
+ const { sourceBranch } = commits[0];
28
+ const targetBranchChoices = getTargetBranchChoices(options, missingTargetBranches, sourceBranch);
29
+ // render prmompt for selecting target branches
30
+ return (0, prompts_1.promptForTargetBranches)({
31
+ targetBranchChoices,
32
+ isMultipleChoice: options.multipleBranches,
33
+ });
34
+ }
35
+ exports.getTargetBranches = getTargetBranches;
36
+ function getTargetBranchChoices(options, missingTargetBranches, sourceBranch) {
37
+ // exclude sourceBranch from targetBranchChoices
38
+ const targetBranchesChoices = getTargetBranchChoicesAsObject(options.targetBranchChoices).filter((choice) => choice.name !== sourceBranch);
39
+ if ((0, lodash_1.isEmpty)(targetBranchesChoices)) {
40
+ throw new BackportError_1.BackportError('Missing target branch choices');
41
+ }
42
+ if (!options.branchLabelMapping) {
43
+ return targetBranchesChoices;
44
+ }
45
+ // select missing target branches (based on pull request labels)
46
+ return targetBranchesChoices.map((choice) => {
47
+ const isChecked = missingTargetBranches.includes(choice.name);
48
+ return { ...choice, checked: isChecked };
49
+ });
50
+ }
51
+ exports.getTargetBranchChoices = getTargetBranchChoices;
52
+ // `targetBranchChoices` can either be a string or an object.
53
+ // It must be transformed so it is always treated as an object troughout the application
54
+ function getTargetBranchChoicesAsObject(targetBranchChoices) {
55
+ if (!targetBranchChoices) {
56
+ return [];
57
+ }
58
+ return targetBranchChoices.map((choice) => {
59
+ if ((0, lodash_1.isString)(choice)) {
60
+ return {
61
+ name: choice,
62
+ checked: false,
63
+ };
64
+ }
65
+ return choice;
66
+ });
67
+ }
@@ -0,0 +1 @@
1
+ export {};