backport 8.0.0 → 8.3.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/README.md +4 -4
  2. package/dist/backportRun.d.ts +5 -4
  3. package/dist/backportRun.js +42 -48
  4. package/dist/entrypoint.cli.js +3 -7
  5. package/dist/entrypoint.module.d.ts +7 -5
  6. package/dist/entrypoint.module.js +11 -9
  7. package/dist/entrypoint.module.private.test.js +25 -4
  8. package/dist/errors/BackportError.d.ts +19 -0
  9. package/dist/errors/BackportError.js +29 -0
  10. package/dist/lib/BackportError.d.ts +19 -0
  11. package/dist/lib/BackportError.js +29 -0
  12. package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +11 -0
  13. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +242 -0
  14. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  15. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +321 -0
  16. package/dist/lib/child-process-promisified.d.ts +25 -0
  17. package/dist/lib/child-process-promisified.js +60 -0
  18. package/dist/lib/env.d.ts +9 -0
  19. package/dist/lib/env.js +33 -0
  20. package/dist/lib/env.test.d.ts +1 -0
  21. package/dist/lib/env.test.js +26 -0
  22. package/dist/lib/getCommits.d.ts +2 -0
  23. package/dist/lib/getCommits.js +75 -0
  24. package/dist/lib/getCommitsWithoutBackports.d.ts +11 -0
  25. package/dist/lib/getCommitsWithoutBackports.js +68 -0
  26. package/dist/lib/getCommitsWithoutBackports.test.d.ts +1 -0
  27. package/dist/lib/getCommitsWithoutBackports.test.js +335 -0
  28. package/dist/lib/getGitConfigAuthor.d.ts +6 -0
  29. package/dist/lib/getGitConfigAuthor.js +15 -0
  30. package/dist/lib/getTargetBranches.d.ts +5 -0
  31. package/dist/lib/getTargetBranches.js +67 -0
  32. package/dist/lib/getTargetBranches.test.d.ts +1 -0
  33. package/dist/lib/getTargetBranches.test.js +210 -0
  34. package/dist/lib/git.d.ts +77 -0
  35. package/dist/lib/git.js +439 -0
  36. package/dist/lib/git.private.test.d.ts +1 -0
  37. package/dist/lib/git.private.test.js +618 -0
  38. package/dist/lib/git.test.d.ts +1 -0
  39. package/dist/lib/git.test.js +580 -0
  40. package/dist/lib/github/commitFormatters.d.ts +3 -0
  41. package/dist/lib/github/commitFormatters.js +17 -0
  42. package/dist/lib/github/commitFormatters.test.d.ts +1 -0
  43. package/dist/lib/github/commitFormatters.test.js +11 -0
  44. package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +2 -0
  45. package/dist/lib/github/v3/addAssigneesToPullRequest.js +32 -0
  46. package/dist/lib/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  47. package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +27 -0
  48. package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +2 -0
  49. package/dist/lib/github/v3/addLabelsToPullRequest.js +30 -0
  50. package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +2 -0
  51. package/dist/lib/github/v3/addReviewersToPullRequest.js +32 -0
  52. package/dist/lib/github/v3/createPullRequest.d.ts +29 -0
  53. package/dist/lib/github/v3/createPullRequest.js +91 -0
  54. package/dist/lib/github/v3/createPullRequest.test.d.ts +1 -0
  55. package/dist/lib/github/v3/createPullRequest.test.js +377 -0
  56. package/dist/lib/github/v3/createStatusComment.d.ts +11 -0
  57. package/dist/lib/github/v3/createStatusComment.js +138 -0
  58. package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
  59. package/dist/lib/github/v3/createStatusComment.test.js +566 -0
  60. package/dist/lib/github/v3/getGithubV3ErrorMessage.d.ts +14 -0
  61. package/dist/lib/github/v3/getGithubV3ErrorMessage.js +16 -0
  62. package/dist/lib/github/v4/FetchPullRequestId.d.ts +2 -0
  63. package/dist/lib/github/v4/FetchPullRequestId.js +36 -0
  64. package/dist/lib/github/v4/apiRequestV4.d.ts +31 -0
  65. package/dist/lib/github/v4/apiRequestV4.js +71 -0
  66. package/dist/lib/github/v4/apiRequestV4.test.d.ts +1 -0
  67. package/dist/lib/github/v4/apiRequestV4.test.js +109 -0
  68. package/dist/lib/github/v4/disablePullRequestAutoMerge.d.ts +2 -0
  69. package/dist/lib/github/v4/disablePullRequestAutoMerge.js +32 -0
  70. package/dist/lib/github/v4/enablePullRequestAutoMerge.d.ts +2 -0
  71. package/dist/lib/github/v4/enablePullRequestAutoMerge.js +50 -0
  72. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  73. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  74. package/dist/lib/github/v4/fetchAuthorId.d.ts +10 -0
  75. package/dist/lib/github/v4/fetchAuthorId.js +28 -0
  76. package/dist/lib/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  77. package/dist/lib/github/v4/fetchAuthorId.private.test.js +25 -0
  78. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  79. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
  80. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +11 -0
  81. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +58 -0
  82. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  83. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +136 -0
  84. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.d.ts +11 -0
  85. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +48 -0
  86. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  87. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +118 -0
  88. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +29 -0
  89. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +110 -0
  90. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  91. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +196 -0
  92. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  93. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
  94. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  95. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +107 -0
  96. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +12 -0
  97. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +69 -0
  98. package/dist/lib/github/v4/fetchExistingPullRequest.d.ts +9 -0
  99. package/dist/lib/github/v4/fetchExistingPullRequest.js +64 -0
  100. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  101. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.js +44 -0
  102. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.d.ts +2 -0
  103. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.js +39 -0
  104. package/dist/lib/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  105. package/dist/lib/github/v4/fetchRemoteProjectConfig.js +49 -0
  106. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  107. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.js +49 -0
  108. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +72 -0
  109. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +78 -0
  110. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  111. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +116 -0
  112. package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +16 -0
  113. package/dist/lib/github/v4/getOptionsFromGithub/query.js +29 -0
  114. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
  115. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.js +61 -0
  116. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  117. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +72 -0
  118. package/dist/lib/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  119. package/dist/lib/github/v4/mocks/commitsByAuthorMock.js +176 -0
  120. package/dist/lib/github/v4/throwOnInvalidAccessToken.d.ts +7 -0
  121. package/dist/lib/github/v4/throwOnInvalidAccessToken.js +45 -0
  122. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  123. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  124. package/dist/lib/github/v4/validateTargetBranches.d.ts +9 -0
  125. package/dist/lib/github/v4/validateTargetBranches.js +46 -0
  126. package/dist/lib/github/v4/validateTargetBranches.private.test.d.ts +1 -0
  127. package/dist/lib/github/v4/validateTargetBranches.private.test.js +51 -0
  128. package/dist/lib/logger.d.ts +11 -0
  129. package/dist/lib/logger.js +80 -0
  130. package/dist/lib/ora.d.ts +2 -0
  131. package/dist/lib/ora.js +21 -0
  132. package/dist/lib/prompt.test.d.ts +1 -0
  133. package/dist/lib/prompt.test.js +139 -0
  134. package/dist/lib/prompts.d.ts +17 -0
  135. package/dist/lib/prompts.js +132 -0
  136. package/dist/lib/remoteConfig.d.ts +20 -0
  137. package/dist/lib/remoteConfig.js +52 -0
  138. package/dist/lib/sequentially.d.ts +1 -0
  139. package/dist/lib/sequentially.js +10 -0
  140. package/dist/lib/setupRepo.d.ts +2 -0
  141. package/dist/lib/setupRepo.js +56 -0
  142. package/dist/lib/setupRepo.test.d.ts +1 -0
  143. package/dist/lib/setupRepo.test.js +278 -0
  144. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
  145. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
  146. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  147. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
  148. package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
  149. package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
  150. package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
  151. package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
  152. package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  153. package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
  154. package/dist/options/ConfigOptions.d.ts +4 -2
  155. package/dist/options/cliArgs.d.ts +12 -9
  156. package/dist/options/cliArgs.js +34 -19
  157. package/dist/options/cliArgs.test.js +126 -2
  158. package/dist/options/config/config.d.ts +5 -4
  159. package/dist/options/config/config.js +3 -5
  160. package/dist/options/config/config.test.js +0 -1
  161. package/dist/options/config/globalConfig.d.ts +3 -1
  162. package/dist/options/config/globalConfig.js +5 -5
  163. package/dist/options/config/readConfigFile.d.ts +6 -4
  164. package/dist/options/config/readConfigFile.js +2 -2
  165. package/dist/options/options.d.ts +40 -4
  166. package/dist/options/options.js +20 -24
  167. package/dist/options/options.test.js +112 -54
  168. package/dist/runSequentially.d.ts +10 -9
  169. package/dist/runSequentially.js +7 -8
  170. package/dist/scripts/postinstall.js +3 -3
  171. package/dist/scripts/postinstall.test.js +1 -1
  172. package/dist/services/BackportError.d.ts +19 -0
  173. package/dist/services/BackportError.js +29 -0
  174. package/dist/services/HandledBackportError.d.ts +19 -0
  175. package/dist/services/HandledBackportError.js +29 -0
  176. package/dist/services/HandledError.d.ts +1 -1
  177. package/dist/services/HandledError.js +5 -5
  178. package/dist/services/git.js +7 -7
  179. package/dist/services/github/v3/createPullRequest.js +2 -2
  180. package/dist/services/github/v3/createStatusComment.js +2 -2
  181. package/dist/services/github/v3/createStatusComment.test.js +5 -4
  182. package/dist/services/github/v4/apiRequestV4.js +2 -2
  183. package/dist/services/github/v4/apiRequestV4.test.js +2 -2
  184. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +3 -3
  185. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
  186. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +3 -3
  187. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +2 -2
  188. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
  189. package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
  190. package/dist/state.d.ts +0 -0
  191. package/dist/state.js +1 -0
  192. package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
  193. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +27 -25
  194. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +46 -250
  195. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.d.ts +1 -0
  196. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +80 -0
  197. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.d.ts +1 -0
  198. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +199 -0
  199. package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +1 -0
  200. package/dist/test/e2e/cli/interactive-error-handling.private.test.js +80 -0
  201. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +1 -0
  202. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +198 -0
  203. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +13 -15
  204. package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -2
  205. package/dist/test/e2e/cli/runBackportViaCli.js +42 -29
  206. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
  207. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +2 -2
  208. package/dist/test/handleUnbackportedPullRequests.private.test.js +3 -2
  209. package/dist/test/setupFiles/automatic-mocks.js +1 -1
  210. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
  211. package/dist/ui/getCommits.js +2 -2
  212. package/dist/ui/getTargetBranches.js +3 -3
  213. package/dist/ui/setupRepo.js +2 -2
  214. package/dist/utils/packageVersion.d.ts +1 -1
  215. package/dist/utils/packageVersion.js +1 -1
  216. package/package.json +14 -14
  217. package/yarn.lock +125 -73
