backport 8.0.0 → 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 (205) hide show
  1. package/README.md +4 -4
  2. package/dist/backportRun.d.ts +5 -4
  3. package/dist/backportRun.js +41 -42
  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 +4 -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 +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 +4 -2
  151. package/dist/options/cliArgs.d.ts +15 -12
  152. package/dist/options/cliArgs.js +34 -19
  153. package/dist/options/cliArgs.test.js +125 -1
  154. package/dist/options/config/config.d.ts +5 -4
  155. package/dist/options/config/config.js +3 -5
  156. package/dist/options/config/config.test.js +0 -1
  157. package/dist/options/config/globalConfig.d.ts +3 -1
  158. package/dist/options/config/globalConfig.js +5 -5
  159. package/dist/options/config/readConfigFile.d.ts +9 -7
  160. package/dist/options/config/readConfigFile.js +2 -2
  161. package/dist/options/options.d.ts +43 -7
  162. package/dist/options/options.js +20 -24
  163. package/dist/options/options.test.js +112 -54
  164. package/dist/runSequentially.d.ts +10 -7
  165. package/dist/runSequentially.js +5 -5
  166. package/dist/scripts/postinstall.js +3 -3
  167. package/dist/scripts/postinstall.test.js +1 -1
  168. package/dist/services/BackportError.d.ts +19 -0
  169. package/dist/services/BackportError.js +29 -0
  170. package/dist/services/HandledBackportError.d.ts +19 -0
  171. package/dist/services/HandledBackportError.js +29 -0
  172. package/dist/services/HandledError.d.ts +1 -1
  173. package/dist/services/HandledError.js +5 -5
  174. package/dist/services/git.js +7 -7
  175. package/dist/services/github/v3/createPullRequest.js +2 -2
  176. package/dist/services/github/v3/createStatusComment.js +2 -2
  177. package/dist/services/github/v3/createStatusComment.test.js +5 -4
  178. package/dist/services/github/v4/apiRequestV4.js +2 -2
  179. package/dist/services/github/v4/apiRequestV4.test.js +2 -2
  180. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +3 -3
  181. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
  182. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +3 -3
  183. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +2 -2
  184. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
  185. package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
  186. package/dist/state.d.ts +0 -0
  187. package/dist/state.js +1 -0
  188. package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
  189. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +26 -24
  190. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +189 -140
  191. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +12 -14
  192. package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -2
  193. package/dist/test/e2e/cli/runBackportViaCli.js +42 -29
  194. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
  195. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +2 -2
  196. package/dist/test/handleUnbackportedPullRequests.private.test.js +3 -2
  197. package/dist/test/setupFiles/automatic-mocks.js +1 -1
  198. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
  199. package/dist/ui/getCommits.js +2 -2
  200. package/dist/ui/getTargetBranches.js +3 -3
  201. package/dist/ui/setupRepo.js +2 -2
  202. package/dist/utils/packageVersion.d.ts +1 -1
  203. package/dist/utils/packageVersion.js +1 -1
  204. package/package.json +12 -12
  205. package/yarn.lock +112 -65
@@ -22,37 +22,41 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
- const child_process_promisified_1 = require("../../../services/child-process-promisified");
27
- const env_1 = require("../../../services/env");
29
+ const promises_1 = __importDefault(require("fs/promises"));
30
+ const path_1 = __importDefault(require("path"));
31
+ const child_process_promisified_1 = require("../../../lib/child-process-promisified");
28
32
  const packageVersion = __importStar(require("../../../utils/packageVersion"));
29
33
  const getDevAccessToken_1 = require("../../private/getDevAccessToken");
30
34
  const sandbox_1 = require("../../sandbox");
31
35
  const runBackportViaCli_1 = require("./runBackportViaCli");
32
- const TIMEOUT_IN_SECONDS = 15;
33
- jest.setTimeout(TIMEOUT_IN_SECONDS * 1000);
36
+ jest.setTimeout(10000);
34
37
  const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
