backport 7.3.6 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/README.md +16 -21
  2. package/dist/backportRun.d.ts +18 -6
  3. package/dist/backportRun.js +70 -50
  4. package/dist/entrypoint.cli.js +4 -8
  5. package/dist/entrypoint.module.d.ts +13 -6
  6. package/dist/entrypoint.module.js +17 -19
  7. package/dist/entrypoint.module.private.test.js +129 -330
  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 +13 -0
  13. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +238 -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 +58 -0
  18. package/dist/lib/env.d.ts +7 -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 +206 -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 +136 -0
  58. package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
  59. package/dist/lib/github/v3/createStatusComment.test.js +461 -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/logger.d.ts +9 -0
  125. package/dist/lib/logger.js +74 -0
  126. package/dist/lib/ora.d.ts +2 -0
  127. package/dist/lib/ora.js +21 -0
  128. package/dist/lib/prompt.test.d.ts +1 -0
  129. package/dist/lib/prompt.test.js +139 -0
  130. package/dist/lib/prompts.d.ts +17 -0
  131. package/dist/lib/prompts.js +132 -0
  132. package/dist/lib/remoteConfig.d.ts +20 -0
  133. package/dist/lib/remoteConfig.js +52 -0
  134. package/dist/lib/sequentially.d.ts +1 -0
  135. package/dist/lib/sequentially.js +10 -0
  136. package/dist/lib/setupRepo.d.ts +2 -0
  137. package/dist/lib/setupRepo.js +56 -0
  138. package/dist/lib/setupRepo.test.d.ts +1 -0
  139. package/dist/lib/setupRepo.test.js +278 -0
  140. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
  141. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
  142. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  143. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
  144. package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
  145. package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
  146. package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
  147. package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
  148. package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  149. package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
  150. package/dist/options/ConfigOptions.d.ts +6 -4
  151. package/dist/options/cliArgs.d.ts +16 -9
  152. package/dist/options/cliArgs.js +54 -28
  153. package/dist/options/cliArgs.test.js +128 -4
  154. package/dist/options/config/config.d.ts +7 -6
  155. package/dist/options/config/config.js +5 -7
  156. package/dist/options/config/config.test.js +0 -1
  157. package/dist/options/config/globalConfig.d.ts +5 -3
  158. package/dist/options/config/globalConfig.js +17 -14
  159. package/dist/options/config/projectConfig.d.ts +2 -2
  160. package/dist/options/config/projectConfig.js +3 -3
  161. package/dist/options/config/projectConfig.test.js +19 -7
  162. package/dist/options/config/readConfigFile.d.ts +9 -7
  163. package/dist/options/config/readConfigFile.js +2 -2
  164. package/dist/options/options.d.ts +44 -9
  165. package/dist/options/options.js +22 -27
  166. package/dist/options/options.test.js +119 -58
  167. package/dist/runSequentially.d.ts +14 -7
  168. package/dist/runSequentially.js +26 -11
  169. package/dist/scripts/postinstall.js +4 -3
  170. package/dist/scripts/postinstall.test.js +6 -2
  171. package/dist/services/BackportError.d.ts +19 -0
  172. package/dist/services/BackportError.js +29 -0
  173. package/dist/services/HandledBackportError.d.ts +19 -0
  174. package/dist/services/HandledBackportError.js +29 -0
  175. package/dist/services/HandledError.d.ts +7 -3
  176. package/dist/services/HandledError.js +13 -13
  177. package/dist/services/child-process-promisified.d.ts +19 -3
  178. package/dist/services/child-process-promisified.js +46 -17
  179. package/dist/services/git.d.ts +6 -7
  180. package/dist/services/git.integration.test.js +381 -65
  181. package/dist/services/git.js +189 -127
  182. package/dist/services/git.private.test.d.ts +1 -0
  183. package/dist/services/git.private.test.js +618 -0
  184. package/dist/services/git.test.js +167 -158
  185. package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
  186. package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
  187. package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
  188. package/dist/services/github/v3/createPullRequest.js +4 -2
  189. package/dist/services/github/v3/createStatusComment.js +17 -17
  190. package/dist/services/github/v3/createStatusComment.test.js +22 -9
  191. package/dist/services/github/v4/apiRequestV4.js +8 -11
  192. package/dist/services/github/v4/apiRequestV4.test.js +2 -2
  193. package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
  194. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
  195. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +5 -6
  196. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +4 -3
  197. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +10 -9
  198. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +3 -2
  199. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +10 -9
  200. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +4 -3
  201. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +9 -8
  202. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +3 -6
  203. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +3 -2
  204. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -6
  205. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +4 -7
  206. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -2
  207. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
  208. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -7
  209. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +9 -8
  210. package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
  211. package/dist/services/logger.d.ts +1 -4
  212. package/dist/services/logger.js +14 -19
  213. package/dist/services/test.d.ts +1 -0
  214. package/dist/services/test.js +23 -0
  215. package/dist/state.d.ts +0 -0
  216. package/dist/state.js +1 -0
  217. package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
  218. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +26 -24
  219. package/dist/test/e2e/cli/entrypoint.cli.private.test.d.ts +1 -0
  220. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +450 -0
  221. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +27 -28
  222. package/dist/test/e2e/cli/runBackportViaCli.d.ts +6 -2
  223. package/dist/test/e2e/cli/runBackportViaCli.js +44 -23
  224. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
  225. package/dist/test/e2e/module/entrypoint.module.mutation.test.d.ts +1 -0
  226. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +376 -0
  227. package/dist/test/handleUnbackportedPullRequests.private.test.js +12 -10
  228. package/dist/test/sandbox.js +5 -1
  229. package/dist/test/setupFiles/automatic-mocks.js +17 -13
  230. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +11 -7
  231. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
  232. package/dist/ui/getCommits.js +2 -2
  233. package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
  234. package/dist/ui/getGitConfigAuthor.js +1 -1
  235. package/dist/ui/getTargetBranches.js +3 -3
  236. package/dist/ui/getTargetBranches.test.js +5 -1
  237. package/dist/ui/ora.d.ts +1 -8
  238. package/dist/ui/setupRepo.js +3 -3
  239. package/dist/ui/setupRepo.test.js +98 -61
  240. package/dist/utils/isErrnoError.d.ts +2 -0
  241. package/dist/utils/isErrnoError.js +7 -0
  242. package/dist/utils/packageVersion.d.ts +1 -1
  243. package/dist/utils/packageVersion.js +1 -1
  244. package/package.json +17 -17
  245. package/yarn.lock +461 -695
