backport 7.3.6 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/README.md +16 -21
  2. package/dist/backportRun.d.ts +18 -6
  3. package/dist/backportRun.js +70 -50
  4. package/dist/entrypoint.cli.js +4 -8
  5. package/dist/entrypoint.module.d.ts +13 -6
  6. package/dist/entrypoint.module.js +17 -19
  7. package/dist/entrypoint.module.private.test.js +129 -330
  8. package/dist/errors/BackportError.d.ts +19 -0
  9. package/dist/errors/BackportError.js +29 -0
  10. package/dist/lib/BackportError.d.ts +19 -0
  11. package/dist/lib/BackportError.js +29 -0
  12. package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +13 -0
  13. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +238 -0
  14. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  15. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +321 -0
  16. package/dist/lib/child-process-promisified.d.ts +25 -0
  17. package/dist/lib/child-process-promisified.js +58 -0
  18. package/dist/lib/env.d.ts +7 -0
  19. package/dist/lib/env.js +33 -0
  20. package/dist/lib/env.test.d.ts +1 -0
  21. package/dist/lib/env.test.js +26 -0
  22. package/dist/lib/getCommits.d.ts +2 -0
  23. package/dist/lib/getCommits.js +75 -0
  24. package/dist/lib/getCommitsWithoutBackports.d.ts +11 -0
  25. package/dist/lib/getCommitsWithoutBackports.js +68 -0
  26. package/dist/lib/getCommitsWithoutBackports.test.d.ts +1 -0
  27. package/dist/lib/getCommitsWithoutBackports.test.js +335 -0
  28. package/dist/lib/getGitConfigAuthor.d.ts +6 -0
  29. package/dist/lib/getGitConfigAuthor.js +15 -0
  30. package/dist/lib/getTargetBranches.d.ts +5 -0
  31. package/dist/lib/getTargetBranches.js +67 -0
  32. package/dist/lib/getTargetBranches.test.d.ts +1 -0
  33. package/dist/lib/getTargetBranches.test.js +206 -0
  34. package/dist/lib/git.d.ts +77 -0
  35. package/dist/lib/git.js +439 -0
  36. package/dist/lib/git.private.test.d.ts +1 -0
  37. package/dist/lib/git.private.test.js +618 -0
  38. package/dist/lib/git.test.d.ts +1 -0
  39. package/dist/lib/git.test.js +580 -0
  40. package/dist/lib/github/commitFormatters.d.ts +3 -0
  41. package/dist/lib/github/commitFormatters.js +17 -0
  42. package/dist/lib/github/commitFormatters.test.d.ts +1 -0
  43. package/dist/lib/github/commitFormatters.test.js +11 -0
  44. package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +2 -0
  45. package/dist/lib/github/v3/addAssigneesToPullRequest.js +32 -0
  46. package/dist/lib/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  47. package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +27 -0
  48. package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +2 -0
  49. package/dist/lib/github/v3/addLabelsToPullRequest.js +30 -0
  50. package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +2 -0
  51. package/dist/lib/github/v3/addReviewersToPullRequest.js +32 -0
  52. package/dist/lib/github/v3/createPullRequest.d.ts +29 -0
  53. package/dist/lib/github/v3/createPullRequest.js +91 -0
  54. package/dist/lib/github/v3/createPullRequest.test.d.ts +1 -0
  55. package/dist/lib/github/v3/createPullRequest.test.js +377 -0
  56. package/dist/lib/github/v3/createStatusComment.d.ts +11 -0
  57. package/dist/lib/github/v3/createStatusComment.js +136 -0
  58. package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
  59. package/dist/lib/github/v3/createStatusComment.test.js +461 -0
  60. package/dist/lib/github/v3/getGithubV3ErrorMessage.d.ts +14 -0
  61. package/dist/lib/github/v3/getGithubV3ErrorMessage.js +16 -0
  62. package/dist/lib/github/v4/FetchPullRequestId.d.ts +2 -0
  63. package/dist/lib/github/v4/FetchPullRequestId.js +36 -0
  64. package/dist/lib/github/v4/apiRequestV4.d.ts +31 -0
  65. package/dist/lib/github/v4/apiRequestV4.js +71 -0
  66. package/dist/lib/github/v4/apiRequestV4.test.d.ts +1 -0
  67. package/dist/lib/github/v4/apiRequestV4.test.js +109 -0
  68. package/dist/lib/github/v4/disablePullRequestAutoMerge.d.ts +2 -0
  69. package/dist/lib/github/v4/disablePullRequestAutoMerge.js +32 -0
  70. package/dist/lib/github/v4/enablePullRequestAutoMerge.d.ts +2 -0
  71. package/dist/lib/github/v4/enablePullRequestAutoMerge.js +50 -0
  72. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  73. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  74. package/dist/lib/github/v4/fetchAuthorId.d.ts +10 -0
  75. package/dist/lib/github/v4/fetchAuthorId.js +28 -0
  76. package/dist/lib/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  77. package/dist/lib/github/v4/fetchAuthorId.private.test.js +25 -0
  78. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  79. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
  80. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +11 -0
  81. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +58 -0
  82. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  83. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +136 -0
  84. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.d.ts +11 -0
  85. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +48 -0
  86. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  87. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +118 -0
  88. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +29 -0
  89. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +110 -0
  90. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  91. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +196 -0
  92. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  93. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
  94. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  95. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +107 -0
  96. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +12 -0
  97. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +69 -0
  98. package/dist/lib/github/v4/fetchExistingPullRequest.d.ts +9 -0
  99. package/dist/lib/github/v4/fetchExistingPullRequest.js +64 -0
  100. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  101. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.js +44 -0
  102. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.d.ts +2 -0
  103. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.js +39 -0
  104. package/dist/lib/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  105. package/dist/lib/github/v4/fetchRemoteProjectConfig.js +49 -0
  106. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  107. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.js +49 -0
  108. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +72 -0
  109. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +78 -0
  110. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  111. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +116 -0
  112. package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +16 -0
  113. package/dist/lib/github/v4/getOptionsFromGithub/query.js +29 -0
  114. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
  115. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.js +61 -0
  116. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  117. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +72 -0
  118. package/dist/lib/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  119. package/dist/lib/github/v4/mocks/commitsByAuthorMock.js +176 -0
  120. package/dist/lib/github/v4/throwOnInvalidAccessToken.d.ts +7 -0
  121. package/dist/lib/github/v4/throwOnInvalidAccessToken.js +45 -0
  122. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  123. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  124. package/dist/lib/logger.d.ts +9 -0
  125. package/dist/lib/logger.js +74 -0
  126. package/dist/lib/ora.d.ts +2 -0
  127. package/dist/lib/ora.js +21 -0
  128. package/dist/lib/prompt.test.d.ts +1 -0
  129. package/dist/lib/prompt.test.js +139 -0
  130. package/dist/lib/prompts.d.ts +17 -0
  131. package/dist/lib/prompts.js +132 -0
  132. package/dist/lib/remoteConfig.d.ts +20 -0
  133. package/dist/lib/remoteConfig.js +52 -0
  134. package/dist/lib/sequentially.d.ts +1 -0
  135. package/dist/lib/sequentially.js +10 -0
  136. package/dist/lib/setupRepo.d.ts +2 -0
  137. package/dist/lib/setupRepo.js +56 -0
  138. package/dist/lib/setupRepo.test.d.ts +1 -0
  139. package/dist/lib/setupRepo.test.js +278 -0
  140. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
  141. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
  142. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  143. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
  144. package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
  145. package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
  146. package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
  147. package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
  148. package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  149. package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
  150. package/dist/options/ConfigOptions.d.ts +6 -4
  151. package/dist/options/cliArgs.d.ts +16 -9
  152. package/dist/options/cliArgs.js +54 -28
  153. package/dist/options/cliArgs.test.js +128 -4
  154. package/dist/options/config/config.d.ts +7 -6
  155. package/dist/options/config/config.js +5 -7
  156. package/dist/options/config/config.test.js +0 -1
  157. package/dist/options/config/globalConfig.d.ts +5 -3
  158. package/dist/options/config/globalConfig.js +17 -14
  159. package/dist/options/config/projectConfig.d.ts +2 -2
  160. package/dist/options/config/projectConfig.js +3 -3
  161. package/dist/options/config/projectConfig.test.js +19 -7
  162. package/dist/options/config/readConfigFile.d.ts +9 -7
  163. package/dist/options/config/readConfigFile.js +2 -2
  164. package/dist/options/options.d.ts +44 -9
  165. package/dist/options/options.js +22 -27
  166. package/dist/options/options.test.js +119 -58
  167. package/dist/runSequentially.d.ts +14 -7
  168. package/dist/runSequentially.js +26 -11
  169. package/dist/scripts/postinstall.js +4 -3
  170. package/dist/scripts/postinstall.test.js +6 -2
  171. package/dist/services/BackportError.d.ts +19 -0
  172. package/dist/services/BackportError.js +29 -0
  173. package/dist/services/HandledBackportError.d.ts +19 -0
  174. package/dist/services/HandledBackportError.js +29 -0
  175. package/dist/services/HandledError.d.ts +7 -3
  176. package/dist/services/HandledError.js +13 -13
  177. package/dist/services/child-process-promisified.d.ts +19 -3
  178. package/dist/services/child-process-promisified.js +46 -17
  179. package/dist/services/git.d.ts +6 -7
  180. package/dist/services/git.integration.test.js +381 -65
  181. package/dist/services/git.js +189 -127
  182. package/dist/services/git.private.test.d.ts +1 -0
  183. package/dist/services/git.private.test.js +618 -0
  184. package/dist/services/git.test.js +167 -158
  185. package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
  186. package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
  187. package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
  188. package/dist/services/github/v3/createPullRequest.js +4 -2
  189. package/dist/services/github/v3/createStatusComment.js +17 -17
  190. package/dist/services/github/v3/createStatusComment.test.js +22 -9
  191. package/dist/services/github/v4/apiRequestV4.js +8 -11
  192. package/dist/services/github/v4/apiRequestV4.test.js +2 -2
  193. package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
  194. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
  195. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +5 -6
  196. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +4 -3
  197. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +10 -9
  198. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +3 -2
  199. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +10 -9
  200. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +4 -3
  201. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +9 -8
  202. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +3 -6
  203. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +3 -2
  204. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -6
  205. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +4 -7
  206. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -2
  207. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
  208. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -7
  209. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +9 -8
  210. package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
  211. package/dist/services/logger.d.ts +1 -4
  212. package/dist/services/logger.js +14 -19
  213. package/dist/services/test.d.ts +1 -0
  214. package/dist/services/test.js +23 -0
  215. package/dist/state.d.ts +0 -0
  216. package/dist/state.js +1 -0
  217. package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
  218. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +26 -24
  219. package/dist/test/e2e/cli/entrypoint.cli.private.test.d.ts +1 -0
  220. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +450 -0
  221. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +27 -28
  222. package/dist/test/e2e/cli/runBackportViaCli.d.ts +6 -2
  223. package/dist/test/e2e/cli/runBackportViaCli.js +44 -23
  224. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
  225. package/dist/test/e2e/module/entrypoint.module.mutation.test.d.ts +1 -0
  226. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +376 -0
  227. package/dist/test/handleUnbackportedPullRequests.private.test.js +12 -10
  228. package/dist/test/sandbox.js +5 -1
  229. package/dist/test/setupFiles/automatic-mocks.js +17 -13
  230. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +11 -7
  231. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
  232. package/dist/ui/getCommits.js +2 -2
  233. package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
  234. package/dist/ui/getGitConfigAuthor.js +1 -1
  235. package/dist/ui/getTargetBranches.js +3 -3
  236. package/dist/ui/getTargetBranches.test.js +5 -1
  237. package/dist/ui/ora.d.ts +1 -8
  238. package/dist/ui/setupRepo.js +3 -3
  239. package/dist/ui/setupRepo.test.js +98 -61
  240. package/dist/utils/isErrnoError.d.ts +2 -0
  241. package/dist/utils/isErrnoError.js +7 -0
  242. package/dist/utils/packageVersion.d.ts +1 -1
  243. package/dist/utils/packageVersion.js +1 -1
  244. package/package.json +17 -17
  245. package/yarn.lock +461 -695