35
38
  describe('entrypoint cli', () => {
36
39
  it('--version', async () => {
37
- const res = await (0, runBackportViaCli_1.runBackportViaCli)([`--version`], {
40
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`--version`], {
38
41
  showOra: true,
39
42
  });
40
- expect(res).toEqual(process.env.npm_package_version);
43
+ expect(output).toEqual(process.env.npm_package_version);
41
44
  });
42
45
  it('-v', async () => {
43
- const res = await (0, runBackportViaCli_1.runBackportViaCli)([`-v`], {
46
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`-v`], {
44
47
  showOra: true,
45
48
  });
46
- expect(res).toEqual(process.env.npm_package_version);
49
+ expect(output).toEqual(process.env.npm_package_version);
47
50
  });
48
51
  it('PACKAGE_VERSION should match', async () => {
49
52
  // @ts-expect-error
50
53
  expect(packageVersion.UNMOCKED_PACKAGE_VERSION).toBe(process.env.npm_package_version);
51
54
  });
52
55
  it('--help', async () => {
53
- const res = await (0, runBackportViaCli_1.runBackportViaCli)([`--help`]);
54
- expect(res).toMatchInlineSnapshot(`
56
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`--help`]);
57
+ expect(output).toMatchInlineSnapshot(`
55
58
  "entrypoint.cli.ts [args]
59
+
56
60
  Options:
57
61
  -v, --version Show version number [boolean]
58
62
  --accessToken, --accesstoken Github access token [string]
@@ -62,10 +66,10 @@ describe('entrypoint cli', () => {
62
66
  --autoMerge Enable auto-merge for created pull requests [boolean]
63
67
  --autoMergeMethod Sets auto-merge method when using --auto-merge. Default:
64
68
  merge [string] [choices: \\"merge\\", \\"rebase\\", \\"squash\\"]
65
- --ci Disable interactive prompts [boolean]
66
69
  --cherrypickRef Append commit message with \\"(cherry picked from commit...)
67
70
  [boolean]
68
71
  --projectConfigFile, --config Path to project config [string]
72
+ --globalConfigFile Path to global config [string]
69
73
  --since ISO-8601 date for filtering commits [string]
70
74
  --until ISO-8601 date for filtering commits [string]
71
75
  --dir Path to temporary backport repo [string]
@@ -78,6 +82,8 @@ describe('entrypoint cli', () => {
78
82
  [boolean]
79
83
  --gitAuthorName Set commit author name [string]
80
84
  --gitAuthorEmail Set commit author email [string]
85
+ --nonInteractive, --json Disable interactive prompts and return response as JSON
86
+ [boolean]
81
87
  --ls List commits instead of backporting them [boolean]
82
88
  --mainline Parent id of merge commit. Defaults to 1 when supplied
83
89
  without arguments [number]
@@ -112,102 +118,36 @@ describe('entrypoint cli', () => {
112
118
  -l, --targetPRLabel, --label Add labels to the target (backport) PR [array]
113
119
  --verify Opposite of no-verify [boolean]
114
120
  --help Show help [boolean]
121
+
115
122
  For bugs, feature requests or questions: https://github.com/sqren/backport/issues
116
123
  Or contact me directly: https://twitter.com/sorenlouv"
117
124
  `);
118
125
  });
119
- it('should output error when branch is missing', async () => {
120
- const res = await (0, runBackportViaCli_1.runBackportViaCli)([
121
- '--skip-remote-config',
122
- '--repo=backport-org/backport-e2e',
123
- `--accessToken=${accessToken}`,
124
- ]);
125
- expect(res).toMatchInlineSnapshot(`
126
- "Please specify a target branch: \\"--branch 6.1\\".
127
- Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
128
- `);
129
- });
130
- it('should output error when access token is invalid', async () => {
131
- const res = await (0, runBackportViaCli_1.runBackportViaCli)([
132
- '--branch=foo',
133
- '--repo=foo/bar',
134
- '--accessToken=some-token',
135
- ]);
136
- expect(res).toContain('Please check your access token and make sure it is valid');
137
- });
138
126
  it('should list commits based on .git/config when `repoOwner`/`repoName` is missing', async () => {
139
127
  const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
140
128
  await (0, sandbox_1.resetSandbox)(sandboxPath);
141
129
  await (0, child_process_promisified_1.exec)(`git init`, { cwd: sandboxPath });
142
130
  await (0, child_process_promisified_1.exec)(`git remote add origin git@github.com:backport-org/backport-e2e.git`, { cwd: sandboxPath });
143
- const res = await (0, runBackportViaCli_1.runBackportViaCli)([`--accessToken=${accessToken}`], {
131
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`--accessToken=${accessToken}`], {
144
132
  cwd: sandboxPath,
145
133
  waitForString: 'Select commit',
146
134
  });
147
- expect(res).toMatchInlineSnapshot(`
135
+ expect(output).toMatchInlineSnapshot(`
148
136
  "? Select commit (Use arrow keys)
149
- ❯ 1. Add sheep emoji (#9) 7.8
150
- 2. Change Ulysses to Gretha (conflict) (#8) 7.x
151
- 3. Add 🍏 emoji (#5) 7.x, 7.8
152
- 4. Add family emoji (#2) 7.x
153
- 5. Add \`backport\` dep
154
- 6. Merge pull request #1 from backport-org/add-heart-emoji
155
- 7. Add ❤️ emoji
156
- 8. Update .backportrc.json
157
- 9. Bump to 8.0.0
137
+ ❯ 1. Add sheep emoji (#9) 7.8
138
+ 2. Change Ulysses to Gretha (conflict) (#8) 7.x
139
+ 3. Add 🍏 emoji (#5) 7.x, 7.8
140
+ 4. Add family emoji (#2) 7.x
141
+ 5. Add \`backport\` dep
142
+ 6. Merge pull request #1 from backport-org/add-heart-emoji
143
+ 7. Add ❤️ emoji
144
+ 8. Update .backportrc.json
145
+ 9. Bump to 8.0.0
158
146
  10.Add package.json"
159
147
  `);
160
148
  });
161
- it(`should output error when repo doesn't exist`, async () => {
162
- const res = await (0, runBackportViaCli_1.runBackportViaCli)([
163
- '--branch=foo',
164
- '--repo=foo/bar',
165
- '--author=sqren',
166
- `--accessToken=${accessToken}`,
167
- ]);
168
- expect(res).toMatchInlineSnapshot(`"The repository \\"foo/bar\\" doesn't exist"`);
169
- });
170
- it(`should output error when given branch is invalid`, async () => {
171
- const res = await (0, runBackportViaCli_1.runBackportViaCli)([
172
- '--branch=foo',
173
- '--repo=backport-org/backport-e2e',
174
- '--pr=9',
175
- `--accessToken=${accessToken}`,
176
- ], { waitForString: "is invalid or doesn't exist" });
177
- expect(res).toMatchInlineSnapshot(`
178
- "
179
- Backporting to foo:
180
- The branch \\"foo\\" is invalid or doesn't exist"
181
- `);
182
- });
183
- it(`should output merge conflict`, async () => {
184
- const res = await (0, runBackportViaCli_1.runBackportViaCli)([
185
- '--repo=backport-org/repo-with-conflicts',
186
- '--pr=12',
187
- '--branch=7.x',
188
- `--accessToken=${accessToken}`,
189
- '--dry-run',
190
- ], {
191
- waitForString: 'Press ENTER when the conflicts',
192
- });
193
- const backportDir = (0, env_1.getBackportDirPath)();
194
- expect(res.replaceAll(backportDir, '<HOMEDIR>')).toMatchInlineSnapshot(`
195
- "
196
- Backporting to 7.x:
197
- The commit could not be backported due to conflicts
198
- Please fix the conflicts in <HOMEDIR>/repositories/backport-org/repo-with-conflicts
199
- Hint: Before fixing the conflicts manually you should consider backporting the following pull requests to \\"7.x\\":
200
- - Change Barca to Braithwaite (#8) (backport missing)
201
- https://github.com/backport-org/repo-with-conflicts/pull/8
202
- ? Fix the following conflicts manually:
203
- Conflicting files:
204
- - <HOMEDIR>/repositories/backport-org/repo-with-conflicts/la-liga.
205
- md
206
- Press ENTER when the conflicts are resolved and files are staged (Y/n)"
207
- `);
208
- });
209
149
  it(`should list commits from master`, async () => {
210
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
150
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
211
151
  '--branch=foo',
212
152
  '--repo=backport-org/backport-e2e',
213
153
  '--author=sqren',
@@ -216,16 +156,16 @@ describe('entrypoint cli', () => {
216
156
  ], { waitForString: 'Select commit' });
217
157
  expect(output).toMatchInlineSnapshot(`
218
158
  "? Select commit (Use arrow keys)
219
- ❯ 1. Add sheep emoji (#9) 7.8
220
- 2. Change Ulysses to Gretha (conflict) (#8) 7.x
221
- 3. Add 🍏 emoji (#5) 7.x, 7.8
222
- 4. Add family emoji (#2) 7.x
223
- 5. Add \`backport\` dep
159
+ ❯ 1. Add sheep emoji (#9) 7.8
160
+ 2. Change Ulysses to Gretha (conflict) (#8) 7.x
161
+ 3. Add 🍏 emoji (#5) 7.x, 7.8
162
+ 4. Add family emoji (#2) 7.x
163
+ 5. Add \`backport\` dep
224
164
  6. Merge pull request #1 from backport-org/add-heart-emoji"
225
165
  `);
226
166
  });
227
167
  it(`should filter commits by "since" and "until"`, async () => {
228
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
168
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
229
169
  '--branch=foo',
230
170
  '--repo=backport-org/backport-e2e',
231
171
  `--accessToken=${accessToken}`,
@@ -234,14 +174,14 @@ describe('entrypoint cli', () => {
234
174
  ], { waitForString: 'Select commit' });
235
175
  expect(output).toMatchInlineSnapshot(`
236
176
  "? Select commit (Use arrow keys)
237
- ❯ 1. Bump to 8.0.0
238
- 2. Add package.json
239
- 3. Update .backportrc.json
177
+ ❯ 1. Bump to 8.0.0
178
+ 2. Add package.json
179
+ 3. Update .backportrc.json
240
180
  4. Create .backportrc.json"
241
181
  `);
242
182
  });
243
183
  it(`should list commits from 7.x`, async () => {
244
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
184
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
245
185
  '--branch=foo',
246
186
  '--repo=backport-org/backport-e2e',
247
187
  '--author=sqren',
@@ -251,31 +191,154 @@ describe('entrypoint cli', () => {
251
191
  ], { waitForString: 'Select commit' });
252
192
  expect(output).toMatchInlineSnapshot(`
253
193
  "? Select commit (Use arrow keys)
254
- ❯ 1. Add 🍏 emoji (#5) (#6)
255
- 2. Change Ulysses to Carol
256
- 3. Add family emoji (#2) (#4)
257
- 4. Update .backportrc.json
258
- 5. Branch off: 7.9.0 (7.x)
194
+ ❯ 1. Add 🍏 emoji (#5) (#6)
195
+ 2. Change Ulysses to Carol
196
+ 3. Add family emoji (#2) (#4)
197
+ 4. Update .backportrc.json
198
+ 5. Branch off: 7.9.0 (7.x)
259
199
  6. Bump to 8.0.0"
260
200
  `);
261
201
  });
262
- describe('ci failure cases', () => {
202
+ async function createConfigFile(options) {
203
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
204
+ const configPath = path_1.default.join(sandboxPath, 'config.json');
205
+ await promises_1.default.writeFile(configPath, JSON.stringify(options));
206
+ return configPath;
207
+ }
208
+ describe('errors in interactive mode (non-json)', () => {
209
+ it('when branch is missing', async () => {
210
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
211
+ '--skip-remote-config',
212
+ '--repo=backport-org/backport-e2e',
213
+ `--accessToken=${accessToken}`,
214
+ ]);
215
+ expect(output).toMatchInlineSnapshot(`
216
+ "Please specify a target branch: \\"--branch 6.1\\".
217
+
218
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
219
+ `);
220
+ });
221
+ it('when supplying invalid argument', async () => {
222
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`--foo`]);
223
+ expect(output).toMatchInlineSnapshot(`
224
+ "Unknown argument: foo
225
+ Run \\"backport --help\\" to see all options"
226
+ `);
227
+ });
228
+ it('when access token is invalid', async () => {
229
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
230
+ '--branch=foo',
231
+ '--repo=foo/bar',
232
+ '--accessToken=some-token',
233
+ ]);
234
+ expect(output).toContain('Please check your access token and make sure it is valid');
235
+ });
236
+ it(`should output error when repo doesn't exist`, async () => {
237
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
238
+ '--branch=foo',
239
+ '--repo=foo/bar',
240
+ '--author=sqren',
241
+ `--accessToken=${accessToken}`,
242
+ ]);
243
+ expect(output).toMatchInlineSnapshot(`"The repository \\"foo/bar\\" doesn't exist"`);
244
+ });
245
+ it(`should output error when given branch is invalid`, async () => {
246
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
247
+ '--branch=foo',
248
+ '--repo=backport-org/backport-e2e',
249
+ '--pr=9',
250
+ `--accessToken=${accessToken}`,
251
+ ]);
252
+ expect(output).toMatchInlineSnapshot(`
253
+ "Backporting to foo:
254
+ The branch \\"foo\\" is invalid or doesn't exist"
255
+ `);
256
+ });
257
+ it(`should output merge conflict`, async () => {
258
+ const backportDir = (0, sandbox_1.getSandboxPath)({ filename: __filename });
259
+ await (0, sandbox_1.resetSandbox)(backportDir);
260
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
261
+ '--repo=backport-org/repo-with-conflicts',
262
+ '--pr=12',
263
+ '--branch=7.x',
264
+ `--accessToken=${accessToken}`,
265
+ `--dir=${backportDir}`,
266
+ '--dry-run',
267
+ ], {
268
+ waitForString: 'Press ENTER when the conflicts',
269
+ timeoutSeconds: 5,
270
+ });
271
+ // //@ts-expect-error
272
+ // const lineToReplace = output.match(
273
+ // /Conflicting files:[\s]+- (.*[\s].*)la-liga.md/
274
+ // )[1];
275
+ // const lineWithoutBreaks = lineToReplace.replace(/\s/g, '');
276
+ // const outputReplaced = output
277
+ // .replace(lineToReplace, lineWithoutBreaks)
278
+ // .replaceAll(backportDir, '<BACKPORT_DIR>');
279
+ const outputReplaced = output
280
+ .replaceAll('\n', '')
281
+ .replaceAll(backportDir, '<BACKPORT_DIR>');
282
+ expect(outputReplaced).toMatchInlineSnapshot(`"Backporting to 7.x:The commit could not be backported due to conflictsPlease fix the conflicts in <BACKPORT_DIR>Hint: Before fixing the conflicts manually you should consider backporting the following pull requests to \\"7.x\\": - Change Barca to Braithwaite (#8) (backport missing) https://github.com/backport-org/repo-with-conflicts/pull/8? Fix the following conflicts manually:Conflicting files: - <BACKPORT_DIR>/la-liga.mdPress ENTER when the conflicts are resolved and files are staged (Y/n)"`);
283
+ });
284
+ });
285
+ describe('failure cases in json mode (and non-interactive)', () => {
263
286
  it(`when access token is missing`, async () => {
264
- const output = await (0, runBackportViaCli_1.runBackportViaCli)(['--ci']);
287
+ const configFilePath = await createConfigFile({});
288
+ const { output, code } = await (0, runBackportViaCli_1.runBackportViaCli)([
289
+ '--json',
290
+ `--globalConfigFile=${configFilePath}`,
291
+ ]);
292
+ const backportResult = JSON.parse(output);
293
+ expect(code).toBe(1);
294
+ expect(backportResult.status).toBe('failure');
295
+ expect(backportResult.errorMessage.replace(configFilePath, '<GLOBAL_CONFIG_FILE>')).toMatchInlineSnapshot(`
296
+ "Please update your config file: \\"<GLOBAL_CONFIG_FILE>\\".
297
+ It must contain a valid \\"accessToken\\".
298
+
299
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson"
300
+ `);
301
+ });
302
+ it('when target branches cannot be inferred from pull request', async () => {
303
+ const { output, code } = await (0, runBackportViaCli_1.runBackportViaCli)([
304
+ '--json',
305
+ '--repo=backport-org/backport-e2e',
306
+ '--pr=9',
307
+ `--accessToken=${accessToken}`,
308
+ ]);
309
+ expect(code).toBe(0);
310
+ const backportResult = JSON.parse(output);
311
+ expect(backportResult.status).toBe('aborted');
312
+ expect(backportResult.error).toEqual({
313
+ errorContext: { code: 'no-branches-exception' },
314
+ name: 'BackportError',
315
+ });
316
+ expect(backportResult.errorMessage).toBe('There are no branches to backport to. Aborting.');
317
+ });
318
+ it(`when target branch and branch label mapping are missing`, async () => {
319
+ const { output, code } = await (0, runBackportViaCli_1.runBackportViaCli)([
320
+ '--json',
321
+ `--access-token=${accessToken}`,
322
+ ]);
323
+ expect(code).toBe(1);
265
324
  const backportResult = JSON.parse(output);
266
325
  expect(backportResult.status).toBe('failure');
267
- expect(backportResult.errorMessage).toEqual('Access token missing. It must be explicitly supplied when using "--ci" option. Example: --access-token very-secret');
326
+ expect(backportResult.errorMessage).toMatchInlineSnapshot(`
327
+ "Please specify a target branch: \\"--branch 6.1\\".
328
+
329
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
330
+ `);
268
331
  });
269
332
  it(`when argument is invalid`, async () => {
270
- const output = await (0, runBackportViaCli_1.runBackportViaCli)(['--ci', '--foo']);
333
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)(['--json', '--foo'], {});
271
334
  const backportResult = JSON.parse(output);
272
335
  expect(backportResult.status).toBe('failure');
273
336
  expect(backportResult.errorMessage).toEqual('Unknown argument: foo');
274
337
  });
275
338
  it('when `--repo` is invalid', async () => {
276
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
339
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
340
+ '--json',
277
341
  '--repo=backport-org/backport-e2e-foo',
278
- '--ci',
279
342
  `--accessToken=${accessToken}`,
280
343
  ]);
281
344
  const backportResult = JSON.parse(output);
@@ -283,10 +346,10 @@ describe('entrypoint cli', () => {
283
346
  expect(backportResult.errorMessage).toEqual('The repository "backport-org/backport-e2e-foo" doesn\'t exist');
284
347
  });
285
348
  it('when `--sha` is invalid', async () => {
286
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
349
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
350
+ '--json',
287
351
  '--repo=backport-org/backport-e2e',
288
352
  '--sha=abcdefg',
289
- '--ci',
290
353
  `--accessToken=${accessToken}`,
291
354
  ]);
292
355
  const backportResult = JSON.parse(output);
@@ -294,11 +357,11 @@ describe('entrypoint cli', () => {
294
357
  expect(backportResult.errorMessage).toEqual('No commit found on branch "master" with sha "abcdefg"');
295
358
  });
296
359
  it('when `--branch` is invalid', async () => {
297
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
360
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
361
+ '--json',
298
362
  '--repo=backport-org/backport-e2e',
299
363
  '--pr=9',
300
364
  '--branch=foobar',
301
- '--ci',
302
365
  `--accessToken=${accessToken}`,
303
366
  ]);
304
367
  const backportResult = JSON.parse(output);
@@ -309,30 +372,30 @@ describe('entrypoint cli', () => {
309
372
  code: 'message-only-exception',
310
373
  message: 'The branch "foobar" is invalid or doesn\'t exist',
311
374
  },
312
- name: 'HandledError',
375
+ name: 'BackportError',
313
376
  },
314
377
  status: 'handled-error',
315
378
  targetBranch: 'foobar',
316
379
  });