@@ -0,0 +1,206 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const getTargetBranches_1 = require("./getTargetBranches");
27
+ const prompts = __importStar(require("./prompts"));
28
+ describe('getTargetBranches', () => {
29
+ let promptSpy;
30
+ beforeEach(() => {
31
+ jest.clearAllMocks();
32
+ promptSpy = jest
33
+ .spyOn(prompts, 'promptForTargetBranches')
34
+ .mockResolvedValueOnce(['branchA']);
35
+ });
36
+ describe('when `options.targetBranches` is empty', () => {
37
+ let branches;
38
+ beforeEach(async () => {
39
+ const options = {
40
+ targetBranches: [],
41
+ targetBranchChoices: [{ name: 'branchA' }, { name: 'branchB' }],
42
+ multipleBranches: false,
43
+ interactive: true,
44
+ };
45
+ const commits = [
46
+ {
47
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
48
+ sourceCommit: {
49
+ committedDate: 'aaa',
50
+ message: 'hey',
51
+ sha: 'abcd',
52
+ },
53
+ sourcePullRequest: {
54
+ url: 'foo',
55
+ number: 1337,
56
+ mergeCommit: {
57
+ message: 'hey',
58
+ sha: 'abcd',
59
+ },
60
+ },
61
+ sourceBranch: '7.x',
62
+ expectedTargetPullRequests: [],
63
+ },
64
+ ];
65
+ branches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
66
+ });
67
+ it('should return branches from prompt', () => {
68
+ expect(branches).toEqual(['branchA']);
69
+ });
70
+ it('should call prompt with correct args', () => {
71
+ expect(promptSpy).toHaveBeenLastCalledWith({
72
+ targetBranchChoices: [{ name: 'branchA' }, { name: 'branchB' }],
73
+ isMultipleChoice: false,
74
+ });
75
+ });
76
+ });
77
+ describe('when `options.targetBranches` is not empty', () => {
78
+ let branches;
79
+ beforeEach(() => {
80
+ branches = (0, getTargetBranches_1.getTargetBranches)({
81
+ targetBranches: ['branchA', 'branchB'],
82
+ targetBranchChoices: [],
83
+ multipleBranches: false,
84
+ }, []);
85
+ });
86
+ it('should return branches from `options.branches`', () => {
87
+ expect(branches).toEqual(['branchA', 'branchB']);
88
+ });
89
+ it('should not call prompt', () => {
90
+ expect(promptSpy).not.toHaveBeenCalled();
91
+ });
92
+ });
93
+ describe('when interactive=false', () => {
94
+ it('should throw when there are no missing backports', () => {
95
+ const commits = [];
96
+ expect(() => {
97
+ return (0, getTargetBranches_1.getTargetBranches)({
98
+ expectedTargetPullRequests: [],
99
+ interactive: false,
100
+ }, commits);
101
+ }).toThrow('There are no branches to backport to. Aborting.');
102
+ });
103
+ it('should return missing backports', () => {
104
+ const commits = [
105
+ {
106
+ expectedTargetPullRequests: [
107
+ { branch: '7.2', state: 'MERGED' },
108
+ { branch: '7.1', state: 'OPEN' },
109
+ { branch: '7.x', state: 'NOT_CREATED' },
110
+ ],
111
+ },
112
+ ];
113
+ const targetBranches = (0, getTargetBranches_1.getTargetBranches)({ interactive: false }, commits);
114
+ expect(targetBranches).toEqual(['7.x']);
115
+ });
116
+ });
117
+ describe('when `expectedTargetPullRequests` is missing a backport to 7.x', () => {
118
+ let targetBranchChoices;
119
+ beforeEach(async () => {
120
+ const options = {
121
+ interactive: true,
122
+ targetBranches: [],
123
+ multipleBranches: true,
124
+ targetBranchChoices: [
125
+ { name: 'master' },
126
+ { name: '7.x' },
127
+ { name: '7.7' },
128
+ { name: '7.6' },
129
+ { name: '7.5' },
130
+ ],
131
+ branchLabelMapping: {},
132
+ sourceBranch: 'master',
133
+ };
134
+ const commits = [
135
+ {
136
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
137
+ sourceCommit: {
138
+ committedDate: 'bbb',
139
+ message: '[backport] Bump to 5.1.3 (#62286)',
140
+ sha: 'my-sha',
141
+ },
142
+ sourcePullRequest: {
143
+ url: 'foo',
144
+ number: 62286,
145
+ mergeCommit: {
146
+ message: '[backport] Bump to 5.1.3 (#62286)',
147
+ sha: 'my-sha',
148
+ },
149
+ },
150
+ sourceBranch: 'master',
151
+ expectedTargetPullRequests: [{ branch: '7.x', state: 'NOT_CREATED' }],
152
+ },
153
+ ];
154
+ await (0, getTargetBranches_1.getTargetBranches)(options, commits);
155
+ targetBranchChoices = promptSpy.mock.calls[0][0].targetBranchChoices;
156
+ });
157
+ it('should list the correct branches', async () => {
158
+ expect(targetBranchChoices).toEqual([
159
+ { checked: true, name: '7.x' },
160
+ { checked: false, name: '7.7' },
161
+ { checked: false, name: '7.6' },
162
+ { checked: false, name: '7.5' },
163
+ ]);
164
+ });
165
+ it('should not list the sourceBranch (master)', async () => {
166
+ expect(targetBranchChoices).not.toContainEqual(expect.objectContaining({ name: 'master' }));
167
+ });
168
+ it('should select 7.x', async () => {
169
+ expect(targetBranchChoices).toContainEqual({
170
+ name: '7.x',
171
+ checked: true,
172
+ });
173
+ });
174
+ });
175
+ });
176
+ describe('getTargetBranchChoices', () => {
177
+ const options = {
178
+ interactive: true,
179
+ targetBranchChoices: [
180
+ { name: 'master', checked: true },
181
+ { name: '7.x', checked: true },
182
+ { name: '7.8', checked: false },
183
+ { name: '7.7', checked: false },
184
+ ],
185
+ branchLabelMapping: {},
186
+ };
187
+ const sourceBranch = 'master';
188
+ it('should not check any branches if no labels match', () => {
189
+ const targetBranchesFromLabels = [];
190
+ const branches = (0, getTargetBranches_1.getTargetBranchChoices)(options, targetBranchesFromLabels, sourceBranch);
191
+ expect(branches).toEqual([
192
+ { checked: false, name: '7.x' },
193
+ { checked: false, name: '7.8' },
194
+ { checked: false, name: '7.7' },
195
+ ]);
196
+ });
197
+ it('should pre-select branches based on labels', () => {
198
+ const targetBranchesFromLabels = ['7.7'];
199
+ const branches = (0, getTargetBranches_1.getTargetBranchChoices)(options, targetBranchesFromLabels, sourceBranch);
200
+ expect(branches).toEqual([
201
+ { checked: false, name: '7.x' },
202
+ { checked: false, name: '7.8' },
203
+ { checked: true, name: '7.7' },
204
+ ]);
205
+ });
206
+ });
@@ -0,0 +1,77 @@
1
+ import { ValidConfigOptions } from '../options/options';
2
+ import { ExpectedTargetPullRequest } from './sourceCommit/getExpectedTargetPullRequests';
3
+ import { Commit } from './sourceCommit/parseSourceCommit';
4
+ export declare function getRemoteUrl({ repoName, accessToken, gitHostname }: ValidConfigOptions, repoOwner: string): string;
5
+ export declare function cloneRepo({ sourcePath, targetPath }: {
6
+ sourcePath: string;
7
+ targetPath: string;
8
+ }, onProgress: (progress: number) => void): Promise<void>;
9
+ export declare function getLocalConfigFileCommitDate({ cwd }: {
10
+ cwd: string;
11
+ }): Promise<number | undefined>;
12
+ export declare function isLocalConfigFileUntracked({ cwd }: {
13
+ cwd: string;
14
+ }): Promise<boolean | undefined>;
15
+ export declare function isLocalConfigFileModified({ cwd }: {
16
+ cwd: string;
17
+ }): Promise<boolean>;
18
+ export declare function getRepoInfoFromGitRemotes({ cwd }: {
19
+ cwd: string;
20
+ }): Promise<{
21
+ repoOwner: string;
22
+ repoName: string;
23
+ }[]>;
24
+ export declare function getGitProjectRootPath(dir: string): Promise<string | undefined>;
25
+ export declare function getIsCommitInBranch(options: ValidConfigOptions, commitSha: string): Promise<boolean>;
26
+ export declare function deleteRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
27
+ export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
28
+ export declare function fetchBranch(options: ValidConfigOptions, branch: string): Promise<void>;
29
+ export declare function getIsMergeCommit(options: ValidConfigOptions, sha: string): Promise<boolean>;
30
+ export declare function getCommitsInMergeCommit(options: ValidConfigOptions, sha: string): Promise<string[]>;
31
+ export declare function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor, }: {
32
+ options: ValidConfigOptions;
33
+ sha: string;
34
+ mergedTargetPullRequest?: ExpectedTargetPullRequest;
35
+ commitAuthor: {
36
+ name: string;
37
+ email: string;
38
+ };
39
+ }): Promise<{
40
+ conflictingFiles: {
41
+ absolute: string;
42
+ relative: string;
43
+ }[];
44
+ unstagedFiles: string[];
45
+ needsResolving: boolean;
46
+ }>;
47
+ export declare function commitChanges(commit: Commit, options: ValidConfigOptions): Promise<void>;
48
+ export declare type ConflictingFiles = Awaited<ReturnType<typeof getConflictingFiles>>;
49
+ export declare function getConflictingFiles(options: ValidConfigOptions): Promise<{
50
+ absolute: string;
51
+ relative: string;
52
+ }[]>;
53
+ export declare function getUnstagedFiles(options: ValidConfigOptions): Promise<string[]>;
54
+ export declare function getGitConfig({ dir, key, }: {
55
+ dir: string;
56
+ key: 'user.name' | 'user.email';
57
+ }): Promise<string | undefined>;
58
+ export declare function createBackportBranch({ options, targetBranch, backportBranch, }: {
59
+ options: ValidConfigOptions;
60
+ targetBranch: string;
61
+ backportBranch: string;
62
+ }): Promise<void>;
63
+ export declare function deleteBackportBranch({ options, backportBranch, }: {
64
+ options: ValidConfigOptions;
65
+ backportBranch: string;
66
+ }): Promise<void>;
67
+ export declare function getRepoForkOwner(options: ValidConfigOptions): string;
68
+ export declare function pushBackportBranch({ options, backportBranch, }: {
69
+ options: ValidConfigOptions;
70
+ backportBranch: string;
71
+ }): Promise<{
72
+ cmdArgs: string[];
73
+ code: number | null;
74
+ stderr: string;
75
+ stdout: string;
76
+ }>;
77
+ export declare function getLocalSourceRepoPath(options: ValidConfigOptions): Promise<string | undefined>;