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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const child_process_promisified_1 = require("../../../services/child-process-promisified");
3
+ const child_process_promisified_1 = require("../../../lib/child-process-promisified");
4
4
  const getDevAccessToken_1 = require("../../private/getDevAccessToken");
5
5
  const sandbox_1 = require("../../sandbox");
6
6
  const runBackportViaCli_1 = require("./runBackportViaCli");
@@ -15,30 +15,42 @@ describe('test-that-repo-can-be-cloned', () => {
15
15
  function run() {
16
16
  return (0, runBackportViaCli_1.runBackportViaCli)([
17
17
  '--repo=backport-org/test-that-repo-can-be-cloned',
18
- '--branch=foo',
18
+ '--branch=production',
19
19
  '--pr=1',
20
20
  `--dir=${sandboxPath}`,
21
21
  '--dry-run',
22
22
  `--accessToken=${accessToken}`,
23
- ], { showOra: true, waitForString: 'Backporting to foo:' });
23
+ ], { showOra: true });
24
24
  }
25
25
  it('clones the repo remote repo', async () => {
26
- const output = await run();
26
+ const { output } = await run();
27
27
  expect(output).toContain('Cloning repository from github.com');
28
28
  expect(output).toMatchInlineSnapshot(`
29
29
  "- Initializing...
30
30
  ? Select pull request Beginning of a beautiful repo (#1)
31
31
  ✔ 100% Cloning repository from github.com (one-time operation)
32
- Backporting to foo:"
32
+
33
+ Backporting to production:
34
+ - Pulling latest changes
35
+ ✔ Pulling latest changes
36
+ - Cherry-picking: Beginning of a beautiful repo (#1)
37
+ ✔ Cherry-picking: Beginning of a beautiful repo (#1)
38
+ ✔ Dry run complete"
33
39
  `);
34
40
  });
35
41
  it('does not clone again on subsequent runs', async () => {
36
- const output = await run();
42
+ const { output } = await run();
37
43
  expect(output).not.toContain('Cloning repository from github.com');
38
44
  expect(output).toMatchInlineSnapshot(`
39
45
  "- Initializing...
40
46
  ? Select pull request Beginning of a beautiful repo (#1)
41
- Backporting to foo:"
47
+
48
+ Backporting to production:
49
+ - Pulling latest changes
50
+ ✔ Pulling latest changes
51
+ - Cherry-picking: Beginning of a beautiful repo (#1)
52
+ ✔ Cherry-picking: Beginning of a beautiful repo (#1)
53
+ ✔ Dry run complete"
42
54
  `);
43
55
  });
44
56
  });
@@ -54,19 +66,15 @@ describe('test-that-repo-can-be-cloned', () => {
54
66
  });
55
67
  function run() {
56
68
  return (0, runBackportViaCli_1.runBackportViaCli)([
57
- '--branch=foo',
69
+ '--branch=production',
58
70
  '--pr=1',
59
71
  `--dir=${backportRepo}`,
60
72
  '--dry-run',
61
73
  `--accessToken=${accessToken}`,
62
- ], {
63
- cwd: sourceRepo,
64
- showOra: true,
65
- waitForString: 'Backporting to foo:',
66
- });
74
+ ], { cwd: sourceRepo, showOra: true });
67
75
  }
68
76
  it('clones using the local repo', async () => {
69
- const output = await run();
77
+ const { output } = await run();
70
78
  expect(output).toEqual(expect.stringMatching(/100% Cloning repository from .*\/src\/test\/_tmp_sandbox_\/test-that-repo-can-be-cloned.private.test\/source \(one-time operation\)/gm));
71
79
  });
72
80
  });