@@ -0,0 +1,450 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const promises_1 = __importDefault(require("fs/promises"));
30
+ const path_1 = __importDefault(require("path"));
31
+ const child_process_promisified_1 = require("../../../lib/child-process-promisified");
32
+ const packageVersion = __importStar(require("../../../utils/packageVersion"));
33
+ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
34
+ const sandbox_1 = require("../../sandbox");
35
+ const runBackportViaCli_1 = require("./runBackportViaCli");
36
+ jest.setTimeout(10000);
37
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
38
+ describe('entrypoint cli', () => {
39
+ it('--version', async () => {
40
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`--version`], {
41
+ showOra: true,
42
+ });
43
+ expect(output).toEqual(process.env.npm_package_version);
44
+ });
45
+ it('-v', async () => {
46
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`-v`], {
47
+ showOra: true,
48
+ });
49
+ expect(output).toEqual(process.env.npm_package_version);
50
+ });
51
+ it('PACKAGE_VERSION should match', async () => {
52
+ // @ts-expect-error
53
+ expect(packageVersion.UNMOCKED_PACKAGE_VERSION).toBe(process.env.npm_package_version);
54
+ });
55
+ it('--help', async () => {
56
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`--help`]);
57
+ expect(output).toMatchInlineSnapshot(`
58
+ "entrypoint.cli.ts [args]
59
+
60
+ Options:
61
+ -v, --version Show version number [boolean]
62
+ --accessToken, --accesstoken Github access token [string]
63
+ -a, --all List all commits [boolean]
64
+ --assignee, --assign Add assignees to the target pull request [array]
65
+ --autoAssign Auto assign the target pull request to yourself [boolean]
66
+ --autoMerge Enable auto-merge for created pull requests [boolean]
67
+ --autoMergeMethod Sets auto-merge method when using --auto-merge. Default:
68
+ merge [string] [choices: \\"merge\\", \\"rebase\\", \\"squash\\"]
69
+ --cherrypickRef Append commit message with \\"(cherry picked from commit...)
70
+ [boolean]
71
+ --projectConfigFile, --config Path to project config [string]
72
+ --globalConfigFile Path to global config [string]
73
+ --since ISO-8601 date for filtering commits [string]
74
+ --until ISO-8601 date for filtering commits [string]
75
+ --dir Path to temporary backport repo [string]
76
+ --details Show details about each commit [boolean]
77
+ --dryRun Run backport locally without pushing to Github [boolean]
78
+ --editor Editor to be opened during conflict resolution [string]
79
+ --skipRemoteConfig Use local .backportrc.json config instead of loading from
80
+ Github [boolean]
81
+ --fork Create backports in fork or origin repo. Defaults to true
82
+ [boolean]
83
+ --gitAuthorName Set commit author name [string]
84
+ --gitAuthorEmail Set commit author email [string]
85
+ --nonInteractive, --json Disable interactive prompts and return response as JSON
86
+ [boolean]
87
+ --ls List commits instead of backporting them [boolean]
88
+ --mainline Parent id of merge commit. Defaults to 1 when supplied
89
+ without arguments [number]
90
+ -n, --maxNumber, --number Number of commits to choose from [number]
91
+ --multiple Select multiple branches/commits [boolean]
92
+ --multipleBranches Backport to multiple branches [boolean]
93
+ --multipleCommits Backport multiple commits [boolean]
94
+ --noCherrypickRef Do not append commit message with \\"(cherry picked from
95
+ commit...)\\" [boolean]
96
+ --noStatusComment Don't publish status comment to Github [boolean]
97
+ --noVerify Bypass the pre-commit and commit-msg hooks [boolean]
98
+ --noFork Create backports in the origin repo [boolean]
99
+ --onlyMissing Only list commits with missing or unmerged backports
100
+ [boolean]
101
+ -p, --path Only list commits touching files under the specified path
102
+ [array]
103
+ --prDescription, --description Description to be added to pull request [string]
104
+ --prTitle, --title Title of pull request [string]
105
+ --prFilter Filter source pull requests by a query [string]
106
+ --pullNumber, --pr Pull request to backport [number]
107
+ --resetAuthor Set yourself as commit author [boolean]
108
+ --reviewer Add reviewer to the target PR [array]
109
+ --repoForkOwner The owner of the fork where the backport branch is pushed.
110
+ Defaults to the currently authenticated user [string]
111
+ --repo Repo owner and name [string]
112
+ --sha, --commit Commit sha to backport [string]
113
+ --sourceBranch Specify a non-default branch (normally \\"master\\") to backport
114
+ from [string]
115
+ --sourcePRLabel, --sourcePrLabel Add labels to the source (original) PR [array]
116
+ -b, --targetBranch, --branch Branch(es) to backport to [array]
117
+ --targetBranchChoice List branches to backport to [array]
118
+ -l, --targetPRLabel, --label Add labels to the target (backport) PR [array]
119
+ --verify Opposite of no-verify [boolean]
120
+ --help Show help [boolean]
121
+
122
+ For bugs, feature requests or questions: https://github.com/sqren/backport/issues
123
+ Or contact me directly: https://twitter.com/sorenlouv"
124
+ `);
125
+ });
126
+ it('should list commits based on .git/config when `repoOwner`/`repoName` is missing', async () => {
127
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
128
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
129
+ await (0, child_process_promisified_1.exec)(`git init`, { cwd: sandboxPath });
130
+ await (0, child_process_promisified_1.exec)(`git remote add origin git@github.com:backport-org/backport-e2e.git`, { cwd: sandboxPath });
131
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([`--accessToken=${accessToken}`], {
132
+ cwd: sandboxPath,
133
+ waitForString: 'Select commit',
134
+ });
135
+ expect(output).toMatchInlineSnapshot(`
136
+ "? Select commit (Use arrow keys)
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
146
+ 10.Add package.json"
147
+ `);
148
+ });
149
+ it(`should list commits from master`, async () => {
150
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
151
+ '--branch=foo',
152
+ '--repo=backport-org/backport-e2e',
153
+ '--author=sqren',
154
+ `--accessToken=${accessToken}`,
155
+ '--max-number=6',
156
+ ], { waitForString: 'Select commit' });
157
+ expect(output).toMatchInlineSnapshot(`
158
+ "? Select commit (Use arrow keys)
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
164
+ 6. Merge pull request #1 from backport-org/add-heart-emoji"
165
+ `);
166
+ });
167
+ it(`should filter commits by "since" and "until"`, async () => {
168
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
169
+ '--branch=foo',
170
+ '--repo=backport-org/backport-e2e',
171
+ `--accessToken=${accessToken}`,
172
+ '--since=2020-08-15T10:00:00.000Z',
173
+ '--until=2020-08-15T10:30:00.000Z',
174
+ ], { waitForString: 'Select commit' });
175
+ expect(output).toMatchInlineSnapshot(`
176
+ "? Select commit (Use arrow keys)
177
+ ❯ 1. Bump to 8.0.0
178
+ 2. Add package.json
179
+ 3. Update .backportrc.json
180
+ 4. Create .backportrc.json"
181
+ `);
182
+ });
183
+ it(`should list commits from 7.x`, async () => {
184
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
185
+ '--branch=foo',
186
+ '--repo=backport-org/backport-e2e',
187
+ '--author=sqren',
188
+ `--accessToken=${accessToken}`,
189
+ '--max-number=6',
190
+ '--source-branch=7.x',
191
+ ], { waitForString: 'Select commit' });
192
+ expect(output).toMatchInlineSnapshot(`
193
+ "? Select commit (Use arrow keys)
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)
199
+ 6. Bump to 8.0.0"
200
+ `);
201
+ });
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)', () => {
286
+ it(`when access token is missing`, async () => {
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);
324
+ const backportResult = JSON.parse(output);
325
+ expect(backportResult.status).toBe('failure');
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
+ `);
331
+ });
332
+ it(`when argument is invalid`, async () => {
333
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)(['--json', '--foo'], {});
334
+ const backportResult = JSON.parse(output);
335
+ expect(backportResult.status).toBe('failure');
336
+ expect(backportResult.errorMessage).toEqual('Unknown argument: foo');
337
+ });
338
+ it('when `--repo` is invalid', async () => {
339
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
340
+ '--json',
341
+ '--repo=backport-org/backport-e2e-foo',
342
+ `--accessToken=${accessToken}`,
343
+ ]);
344
+ const backportResult = JSON.parse(output);
345
+ expect(backportResult.status).toBe('failure');
346
+ expect(backportResult.errorMessage).toEqual('The repository "backport-org/backport-e2e-foo" doesn\'t exist');
347
+ });
348
+ it('when `--sha` is invalid', async () => {
349
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
350
+ '--json',
351
+ '--repo=backport-org/backport-e2e',
352
+ '--sha=abcdefg',
353
+ `--accessToken=${accessToken}`,
354
+ ]);
355
+ const backportResult = JSON.parse(output);
356
+ expect(backportResult.status).toBe('failure');
357
+ expect(backportResult.errorMessage).toEqual('No commit found on branch "master" with sha "abcdefg"');
358
+ });
359
+ it('when `--branch` is invalid', async () => {
360
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
361
+ '--json',
362
+ '--repo=backport-org/backport-e2e',
363
+ '--pr=9',
364
+ '--branch=foobar',
365
+ `--accessToken=${accessToken}`,
366
+ ]);
367
+ const backportResult = JSON.parse(output);
368
+ expect(backportResult.status).toBe('success');
369
+ expect(backportResult.results[0]).toEqual({
370
+ error: {
371
+ errorContext: {
372
+ code: 'message-only-exception',
373
+ message: 'The branch "foobar" is invalid or doesn\'t exist',
374
+ },
375
+ name: 'BackportError',
376
+ },
377
+ status: 'handled-error',
378
+ targetBranch: 'foobar',
379
+ });
380
+ });
381
+ it('when `--pr` is invalid', async () => {
382
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
383
+ '--json',
384
+ '--repo=backport-org/backport-e2e',
385
+ '--pr=900',
386
+ '--branch=foobar',
387
+ `--accessToken=${accessToken}`,
388
+ ]);
389
+ const backportResult = JSON.parse(output);
390
+ expect(backportResult.status).toEqual('failure');
391
+ expect(backportResult.errorMessage).toEqual('Could not resolve to a PullRequest with the number of 900. (Github API v4)');
392
+ });
393
+ it('when having conflicts in non-interactive mode', async () => {
394
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
395
+ '--json',
396
+ '--repo=backport-org/repo-with-conflicts',
397
+ '--pr=12',
398
+ '--branch=7.x',
399
+ `--accessToken=${accessToken}`,
400
+ ]);
401
+ const backportResult = JSON.parse(output);
402
+ expect(backportResult.status).toEqual('success');
403
+ expect(
404
+ //@ts-expect-error
405
+ backportResult.results[0].error.errorContext.conflictingFiles).toEqual(['la-liga.md']);
406
+ });
407
+ it('when `--source-branch` is invalid', async () => {
408
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
409
+ '--json',
410
+ '--repo=backport-org/backport-e2e',
411
+ '--pr=9',
412
+ '--branch=7.x',
413
+ '--source-branch=foo',
414
+ `--accessToken=${accessToken}`,
415
+ ]);
416
+ const backportResult = JSON.parse(output);
417
+ expect(backportResult.status).toBe('success');
418
+ expect(backportResult.results[0]).toEqual({
419
+ error: {
420
+ context: {
421
+ cmdArgs: ['checkout', 'foo'],
422
+ code: 1,
423
+ stderr: "error: pathspec 'foo' did not match any file(s) known to git\n",
424
+ stdout: '',
425
+ },
426
+ name: 'SpawnError',
427
+ },
428
+ status: 'unhandled-error',
429
+ targetBranch: '7.x',
430
+ });
431
+ });
432
+ it('when PR is not merged', async () => {
433
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
434
+ '--json',
435
+ '--repo=backport-org/backport-e2e',
436
+ '--pr=12',
437
+ `--accessToken=${accessToken}`,
438
+ ]);
439
+ const backportResult = JSON.parse(output);
440
+ expect(backportResult.status).toBe('failure');
441
+ expect(backportResult.error).toEqual({
442
+ errorContext: {
443
+ code: 'message-only-exception',
444
+ message: 'The PR #12 is not merged',
445
+ },
446
+ name: 'BackportError',
447
+ });
448
+ });
449
+ });
450
+ });
@@ -4,46 +4,45 @@ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
4
4
  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
- it('should list commits', async () => {
8
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
7
+ it('lists commits', async () => {
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
- it('should attempt to backport by PR', async () => {
25
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
26
- '--branch=foo',
24
+ it('backports via pr', async () => {
25
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
26
+ '--branch=production',
27
27
  '--repo=backport-org/repo-with-backportrc-removed',
28
28
  '--pr=1',
29
29
  `--accessToken=${accessToken}`,
30
- ], { waitForString: "is invalid or doesn't exist" });
31
- expect(output).toMatchInlineSnapshot(`
32
- "
33
- Backporting to foo:
34
- The branch \\"foo\\" is invalid or doesn't exist"
35
- `);
30
+ '--dry-run',
31
+ ], {
32
+ showOra: true,
33
+ });
34
+ expect(output).toContain('Cherry-picking: Merge pull request #1 from backport-org/add-readme');
36
35
  });
37
- it('should attempt to backport by commit sha', async () => {
38
- const output = await (0, runBackportViaCli_1.runBackportViaCli)([
39
- '--branch=foo',
36
+ it('backport by commit sha', async () => {
37
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
38
+ '--branch=production',
40
39
  '--repo=backport-org/repo-with-backportrc-removed',
41
40
  '--sha=be59df6912a550c8cb49ba3e18be3e512f3d608c',
42
41
  `--accessToken=${accessToken}`,
43
- ], { waitForString: `Backporting to foo:` });
44
- expect(output).toMatchInlineSnapshot(`
45
- "
46
- Backporting to foo:"
47
- `);
42
+ '--dry-run',
43
+ ], {
44
+ showOra: true,
45
+ });
46
+ expect(output).toContain('Cherry-picking: Create README.me');
48
47
  });
49
48
  });
@@ -1,5 +1,9 @@
1
- export declare function runBackportViaCli(cliArgs: string[], { showOra, waitForString, cwd, }?: {
1
+ export declare function runBackportViaCli(backportArgs: string[], { timeoutSeconds, showOra, waitForString, cwd, }?: {
2
+ timeoutSeconds?: number;
2
3
  showOra?: boolean;
3
4
  waitForString?: string;
4
5
  cwd?: string;
5
- }): Promise<string>;
6
+ }): Promise<{
7
+ output: string;
8
+ code: number | null;
9
+ }>;
@@ -8,41 +8,62 @@ const child_process_1 = require("child_process");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const lodash_1 = require("lodash");
10
10
  const strip_ansi_1 = __importDefault(require("strip-ansi"));
11
- const TIMEOUT_IN_SECONDS = 15;
12
- jest.setTimeout(TIMEOUT_IN_SECONDS * 1000);
13
- function runBackportViaCli(cliArgs, { showOra, waitForString, cwd, } = {}) {
11
+ const sandbox_1 = require("../../sandbox");
12
+ jest.setTimeout(15000);
13
+ function runBackportViaCli(backportArgs, { timeoutSeconds = 2, showOra, waitForString, cwd, } = {}) {
14
14
  const tsNodeBinary = path_1.default.resolve('./node_modules/.bin/ts-node');
15
15
  const entrypointFile = path_1.default.resolve('./src/entrypoint.cli.ts');
16
- const proc = (0, child_process_1.spawn)(tsNodeBinary, [
16
+ const randomString = Math.random().toString(36).slice(2);
17
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({
18
+ filename: __filename,
19
+ specname: randomString,
20
+ });
21
+ (0, sandbox_1.resetSandbox)(sandboxPath);
22
+ const cmdArgs = [
17
23
  '--transpile-only',
18
24
  entrypointFile,
19
- '--log-file-path',
20
- '/dev/null',
21
- ...cliArgs,
22
- ], { cwd });
25
+ '--log-file-path=/dev/null',
26
+ ...(backportArgs.some((arg) => arg.includes('--dir'))
27
+ ? []
28
+ : [`--dir=${sandboxPath}`]),
29
+ ...backportArgs,
30
+ ];
31
+ const proc = (0, child_process_1.spawn)(tsNodeBinary, cmdArgs, { cwd });
23
32
  return new Promise((resolve, reject) => {
24
33
  let data = '';
25
- const timeoutSeconds = 2;
26
- const rejectOnTimeout = (0, lodash_1.debounce)(() => {
27
- reject(`Expectation '${waitForString}' not found within ${timeoutSeconds} second in:\n\n${data.toString()}`);
34
+ const postponeTimeout = (0, lodash_1.debounce)(() => {
35
+ const formattedData = formatData(data);
36
+ const cmd = [tsNodeBinary, ...cmdArgs].join(' ');
37
+ reject(waitForString
38
+ ? `Expectation '${waitForString}' not found within ${timeoutSeconds} second in:\n\n${formattedData}\n\nCommand: ${cmd}`
39
+ : `Timeout. Received:\n${formattedData}\n\nCommand: ${cmd}`);
28
40
  }, timeoutSeconds * 1000, { maxWait: 15000 });
29
- // fail if expectations hasn't been found within 10 seconds
41
+ function formatData(data) {
42
+ return (0, strip_ansi_1.default)(data.toString()).trim();
43
+ }
30
44
  const onChunk = (chunk) => {
31
45
  data += chunk;
32
- const stringfiedData = data.toString();
33
- rejectOnTimeout();
34
- // remove ansi codes and whitespace
35
- const output = (0, strip_ansi_1.default)(stringfiedData).replace(/\s+$/gm, '');
36
- if (!waitForString || output.includes(waitForString)) {
37
- rejectOnTimeout.cancel();
38
- resolve(output);
46
+ const output = formatData(data);
47
+ if (waitForString && output.includes(waitForString)) {
48
+ postponeTimeout.cancel();
49
+ resolve({ output, code: null });
39
50
  }
40
51
  };
41
- proc.stdout.on('data', onChunk);
52
+ proc.on('exit', (code) => {
53
+ postponeTimeout.cancel();
54
+ resolve({ output: formatData(data), code });
55
+ });
56
+ proc.stdout.on('data', (chunk) => {
57
+ postponeTimeout();
58
+ onChunk(chunk);
59
+ });
42
60
  // ora (loading spinner) is redirected to stderr
43
- if (showOra) {
44
- proc.stderr.on('data', onChunk);
45
- }
61
+ proc.stderr.on('data', (chunk) => {
62
+ postponeTimeout();
63
+ if (showOra) {
64
+ onChunk(chunk);
65
+ }
66
+ });
46
67
  proc.on('error', (err) => {
47
68
  reject(`runBackportViaCli failed with: ${err}`);
48
69
  });