317
380
  });
318
381
  it('when `--pr` is invalid', async () => {
319
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
382
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
383
+ '--json',
320
384
  '--repo=backport-org/backport-e2e',
321
385
  '--pr=900',
322
386
  '--branch=foobar',
323
- '--ci',
324
387
  `--accessToken=${accessToken}`,
325
388
  ]);
326
389
  const backportResult = JSON.parse(output);
327
390
  expect(backportResult.status).toEqual('failure');
328
391
  expect(backportResult.errorMessage).toEqual('Could not resolve to a PullRequest with the number of 900. (Github API v4)');
329
392
  });
330
- it('when having conflicts', async () => {
331
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
393
+ it('when having conflicts in non-interactive mode', async () => {
394
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
395
+ '--json',
332
396
  '--repo=backport-org/repo-with-conflicts',
333
397
  '--pr=12',
334
398
  '--branch=7.x',
335
- '--ci',
336
399
  `--accessToken=${accessToken}`,
337
400
  ]);
338
401
  const backportResult = JSON.parse(output);
@@ -342,12 +405,12 @@ describe('entrypoint cli', () => {
342
405
  backportResult.results[0].error.errorContext.conflictingFiles).toEqual(['la-liga.md']);
343
406
  });
344
407
  it('when `--source-branch` is invalid', async () => {
345
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
408
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
409
+ '--json',
346
410
  '--repo=backport-org/backport-e2e',
347
411
  '--pr=9',
348
412
  '--branch=7.x',
349
413
  '--source-branch=foo',
350
- '--ci',
351
414
  `--accessToken=${accessToken}`,
352
415
  ]);
353
416
  const backportResult = JSON.parse(output);
@@ -367,10 +430,10 @@ describe('entrypoint cli', () => {
367
430
  });
368
431
  });