@@ -0,0 +1,376 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const rest_1 = require("@octokit/rest");
4
+ const entrypoint_module_1 = require("../../../entrypoint.module");
5
+ const commitFormatters_1 = require("../../../lib/github/commitFormatters");
6
+ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
7
+ const sandbox_1 = require("../../sandbox");
8
+ jest.unmock('find-up');
9
+ jest.unmock('del');
10
+ jest.unmock('make-dir');
11
+ jest.setTimeout(10000);
12
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
13
+ const octokit = new rest_1.Octokit({ auth: accessToken });
14
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
15
+ // repo
16
+ const REPO_OWNER = 'backport-org';
17
+ const REPO_NAME = 'integration-test';
18
+ const AUTHOR = 'sqren';
19
+ // commit 1
20
+ const COMMIT_SHA_1 = '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad';
21
+ const BRANCH_WITH_ONE_COMMIT = `backport/7.x/commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_1)}`;
22
+ // commit 2
23
+ const COMMIT_SHA_2 = '59d6ff1ca90a4ce210c0a4f0e159214875c19d60';
24
+ const BRANCH_WITH_TWO_COMMITS = `backport/7.x/commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_1)}_commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_2)}`;
25
+ describe('entrypoint.module', () => {
26
+ describe('when a single commit is backported', () => {
27
+ let res;
28
+ let pullRequestResponse;
29
+ beforeAll(async () => {
30
+ await resetState(accessToken);
31
+ res = await (0, entrypoint_module_1.backportRun)({
32
+ options: {
33
+ dir: sandboxPath,
34
+ accessToken,
35
+ repoOwner: 'backport-org',
36
+ repoName: 'integration-test',
37
+ sha: COMMIT_SHA_1,
38
+ targetBranches: ['7.x'],
39
+ },
40
+ });
41
+ // @ts-expect-error
42
+ const pullRequestNumber = res.results[0].pullRequestNumber;
43
+ pullRequestResponse = await octokit.pulls.get({
44
+ owner: REPO_OWNER,
45
+ repo: REPO_NAME,
46
+ pull_number: pullRequestNumber,
47
+ });
48
+ });
49
+ it('returns the backport result', () => {
50
+ expect(res).toEqual({
51
+ commits: [
52
+ {
53
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
54
+ expectedTargetPullRequests: [],
55
+ sourceBranch: 'master',
56
+ sourceCommit: {
57
+ committedDate: '2020-08-15T10:37:41Z',
58
+ message: 'Add ❤️ emoji',
59
+ sha: COMMIT_SHA_1,
60
+ },
61
+ sourcePullRequest: undefined,
62
+ },
63
+ ],
64
+ results: [
65
+ {
66
+ didUpdate: false,
67
+ pullRequestNumber: expect.any(Number),
68
+ pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
69
+ status: 'success',
70
+ targetBranch: '7.x',
71
+ },
72
+ ],
73
+ status: 'success',
74
+ });
75
+ });
76
+ it('pull request: status code', async () => {
77
+ expect(pullRequestResponse.status).toEqual(200);
78
+ });
79
+ it('pull request: title', async () => {
80
+ expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji');
81
+ });
82
+ it('pull request: body', async () => {
83
+ expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
84
+ "# Backport
85
+
86
+ This will backport the following commits from \`master\` to \`7.x\`:
87
+ - Add ❤️ emoji (5bf29b7d)
88
+
89
+ <!--- Backport version: 1.2.3-mocked -->
90
+
91
+ ### Questions ?
92
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
93
+ `);
94
+ });
95
+ it('pull request: head branch is in fork repo', async () => {
96
+ expect(pullRequestResponse.data.head.label).toEqual(`sqren:${BRANCH_WITH_ONE_COMMIT}`);
97
+ });
98
+ it('pull request: base branch', async () => {
99
+ expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
100
+ });
101
+ it('does not create any new branches in origin (backport-org/integration-test)', async () => {
102
+ const branches = await getBranchesOnGithub({
103
+ accessToken,
104
+ repoOwner: REPO_OWNER,
105
+ repoName: REPO_NAME,
106
+ });
107
+ expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
108
+ });
109
+ it('creates a branch in the fork (sqren/integration-test)', async () => {
110
+ const branches = await getBranchesOnGithub({
111
+ accessToken,
112
+ repoOwner: AUTHOR,
113
+ repoName: REPO_NAME,
114
+ });
115
+ expect(branches.map((b) => b.name)).toEqual([
116
+ '7.x',
117
+ BRANCH_WITH_ONE_COMMIT,
118
+ 'master',
119
+ ]);
120
+ });
121
+ });
122
+ describe('when two commits are backported', () => {
123
+ let res;
124
+ let pullRequestResponse;
125
+ beforeAll(async () => {
126
+ await resetState(accessToken);
127
+ res = await (0, entrypoint_module_1.backportRun)({
128
+ options: {
129
+ dir: sandboxPath,
130
+ accessToken,
131
+ repoOwner: 'backport-org',
132
+ repoName: 'integration-test',
133
+ sha: [COMMIT_SHA_1, COMMIT_SHA_2],
134
+ targetBranches: ['7.x'],
135
+ },
136
+ });
137
+ // @ts-expect-error
138
+ const pullRequestNumber = res.results[0].pullRequestNumber;
139
+ pullRequestResponse = await octokit.pulls.get({
140
+ owner: REPO_OWNER,
141
+ repo: REPO_NAME,
142
+ pull_number: pullRequestNumber,
143
+ });
144
+ });
145
+ it('returns the backport result containing both commits', () => {
146
+ expect(res).toEqual({
147
+ commits: [
148
+ {
149
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
150
+ expectedTargetPullRequests: [],
151
+ sourceBranch: 'master',
152
+ sourceCommit: {
153
+ committedDate: '2020-08-15T10:37:41Z',
154
+ message: 'Add ❤️ emoji',
155
+ sha: COMMIT_SHA_1,
156
+ },
157
+ sourcePullRequest: undefined,
158
+ },
159
+ {
160
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
161
+ expectedTargetPullRequests: [],
162
+ sourceBranch: 'master',
163
+ sourceCommit: {
164
+ committedDate: '2020-08-15T10:44:04Z',
165
+ message: 'Add family emoji (#2)',
166
+ sha: COMMIT_SHA_2,
167
+ },
168
+ sourcePullRequest: undefined,
169
+ },
170
+ ],
171
+ results: [
172
+ {
173
+ didUpdate: false,
174
+ pullRequestNumber: expect.any(Number),
175
+ pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
176
+ status: 'success',
177
+ targetBranch: '7.x',
178
+ },
179
+ ],
180
+ status: 'success',
181
+ });
182
+ });
183
+ it('pull request: status code', async () => {
184
+ expect(pullRequestResponse.status).toEqual(200);
185
+ });
186
+ it('pull request: title', async () => {
187
+ expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji | Add family emoji (#2)');
188
+ });
189
+ it('pull request: body', async () => {
190
+ expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
191
+ "# Backport
192
+
193
+ This will backport the following commits from \`master\` to \`7.x\`:
194
+ - Add ❤️ emoji (5bf29b7d)
195
+ - Add family emoji (#2) (59d6ff1c)
196
+
197
+ <!--- Backport version: 1.2.3-mocked -->
198
+
199
+ ### Questions ?
200
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
201
+ `);
202
+ });
203
+ it('pull request: head branch contains both commits in name', async () => {
204
+ expect(pullRequestResponse.data.head.label).toEqual(`sqren:${BRANCH_WITH_TWO_COMMITS}`);
205
+ });
206
+ it('pull request: base branch', async () => {
207
+ expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
208
+ });
209
+ });
210
+ describe('when disabling fork mode', () => {
211
+ let res;
212
+ let pullRequestResponse;
213
+ beforeAll(async () => {
214
+ await resetState(accessToken);
215
+ res = await (0, entrypoint_module_1.backportRun)({
216
+ options: {
217
+ fork: false,
218
+ dir: sandboxPath,
219
+ accessToken,
220
+ repoOwner: 'backport-org',
221
+ repoName: 'integration-test',
222
+ sha: COMMIT_SHA_1,
223
+ targetBranches: ['7.x'],
224
+ },
225
+ });
226
+ // @ts-expect-error
227
+ const pullRequestNumber = res.results[0].pullRequestNumber;
228
+ pullRequestResponse = await octokit.pulls.get({
229
+ owner: REPO_OWNER,
230
+ repo: REPO_NAME,
231
+ pull_number: pullRequestNumber,
232
+ });
233
+ });
234
+ it('pull request: title', async () => {
235
+ expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji');
236
+ });
237
+ it('pull request: body', async () => {
238
+ expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
239
+ "# Backport
240
+
241
+ This will backport the following commits from \`master\` to \`7.x\`:
242
+ - Add ❤️ emoji (5bf29b7d)
243
+
244
+ <!--- Backport version: 1.2.3-mocked -->
245
+
246
+ ### Questions ?
247
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
248
+ `);
249
+ });
250
+ it('pull request: head branch is in origin (non-fork) repo', async () => {
251
+ expect(pullRequestResponse.data.head.label).toEqual(`backport-org:${BRANCH_WITH_ONE_COMMIT}`);
252
+ });
253
+ it('pull request: base branch', async () => {
254
+ expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
255
+ });
256
+ it('returns pull request', () => {
257
+ expect(res).toEqual({
258
+ commits: [
259
+ {
260
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
261
+ expectedTargetPullRequests: [],
262
+ sourceBranch: 'master',
263
+ sourceCommit: {
264
+ committedDate: '2020-08-15T10:37:41Z',
265
+ message: 'Add ❤️ emoji',
266
+ sha: COMMIT_SHA_1,
267
+ },
268
+ sourcePullRequest: undefined,
269
+ },
270
+ ],
271
+ results: [
272
+ {
273
+ didUpdate: false,
274
+ pullRequestNumber: expect.any(Number),
275
+ pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
276
+ status: 'success',
277
+ targetBranch: '7.x',
278
+ },
279
+ ],
280
+ status: 'success',
281
+ });
282
+ });
283
+ it('creates a new branch in origin (backport-org/integration-test)', async () => {
284
+ const branches = await getBranchesOnGithub({
285
+ accessToken,
286
+ repoOwner: REPO_OWNER,
287
+ repoName: REPO_NAME,
288
+ });
289
+ expect(branches.map((b) => b.name)).toEqual([
290
+ '7.x',
291
+ BRANCH_WITH_ONE_COMMIT,
292
+ 'master',
293
+ ]);
294
+ });
295
+ it('does not create branches in the fork (sqren/integration-test)', async () => {
296
+ const branches = await getBranchesOnGithub({
297
+ accessToken,
298
+ repoOwner: AUTHOR,
299
+ repoName: REPO_NAME,
300
+ });
301
+ expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
302
+ });
303
+ });
304
+ });
305
+ async function getBranchesOnGithub({ accessToken, repoOwner, repoName, }) {
306
+ // console.log(`fetch branches for ${repoOwner}`);
307
+ const octokit = new rest_1.Octokit({
308
+ auth: accessToken,
309
+ });
310
+ const res = await octokit.repos.listBranches({
311
+ owner: repoOwner,
312
+ repo: repoName,
313
+ });
314
+ return res.data;
315
+ }
316
+ async function deleteBranchOnGithub({ accessToken, repoOwner, repoName, branchName, }) {
317
+ try {
318
+ const octokit = new rest_1.Octokit({
319
+ auth: accessToken,
320
+ });
321
+ // console.log({ accessToken });
322
+ const opts = {
323
+ owner: repoOwner,
324
+ repo: repoName,
325
+ ref: `heads/${branchName}`,
326
+ };
327
+ const res = await octokit.git.deleteRef(opts);
328
+ // console.log(`Deleted ${repoOwner}:heads/${branchName}`);
329
+ return res.data;
330
+ }
331
+ catch (e) {
332
+ // console.log(
333
+ // `Could not delete ${repoOwner}:heads/${branchName} (${e.message})`
334
+ // );
335
+ //@ts-expect-error
336
+ if (e.message === 'Reference does not exist') {
337
+ return;
338
+ }
339
+ throw e;
340
+ }
341
+ }
342
+ async function resetState(accessToken) {
343
+ const ownerBranches = await getBranchesOnGithub({
344
+ accessToken,
345
+ repoOwner: REPO_OWNER,
346
+ repoName: REPO_NAME,
347
+ });
348
+ // delete all branches except master and 7.x
349
+ await Promise.all(ownerBranches
350
+ .filter((b) => b.name !== 'master' && b.name !== '7.x')
351
+ .map((b) => {
352
+ return deleteBranchOnGithub({
353
+ accessToken,
354
+ repoOwner: REPO_OWNER,
355
+ repoName: REPO_NAME,
356
+ branchName: b.name,
357
+ });
358
+ }));
359
+ const forkBranches = await getBranchesOnGithub({
360
+ accessToken,
361
+ repoOwner: AUTHOR,
362
+ repoName: REPO_NAME,
363
+ });
364
+ // delete all branches except master and 7.x
365
+ await Promise.all(forkBranches
366
+ .filter((b) => b.name !== 'master' && b.name !== '7.x')
367
+ .map((b) => {
368
+ return deleteBranchOnGithub({
369
+ accessToken,
370
+ repoOwner: AUTHOR,
371
+ repoName: REPO_NAME,
372
+ branchName: b.name,
373
+ });
374
+ }));
375
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
376
+ }
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const entrypoint_module_1 = require("../entrypoint.module");
4
4
  const getDevAccessToken_1 = require("./private/getDevAccessToken");