@@ -23,36 +23,35 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- const child_process_promisified_1 = require("../../../services/child-process-promisified");
27
- const env_1 = require("../../../services/env");
26
+ const child_process_promisified_1 = require("../../../lib/child-process-promisified");
28
27
  const packageVersion = __importStar(require("../../../utils/packageVersion"));
29
28
  const getDevAccessToken_1 = require("../../private/getDevAccessToken");
30
29
  const sandbox_1 = require("../../sandbox");
31
30
  const runBackportViaCli_1 = require("./runBackportViaCli");
32
- const TIMEOUT_IN_SECONDS = 15;
33
- jest.setTimeout(TIMEOUT_IN_SECONDS * 1000);
31
+ jest.setTimeout(10000);
34
32
  const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
35
33
  describe('entrypoint cli', () => {
36
34
  it('--version', async () => {
37
- const res = await (0, runBackportViaCli_1.runBackportViaCli)([`--version`], {
35
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`--version`], {
38
36
  showOra: true,
39
37
  });
40
- expect(res).toEqual(process.env.npm_package_version);
38
+ expect(output).toEqual(process.env.npm_package_version);
41
39
  });
42
40
  it('-v', async () => {
43
- const res = await (0, runBackportViaCli_1.runBackportViaCli)([`-v`], {
41
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`-v`], {
44
42
  showOra: true,
45
43
  });
46
- expect(res).toEqual(process.env.npm_package_version);
44
+ expect(output).toEqual(process.env.npm_package_version);
47
45
  });
48
46
  it('PACKAGE_VERSION should match', async () => {
49
47
  // @ts-expect-error
50
48
  expect(packageVersion.UNMOCKED_PACKAGE_VERSION).toBe(process.env.npm_package_version);
51
49
  });
52
50
  it('--help', async () => {
53
- const res = await (0, runBackportViaCli_1.runBackportViaCli)([`--help`]);
54
- expect(res).toMatchInlineSnapshot(`
51
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`--help`]);
52
+ expect(output).toMatchInlineSnapshot(`
55
53
  "entrypoint.cli.ts [args]
54
+
56
55
  Options:
57
56
  -v, --version Show version number [boolean]
58
57
  --accessToken, --accesstoken Github access token [string]
@@ -62,10 +61,10 @@ describe('entrypoint cli', () => {
62
61
  --autoMerge Enable auto-merge for created pull requests [boolean]
63
62
  --autoMergeMethod Sets auto-merge method when using --auto-merge. Default:
64
63
  merge [string] [choices: \\"merge\\", \\"rebase\\", \\"squash\\"]
65
- --ci Disable interactive prompts [boolean]
66
64
  --cherrypickRef Append commit message with \\"(cherry picked from commit...)
67
65
  [boolean]
68
66
  --projectConfigFile, --config Path to project config [string]
67
+ --globalConfigFile Path to global config [string]
69
68
  --since ISO-8601 date for filtering commits [string]
70
69
  --until ISO-8601 date for filtering commits [string]
71
70
  --dir Path to temporary backport repo [string]
@@ -78,6 +77,8 @@ describe('entrypoint cli', () => {
78
77
  [boolean]
79
78
  --gitAuthorName Set commit author name [string]
80
79
  --gitAuthorEmail Set commit author email [string]
80
+ --nonInteractive, --json Disable interactive prompts and return response as JSON
81
+ [boolean]
81
82
  --ls List commits instead of backporting them [boolean]
82
83
  --mainline Parent id of merge commit. Defaults to 1 when supplied
83
84
  without arguments [number]
@@ -112,103 +113,37 @@ describe('entrypoint cli', () => {
112
113
  -l, --targetPRLabel, --label Add labels to the target (backport) PR [array]
113
114
  --verify Opposite of no-verify [boolean]
114
115
  --help Show help [boolean]
116
+
115
117
  For bugs, feature requests or questions: https://github.com/sqren/backport/issues
116
118
  Or contact me directly: https://twitter.com/sorenlouv"
117
119
  `);
118
120
  });
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
- it('should list commits based on .git/config when `repoOwner`/`repoName` is missing', async () => {
121
+ it('lists commits based on .git/config when `repoOwner`/`repoName` is missing', async () => {
139
122
  const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
140
123
  await (0, sandbox_1.resetSandbox)(sandboxPath);
141
124
  await (0, child_process_promisified_1.exec)(`git init`, { cwd: sandboxPath });
142
125
  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}`], {
126
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`--accessToken=${accessToken}`], {
144
127
  cwd: sandboxPath,
145
128
  waitForString: 'Select commit',
146
129
  });
147
- expect(res).toMatchInlineSnapshot(`
130
+ expect(output).toMatchInlineSnapshot(`
148
131
  "? 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
132
+ ❯ 1. Add sheep emoji (#9) 7.8
133
+ 2. Change Ulysses to Gretha (conflict) (#8) 7.x
134
+ 3. Add 🍏 emoji (#5) 7.x, 7.8
135
+ 4. Add family emoji (#2) 7.x
136
+ 5. Add \`backport\` dep
137
+ 6. Merge pull request #1 from backport-org/add-heart-emoji
138
+ 7. Add ❤️ emoji
139
+ 8. Update .backportrc.json
140
+ 9. Bump to 8.0.0
158
141
  10.Add package.json"
159
142
  `);
160
143
  });
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',
144
+ it(`lists commits from master`, async () => {
145
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
187
146
  '--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
- it(`should list commits from master`, async () => {
210
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
211
- '--branch=foo',
212
147
  '--repo=backport-org/backport-e2e',
213
148
  '--author=sqren',
214
149
  `--accessToken=${accessToken}`,
@@ -216,17 +151,17 @@ describe('entrypoint cli', () => {
216
151
  ], { waitForString: 'Select commit' });
217
152
  expect(output).toMatchInlineSnapshot(`
218
153
  "? 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
154
+ ❯ 1. Add sheep emoji (#9) 7.8
155
+ 2. Change Ulysses to Gretha (conflict) (#8) 7.x
156
+ 3. Add 🍏 emoji (#5) 7.x, 7.8
157
+ 4. Add family emoji (#2) 7.x
158
+ 5. Add \`backport\` dep
224
159
  6. Merge pull request #1 from backport-org/add-heart-emoji"
225
160
  `);
226
161
  });
227
- it(`should filter commits by "since" and "until"`, async () => {
228
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
229
- '--branch=foo',
162
+ it(`filters commits by "since" and "until"`, async () => {
163
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
164
+ '--branch=7.x',
230
165
  '--repo=backport-org/backport-e2e',
231
166
  `--accessToken=${accessToken}`,
232
167
  '--since=2020-08-15T10:00:00.000Z',
@@ -234,15 +169,15 @@ describe('entrypoint cli', () => {
234
169
  ], { waitForString: 'Select commit' });
235
170
  expect(output).toMatchInlineSnapshot(`
236
171
  "? Select commit (Use arrow keys)
237
- ❯ 1. Bump to 8.0.0
238
- 2. Add package.json
239
- 3. Update .backportrc.json
172
+ ❯ 1. Bump to 8.0.0
173
+ 2. Add package.json
174
+ 3. Update .backportrc.json
240
175
  4. Create .backportrc.json"
241
176
  `);
242
177
  });
243
- it(`should list commits from 7.x`, async () => {
244
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
245
- '--branch=foo',
178
+ it(`lists commits from 7.x`, async () => {
179
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
180
+ '--branch=7.x',
246
181
  '--repo=backport-org/backport-e2e',
247
182
  '--author=sqren',
248
183
  `--accessToken=${accessToken}`,
@@ -251,151 +186,12 @@ describe('entrypoint cli', () => {
251
186
  ], { waitForString: 'Select commit' });
252
187
  expect(output).toMatchInlineSnapshot(`
253
188
  "? 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)
189
+ ❯ 1. Add 🍏 emoji (#5) (#6)
190
+ 2. Change Ulysses to Carol
191
+ 3. Add family emoji (#2) (#4)
192
+ 4. Update .backportrc.json
193
+ 5. Branch off: 7.9.0 (7.x)
259
194
  6. Bump to 8.0.0"
260
195
  `);
261
196
  });
262
- describe('ci failure cases', () => {
263
- it(`when access token is missing`, async () => {
264
- const output = await (0, runBackportViaCli_1.runBackportViaCli)(['--ci']);
265
- const backportResult = JSON.parse(output);
266
- 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');
268
- });
269
- it(`when argument is invalid`, async () => {
270
- const output = await (0, runBackportViaCli_1.runBackportViaCli)(['--ci', '--foo']);
271
- const backportResult = JSON.parse(output);
272
- expect(backportResult.status).toBe('failure');
273
- expect(backportResult.errorMessage).toEqual('Unknown argument: foo');
274
- });
275
- it('when `--repo` is invalid', async () => {
276
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
277
- '--repo=backport-org/backport-e2e-foo',
278
- '--ci',
279
- `--accessToken=${accessToken}`,
280
- ]);
281
- const backportResult = JSON.parse(output);
282
- expect(backportResult.status).toBe('failure');
283
- expect(backportResult.errorMessage).toEqual('The repository "backport-org/backport-e2e-foo" doesn\'t exist');
284
- });
285
- it('when `--sha` is invalid', async () => {
286
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
287
- '--repo=backport-org/backport-e2e',
288
- '--sha=abcdefg',
289
- '--ci',
290
- `--accessToken=${accessToken}`,
291
- ]);
292
- const backportResult = JSON.parse(output);
293
- expect(backportResult.status).toBe('failure');
294
- expect(backportResult.errorMessage).toEqual('No commit found on branch "master" with sha "abcdefg"');
295
- });
296
- it('when `--branch` is invalid', async () => {
297
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
298
- '--repo=backport-org/backport-e2e',
299
- '--pr=9',
300
- '--branch=foobar',
301
- '--ci',
302
- `--accessToken=${accessToken}`,
303
- ]);
304
- const backportResult = JSON.parse(output);
305
- expect(backportResult.status).toBe('success');
306
- expect(backportResult.results[0]).toEqual({
307
- error: {
308
- errorContext: {
309
- code: 'message-only-exception',
310
- message: 'The branch "foobar" is invalid or doesn\'t exist',
311
- },
312
- name: 'HandledError',
313
- },
314
- status: 'handled-error',
315
- targetBranch: 'foobar',
316
- });
317
- });
318
- it('when `--pr` is invalid', async () => {
319
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
320
- '--repo=backport-org/backport-e2e',
321
- '--pr=900',
322
- '--branch=foobar',
323
- '--ci',
324
- `--accessToken=${accessToken}`,
325
- ]);
326
- const backportResult = JSON.parse(output);
327
- expect(backportResult.status).toEqual('failure');
328
- expect(backportResult.errorMessage).toEqual('Could not resolve to a PullRequest with the number of 900. (Github API v4)');
329
- });
330
- it('when having conflicts', async () => {
331
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
332
- '--repo=backport-org/repo-with-conflicts',
333
- '--pr=12',
334
- '--branch=7.x',
335
- '--ci',
336
- `--accessToken=${accessToken}`,
337
- ]);
338
- const backportResult = JSON.parse(output);
339
- expect(backportResult.status).toEqual('success');
340
- expect(
341
- //@ts-expect-error
342
- backportResult.results[0].error.errorContext.conflictingFiles).toEqual(['la-liga.md']);
343
- });
344
- it('when `--source-branch` is invalid', async () => {
345
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
346
- '--repo=backport-org/backport-e2e',
347
- '--pr=9',
348
- '--branch=7.x',
349
- '--source-branch=foo',
350
- '--ci',
351
- `--accessToken=${accessToken}`,
352
- ]);
353
- const backportResult = JSON.parse(output);
354
- expect(backportResult.status).toBe('success');
355
- expect(backportResult.results[0]).toEqual({
356
- error: {
357
- context: {
358
- cmdArgs: ['checkout', 'foo'],
359
- code: 1,
360
- stderr: "error: pathspec 'foo' did not match any file(s) known to git\n",
361
- stdout: '',
362
- },
363
- name: 'SpawnError',
364
- },
365
- status: 'unhandled-error',
366
- targetBranch: '7.x',
367
- });
368
- });
369
- it('when PR is not merged', async () => {
370
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
371
- '--repo=backport-org/backport-e2e',
372
- '--pr=12',
373
- '--ci',
374
- `--accessToken=${accessToken}`,
375
- ]);
376
- const backportResult = JSON.parse(output);
377
- expect(backportResult.status).toBe('failure');
378
- expect(backportResult.error).toEqual({
379
- errorContext: {
380
- code: 'message-only-exception',
381
- message: 'The PR #12 is not merged',
382
- },
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',
398
- });
399
- });
400
- });
401
197
  });
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
4
+ const sandbox_1 = require("../../sandbox");
5
+ const runBackportViaCli_1 = require("./runBackportViaCli");
6
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
7
+ describe('interactive error handling', () => {
8
+ it('when branch is missing', async () => {
9
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
10
+ '--skip-remote-config',
11
+ '--repo=backport-org/backport-e2e',
12
+ `--accessToken=${accessToken}`,
13
+ ]);
14
+ expect(output).toMatchInlineSnapshot(`
15
+ "Please specify a target branch: \\"--branch 6.1\\".
16
+
17
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
18
+ `);
19
+ });
20
+ it('when supplying invalid argument', async () => {
21
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`--foo`]);
22
+ expect(output).toMatchInlineSnapshot(`
23
+ "Unknown argument: foo
24
+ Run \\"backport --help\\" to see all options"
25
+ `);
26
+ });
27
+ it('when access token is invalid', async () => {
28
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
29
+ '--branch=foo',
30
+ '--repo=foo/bar',
31
+ '--accessToken=some-token',
32
+ ]);
33
+ expect(output).toContain('Please check your access token and make sure it is valid');
34
+ });
35
+ it(`when repo doesn't exist`, async () => {
36
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
37
+ '--branch=foo',
38
+ '--repo=foo/bar',
39
+ '--author=sqren',
40
+ `--accessToken=${accessToken}`,
41
+ ]);
42
+ expect(output).toMatchInlineSnapshot(`"The repository \\"foo/bar\\" doesn't exist"`);
43
+ });
44
+ it(`when given branch is invalid`, async () => {
45
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
46
+ '--branch=foo',
47
+ '--repo=backport-org/backport-e2e',
48
+ '--pr=9',
49
+ `--accessToken=${accessToken}`,
50
+ ]);
51
+ expect(output).toMatchInlineSnapshot(`"The branch \\"foo\\" does not exist"`);
52
+ });
53
+ it(`when encountering conflicts`, async () => {
54
+ const backportDir = (0, sandbox_1.getSandboxPath)({ filename: __filename });
55
+ await (0, sandbox_1.resetSandbox)(backportDir);
56
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
57
+ '--repo=backport-org/repo-with-conflicts',
58
+ '--pr=12',
59
+ '--branch=7.x',
60
+ `--accessToken=${accessToken}`,
61
+ `--dir=${backportDir}`,
62
+ '--dry-run',
63
+ ], {
64
+ waitForString: 'Press ENTER when the conflicts',
65
+ timeoutSeconds: 5,
66
+ });
67
+ // //@ts-expect-error
68
+ // const lineToReplace = output.match(
69
+ // /Conflicting files:[\s]+- (.*[\s].*)la-liga.md/
70
+ // )[1];
71
+ // const lineWithoutBreaks = lineToReplace.replace(/\s/g, '');
72
+ // const outputReplaced = output
73
+ // .replace(lineToReplace, lineWithoutBreaks)
74
+ // .replaceAll(backportDir, '<BACKPORT_DIR>');
75
+ const outputReplaced = output
76
+ .replaceAll('\n', '')
77
+ .replaceAll(backportDir, '<BACKPORT_DIR>');
78
+ 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)"`);
79
+ });
80
+ });