369
432
  it('when PR is not merged', async () => {
370
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
433
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
434
+ '--json',
371
435
  '--repo=backport-org/backport-e2e',
372
436
  '--pr=12',
373
- '--ci',
374
437
  `--accessToken=${accessToken}`,
375
438
  ]);
376
439
  const backportResult = JSON.parse(output);
@@ -380,21 +443,7 @@ describe('entrypoint cli', () => {
380
443
  code: 'message-only-exception',
381
444
  message: 'The PR #12 is not merged',
382
445
  },
383
- name: 'HandledError',
384
- });
385
- });
386
- it('when target branch is missing', async () => {
387
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
388
- '--repo=backport-org/backport-e2e',
389
- '--pr=9',
390
- '--ci',
391
- `--accessToken=${accessToken}`,
392
- ]);
393
- const backportResult = JSON.parse(output);
394
- expect(backportResult.status).toBe('aborted');
395
- expect(backportResult.error).toEqual({
396
- errorContext: { code: 'no-branches-exception' },
397
- name: 'HandledError',
446
+ name: 'BackportError',
398
447
  });
399
448
  });
400
449
  });
@@ -5,44 +5,42 @@ const runBackportViaCli_1 = require("./runBackportViaCli");
5
5
  const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
6
6
  describe('repo-with-backportrc-removed (missing .backportrc.json config file)', () => {
7
7
  it('lists commits', async () => {
8
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
8
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
9
9
  '--branch=foo',
10
10
  '--repo=backport-org/repo-with-backportrc-removed',
11
11
  `--accessToken=${accessToken}`,
12
12
  ], { waitForString: 'Select commit' });
13
13
  expect(output).toMatchInlineSnapshot(`
14
- "? Select commit (Use arrow keys)
15
- ❯ 1. Rename README.me to README.md
16
- 2. Merge pull request #1 from backport-org/add-readme
17
- 3. Create README.me
18
- 4. Delete .backportrc.json
19
- 5. Create .backportrc.json
20
- 6. Delete .backportrc.json
21
- 7. Create .backportrc.json"
22
- `);
14
+ "? Select commit (Use arrow keys)
15
+ ❯ 1. Rename README.me to README.md
16
+ 2. Merge pull request #1 from backport-org/add-readme
17
+ 3. Create README.me
18
+ 4. Delete .backportrc.json
19
+ 5. Create .backportrc.json
20
+ 6. Delete .backportrc.json
21
+ 7. Create .backportrc.json"
22
+ `);
23
23
  });
24
24
  it('backports via pr', async () => {
25
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
25
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
26
26
  '--branch=production',
27
27
  '--repo=backport-org/repo-with-backportrc-removed',
28
28
  '--pr=1',
29
29
  `--accessToken=${accessToken}`,
30
30
  '--dry-run',
31
31
  ], {
32
- waitForString: `Dry run complete`,
33
32
  showOra: true,
34
33
  });
35
34
  expect(output).toContain('Cherry-picking: Merge pull request #1 from backport-org/add-readme');
36
35
  });
37
36
  it('backport by commit sha', async () => {
38
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
37
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
39
38
  '--branch=production',
40
39
  '--repo=backport-org/repo-with-backportrc-removed',
41
40
  '--sha=be59df6912a550c8cb49ba3e18be3e512f3d608c',
42
41
  `--accessToken=${accessToken}`,
43
42
  '--dry-run',
44
43
  ], {
45
- waitForString: `Dry run complete`,
46
44
  showOra: true,
47
45
  });
48
46
  expect(output).toContain('Cherry-picking: Create README.me');
@@ -1,6 +1,9 @@
1
- export declare function runBackportViaCli(cliArgs: string[], { timeoutSeconds, showOra, waitForString, cwd, }?: {
1
+ export declare function runBackportViaCli(backportArgs: string[], { timeoutSeconds, showOra, waitForString, cwd, }?: {
2
2
  timeoutSeconds?: number;
3
3
  showOra?: boolean;
4
4
  waitForString?: string;
5
5
  cwd?: string;
6
- }): Promise<string>;
6
+ }): Promise<{
7
+ output: string;
8
+ code: number | null;
9
+ }>;