5
5
  const sandbox_1 = require("./sandbox");
6
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
6
7
  jest.unmock('find-up');
7
8
  jest.setTimeout(15000);
8
9
  describe('Handle unbackported pull requests', () => {
9
10
  it('shows missing backports for PR number 8', async () => {
10
- const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
11
11
  const commits = await (0, entrypoint_module_1.getCommits)({
12
12
  accessToken: accessToken,
13
13
  repoOwner: 'backport-org',
@@ -35,18 +35,20 @@ describe('Handle unbackported pull requests', () => {
35
35
  expect(commits[0]).toEqual(expectedCommit);
36
36
  });
37
37
  it('shows that backport failed because PR number 8 was not backported', async () => {
38
- const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
39
38
  const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
40
39
  await (0, sandbox_1.resetSandbox)(sandboxPath);
41
40
  const result = await (0, entrypoint_module_1.backportRun)({
42
- accessToken: accessToken,
43
- repoOwner: 'backport-org',
44
- repoName: 'repo-with-conflicts',
45
- pullNumber: 12,
46
- targetBranches: ['7.x'],
47
- dir: sandboxPath,
48
- ci: true,
49
- publishStatusComment: false,
41
+ options: {
42
+ accessToken: accessToken,
43
+ repoOwner: 'backport-org',
44
+ repoName: 'repo-with-conflicts',
45
+ pullNumber: 12,
46
+ targetBranches: ['7.x'],
47
+ dir: sandboxPath,
48
+ interactive: false,
49
+ publishStatusCommentOnSuccess: false,
50
+ publishStatusCommentOnFailure: false,
51
+ },
50
52
  });
51
53
  const commit =
52
54
  //@ts-expect-error
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -5,7 +5,11 @@
5
5
  */
6
6
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
7
  if (k2 === undefined) k2 = k;
8
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
9
13
  }) : (function(o, m, k, k2) {
10
14
  if (k2 === undefined) k2 = k;
11
15
  o[k2] = m[k];
@@ -43,21 +47,21 @@ jest.mock('del', () => {
43
47
  return jest.fn(async (path) => `Attempted to delete ${path}`);
44
48
  });
45
49
  (0, mocks_1.mockOra)();
46
- // silence logger
47
- jest.mock('../../services/logger', () => {
50
+ jest.mock('../../lib/logger', () => {
48
51
  const spy = jest.fn();
52
+ const logger = {
53
+ spy: spy,
54
+ info: (msg, meta) => spy(`[INFO] ${msg}`, meta),
55
+ verbose: (msg, meta) => spy(`[VERBOSE] ${msg}`, meta),
56
+ warn: (msg, meta) => spy(`[WARN] ${msg}`, meta),
57
+ error: (msg, meta) => spy(`[ERROR] ${msg}`, meta),
58
+ debug: (msg, meta) => spy(`[DEBUG] ${msg}`, meta),
59
+ };
49
60
  return {
50
- initLogger: jest.fn(),
61
+ initLogger: jest.fn(() => logger),
51
62
  redactAccessToken: jest.fn((str) => str),
52
63
  consoleLog: jest.fn(),
53
- updateLogger: jest.fn(),
54
- logger: {
55
- spy: spy,
56
- info: (msg, meta) => spy(`[INFO] ${msg}`, meta),
57
- verbose: (msg, meta) => spy(`[VERBOSE] ${msg}`, meta),
58
- warn: (msg, meta) => spy(`[WARN] ${msg}`, meta),
59
- error: (msg, meta) => spy(`[ERROR] ${msg}`, meta),
60
- debug: (msg, meta) => spy(`[DEBUG] ${msg}`, meta),
61
- },
64
+ setAccessToken: jest.fn(),
65
+ logger,
62
66
  };
63
67
  });
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.cherrypickAndCreateTargetPullRequest = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const lodash_1 = require("lodash");
9
- const HandledError_1 = require("../services/HandledError");
9
+ const BackportError_1 = require("../services/BackportError");
10
10
  const child_process_promisified_1 = require("../services/child-process-promisified");
11
11
  const env_1 = require("../services/env");
12
12
  const git_1 = require("../services/git");
@@ -140,16 +140,20 @@ async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor)
140
140
  }
141
141
  autoResolveSpinner.fail();
142
142
  }
143
+ const conflictingFilesRelative = conflictingFiles
144
+ .map((f) => f.relative)
145
+ .slice(0, 50);
143
146
  const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
144
147
  options,
145
148
  commit,
146
149
  targetBranch,
147
- conflictingFiles: conflictingFiles.map((f) => f.relative).slice(0, 50),
150
+ conflictingFiles: conflictingFilesRelative,
148
151
  });
149
152
  if (options.ci) {
150
- throw new HandledError_1.HandledError({
153
+ throw new BackportError_1.BackportError({
151
154
  code: 'merge-conflict-exception',
152
155
  commitsWithoutBackports,
156
+ conflictingFiles: conflictingFilesRelative,
153
157
  });
154
158
  }
155
159
  (0, logger_1.consoleLog)(chalk_1.default.bold('\nThe commit could not be backported due to conflicts\n'));
@@ -162,7 +166,7 @@ async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor)
162
166
  * Commit could not be cleanly cherrypicked: Initiating conflict resolution
163
167
  */
164
168
  if (options.editor) {
165
- await (0, child_process_promisified_1.exec)(`${options.editor} ${repoPath}`, { cwd: options.cwd });
169
+ await (0, child_process_promisified_1.spawnPromise)(options.editor, [repoPath], options.cwd);
166
170
  }
167
171
  // list files with conflict markers + unstaged files and require user to resolve them
168
172
  await listConflictingAndUnstagedFiles({
@@ -201,14 +205,14 @@ async function listConflictingAndUnstagedFiles({ retries, options, conflictingFi
201
205
  const unstagedSection = hasUnstagedFiles
202
206
  ? `Unstaged files:\n${chalk_1.default.reset(unstagedFiles.map((file) => ` - ${file}`).join('\n'))}`
203
207
  : '';
204
- const res = await (0, prompts_1.confirmPrompt)(`${header}
208
+ const didConfirm = await (0, prompts_1.confirmPrompt)(`${header}
205
209
 
206
210
  ${conflictSection}
207
211
  ${unstagedSection}
208
212
 
209
213
  Press ENTER when the conflicts are resolved and files are staged`);
210
- if (!res) {
211
- throw new HandledError_1.HandledError({ code: 'abort-exception' });
214
+ if (!didConfirm) {
215
+ throw new BackportError_1.BackportError({ code: 'abort-exception' });
212
216
  }
213
217
  const MAX_RETRIES = 100;
214
218
  if (retries++ > MAX_RETRIES) {