backport 8.3.0 → 8.4.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 (238) hide show
  1. package/README.md +11 -178
  2. package/dist/backportRun.js +1 -1
  3. package/dist/entrypoint.module.d.ts +2 -2
  4. package/dist/entrypoint.module.js +2 -0
  5. package/dist/entrypoint.module.private.test.js +11 -10
  6. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +30 -20
  7. package/dist/lib/child-process-promisified.js +2 -2
  8. package/dist/lib/getCommits.js +1 -1
  9. package/dist/lib/git.d.ts +1 -1
  10. package/dist/lib/git.js +8 -28
  11. package/dist/lib/git.private.test.js +7 -7
  12. package/dist/lib/git.test.js +28 -12
  13. package/dist/lib/github/v3/createStatusComment.js +3 -2
  14. package/dist/lib/github/v3/createStatusComment.test.js +61 -0
  15. package/dist/lib/github/v4/apiRequestV4.js +1 -1
  16. package/dist/lib/github/v4/enablePullRequestAutoMerge.js +2 -1
  17. package/dist/{entrypoint.cli.private.test.d.ts → lib/github/v4/enablePullRequestAutoMerge.mutation.test.d.ts} +0 -0
  18. package/dist/lib/github/v4/{enablePullRequestAutoMerge.private.test.js → enablePullRequestAutoMerge.mutation.test.js} +34 -8
  19. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +6 -3
  20. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -1
  21. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +0 -1
  22. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +5 -6
  23. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +7 -3
  24. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +2 -0
  25. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +23 -7
  26. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -0
  27. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +1 -0
  28. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +2 -0
  29. package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +1 -0
  30. package/dist/lib/github/v4/getOptionsFromGithub/query.js +1 -0
  31. package/dist/lib/ora.d.ts +1 -0
  32. package/dist/lib/remoteConfig.d.ts +1 -1
  33. package/dist/lib/remoteConfig.js +4 -0
  34. package/dist/options/ConfigOptions.d.ts +1 -0
  35. package/dist/options/cliArgs.d.ts +3 -2
  36. package/dist/options/cliArgs.js +21 -6
  37. package/dist/options/config/config.d.ts +1 -0
  38. package/dist/options/config/readConfigFile.d.ts +1 -0
  39. package/dist/options/options.d.ts +5 -2
  40. package/dist/options/options.js +3 -3
  41. package/dist/options/options.test.js +7 -4
  42. package/dist/{lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts → test/e2e/cli/date-filters.private.test.d.ts} +0 -0
  43. package/dist/test/e2e/cli/date-filters.private.test.js +48 -0
  44. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +120 -4
  45. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +4 -18
  46. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +2 -1
  47. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +3 -2
  48. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +2 -2
  49. package/dist/test/e2e/cli/runBackportViaCli.d.ts +8 -2
  50. package/dist/test/e2e/cli/runBackportViaCli.js +47 -17
  51. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +1 -0
  52. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +1 -1
  53. package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -1
  54. package/dist/utils/packageVersion.d.ts +1 -1
  55. package/dist/utils/packageVersion.js +1 -1
  56. package/package.json +20 -21
  57. package/yarn.lock +210 -220
  58. package/dist/entrypoint.cli.private.test.js +0 -47
  59. package/dist/errors/BackportError.d.ts +0 -19
  60. package/dist/errors/BackportError.js +0 -29
  61. package/dist/runSequentially.test.d.ts +0 -1
  62. package/dist/runSequentially.test.js +0 -243
  63. package/dist/services/BackportError.d.ts +0 -19
  64. package/dist/services/BackportError.js +0 -29
  65. package/dist/services/HandledBackportError.d.ts +0 -19
  66. package/dist/services/HandledBackportError.js +0 -29
  67. package/dist/services/HandledError.d.ts +0 -19
  68. package/dist/services/HandledError.js +0 -29
  69. package/dist/services/child-process-promisified.d.ts +0 -25
  70. package/dist/services/child-process-promisified.js +0 -58
  71. package/dist/services/env.d.ts +0 -7
  72. package/dist/services/env.js +0 -30
  73. package/dist/services/env.test.d.ts +0 -1
  74. package/dist/services/env.test.js +0 -21
  75. package/dist/services/git.d.ts +0 -77
  76. package/dist/services/git.integration.test.d.ts +0 -1
  77. package/dist/services/git.integration.test.js +0 -616
  78. package/dist/services/git.js +0 -439
  79. package/dist/services/git.private.test.d.ts +0 -1
  80. package/dist/services/git.private.test.js +0 -618
  81. package/dist/services/git.test.d.ts +0 -1
  82. package/dist/services/git.test.js +0 -580
  83. package/dist/services/github/commitFormatters.d.ts +0 -3
  84. package/dist/services/github/commitFormatters.js +0 -17
  85. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  86. package/dist/services/github/commitFormatters.test.js +0 -11
  87. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +0 -2
  88. package/dist/services/github/v3/addAssigneesToPullRequest.js +0 -32
  89. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  90. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  91. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +0 -2
  92. package/dist/services/github/v3/addLabelsToPullRequest.js +0 -30
  93. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +0 -2
  94. package/dist/services/github/v3/addReviewersToPullRequest.js +0 -32
  95. package/dist/services/github/v3/createPullRequest.d.ts +0 -29
  96. package/dist/services/github/v3/createPullRequest.js +0 -91
  97. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  98. package/dist/services/github/v3/createPullRequest.test.js +0 -377
  99. package/dist/services/github/v3/createStatusComment.d.ts +0 -11
  100. package/dist/services/github/v3/createStatusComment.js +0 -131
  101. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  102. package/dist/services/github/v3/createStatusComment.test.js +0 -409
  103. package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +0 -14
  104. package/dist/services/github/v3/getGithubV3ErrorMessage.js +0 -16
  105. package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -2
  106. package/dist/services/github/v4/FetchPullRequestId.js +0 -36
  107. package/dist/services/github/v4/apiRequestV4.d.ts +0 -31
  108. package/dist/services/github/v4/apiRequestV4.js +0 -71
  109. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  110. package/dist/services/github/v4/apiRequestV4.test.js +0 -109
  111. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -2
  112. package/dist/services/github/v4/disablePullRequestAutoMerge.js +0 -32
  113. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -2
  114. package/dist/services/github/v4/enablePullRequestAutoMerge.js +0 -50
  115. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  116. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  117. package/dist/services/github/v4/fetchAuthorId.d.ts +0 -10
  118. package/dist/services/github/v4/fetchAuthorId.js +0 -28
  119. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  120. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -25
  121. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  122. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
  123. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -11
  124. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -58
  125. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  126. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -136
  127. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -11
  128. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +0 -48
  129. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  130. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -118
  131. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -29
  132. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +0 -110
  133. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  134. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -196
  135. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  136. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -157
  137. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +0 -3
  138. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +0 -61
  139. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  140. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -107
  141. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +0 -12
  142. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +0 -69
  143. package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -9
  144. package/dist/services/github/v4/fetchExistingPullRequest.js +0 -64
  145. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  146. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -44
  147. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -2
  148. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +0 -39
  149. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +0 -8
  150. package/dist/services/github/v4/fetchRemoteProjectConfig.js +0 -49
  151. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  152. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -49
  153. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +0 -69
  154. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -73
  155. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  156. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -116
  157. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +0 -16
  158. package/dist/services/github/v4/getOptionsFromGithub/query.js +0 -29
  159. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +0 -29
  160. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +0 -61
  161. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  162. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -72
  163. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  164. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -176
  165. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +0 -6
  166. package/dist/services/github/v4/throwOnInvalidAccessToken.js +0 -45
  167. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  168. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  169. package/dist/services/logger.d.ts +0 -9
  170. package/dist/services/logger.js +0 -74
  171. package/dist/services/prompt.test.d.ts +0 -1
  172. package/dist/services/prompt.test.js +0 -139
  173. package/dist/services/prompts.d.ts +0 -17
  174. package/dist/services/prompts.js +0 -132
  175. package/dist/services/remoteConfig.d.ts +0 -20
  176. package/dist/services/remoteConfig.js +0 -52
  177. package/dist/services/sequentially.d.ts +0 -1
  178. package/dist/services/sequentially.js +0 -10
  179. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
  180. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +0 -102
  181. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  182. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -467
  183. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +0 -26
  184. package/dist/services/sourceCommit/getMockSourceCommit.js +0 -103
  185. package/dist/services/sourceCommit/parseSourceCommit.d.ts +0 -108
  186. package/dist/services/sourceCommit/parseSourceCommit.js +0 -123
  187. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  188. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -226
  189. package/dist/services/test.d.ts +0 -1
  190. package/dist/services/test.js +0 -23
  191. package/dist/state.d.ts +0 -0
  192. package/dist/state.js +0 -1
  193. package/dist/test/ExecError.d.ts +0 -16
  194. package/dist/test/ExecError.js +0 -15
  195. package/dist/test/e2e/cli/cli.private.test.d.ts +0 -1
  196. package/dist/test/e2e/cli/cli.private.test.js +0 -222
  197. package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +0 -1
  198. package/dist/test/e2e/cli/interactive-error-handling.private.test.js +0 -80
  199. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +0 -1
  200. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +0 -198
  201. package/dist/test/e2e/cli.e2e.private.test.d.ts +0 -1
  202. package/dist/test/e2e/cli.e2e.private.test.js +0 -433
  203. package/dist/test/e2e/module/module.mutation.test.d.ts +0 -1
  204. package/dist/test/e2e/module/module.mutation.test.js +0 -369
  205. package/dist/test/e2e/module.e2e.mutation.test.d.ts +0 -1
  206. package/dist/test/e2e/module.e2e.mutation.test.js +0 -369
  207. package/dist/test/e2e/module.e2e.private.test.d.ts +0 -1
  208. package/dist/test/e2e/module.e2e.private.test.js +0 -369
  209. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -13
  210. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +0 -243
  211. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  212. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -320
  213. package/dist/ui/getCommits.d.ts +0 -2
  214. package/dist/ui/getCommits.js +0 -75
  215. package/dist/ui/getCommitsWithoutBackports.d.ts +0 -11
  216. package/dist/ui/getCommitsWithoutBackports.js +0 -68
  217. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  218. package/dist/ui/getCommitsWithoutBackports.test.js +0 -335
  219. package/dist/ui/getGitConfigAuthor.d.ts +0 -6
  220. package/dist/ui/getGitConfigAuthor.js +0 -15
  221. package/dist/ui/getTargetBranches.d.ts +0 -5
  222. package/dist/ui/getTargetBranches.js +0 -67
  223. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  224. package/dist/ui/getTargetBranches.test.js +0 -204
  225. package/dist/ui/maybeSetupRepo.d.ts +0 -2
  226. package/dist/ui/maybeSetupRepo.js +0 -53
  227. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  228. package/dist/ui/maybeSetupRepo.test.js +0 -238
  229. package/dist/ui/ora.d.ts +0 -2
  230. package/dist/ui/ora.js +0 -21
  231. package/dist/ui/setupRepo.d.ts +0 -2
  232. package/dist/ui/setupRepo.js +0 -56
  233. package/dist/ui/setupRepo.test.d.ts +0 -1
  234. package/dist/ui/setupRepo.test.js +0 -273
  235. package/dist/utils/filterMissingCommits.d.ts +0 -2
  236. package/dist/utils/filterMissingCommits.js +0 -7
  237. package/dist/utils/redact.d.ts +0 -1
  238. package/dist/utils/redact.js +0 -7
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.maybeSetupRepo = void 0;
4
- const del = require("del");
5
- const HandledError_1 = require("../services/HandledError");
6
- const env_1 = require("../services/env");
7
- const git_1 = require("../services/git");
8
- const ora_1 = require("./ora");
9
- async function maybeSetupRepo(options) {
10
- const repoPath = (0, env_1.getRepoPath)(options);
11
- const isAlreadyCloned = await getIsRepoCloned(options);
12
- if (options.cwd.includes(repoPath)) {
13
- throw new HandledError_1.HandledError(`Refusing to clone repo into "${repoPath}" when current working directory is "${options.cwd}". Please change backport directory via \`--dir\` option or run backport from another location`);
14
- }
15
- // clone repo if folder does not already exists
16
- if (!isAlreadyCloned) {
17
- const spinner = (0, ora_1.ora)(options.ci).start();
18
- try {
19
- const sourcePath = await (0, git_1.getSourceRepoPath)(options);
20
- const sourcePathHumanReadable = sourcePath.includes(options.gitHostname)
21
- ? options.gitHostname
22
- : sourcePath;
23
- const spinnerCloneText = `Cloning repository from ${sourcePathHumanReadable} (one-time operation)`;
24
- spinner.text = `0% ${spinnerCloneText}`;
25
- await del(repoPath, { force: true });
26
- await (0, git_1.cloneRepo)({ sourcePath, targetPath: repoPath }, (progress) => {
27
- spinner.text = `${progress}% ${spinnerCloneText}`;
28
- });
29
- spinner.succeed(`100% ${spinnerCloneText}`);
30
- }
31
- catch (e) {
32
- spinner.fail();
33
- await del(repoPath, { force: true });
34
- throw e;
35
- }
36
- }
37
- // delete default "origin" remote to avoid confusion
38
- await (0, git_1.deleteRemote)(options, 'origin');
39
- // ensure remote are setup with latest accessToken
40
- await (0, git_1.deleteRemote)(options, options.authenticatedUsername);
41
- await (0, git_1.addRemote)(options, options.authenticatedUsername);
42
- // add remote for non-fork repo (if the above is a fork)
43
- if (options.authenticatedUsername !== options.repoOwner) {
44
- await (0, git_1.deleteRemote)(options, options.repoOwner);
45
- await (0, git_1.addRemote)(options, options.repoOwner);
46
- }
47
- }
48
- exports.maybeSetupRepo = maybeSetupRepo;
49
- async function getIsRepoCloned(options) {
50
- const repoPath = (0, env_1.getRepoPath)(options);
51
- const projectRoot = await (0, git_1.getGitProjectRoot)(repoPath);
52
- return repoPath === projectRoot;
53
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,238 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- const os_1 = __importDefault(require("os"));
26
- const del_1 = __importDefault(require("del"));
27
- const childProcess = __importStar(require("../services/child-process-promisified"));
28
- const git = __importStar(require("../services/git"));
29
- const mocks_1 = require("../test/mocks");
30
- const maybeSetupRepo_1 = require("./maybeSetupRepo");
31
- describe('maybeSetupRepo', () => {
32
- let execSpy;
33
- beforeEach(() => {
34
- jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
35
- execSpy = jest
36
- .spyOn(childProcess, 'exec')
37
- .mockResolvedValue({ stderr: '', stdout: '' });
38
- });
39
- afterEach(() => {
40
- jest.restoreAllMocks();
41
- });
42
- describe('if an error occurs while cloning', () => {
43
- it('should delete repo', async () => {
44
- expect.assertions(2);
45
- execSpy = jest
46
- .spyOn(childProcess, 'execAsCallback')
47
- .mockImplementation((cmd) => {
48
- if (cmd.startsWith('git clone')) {
49
- throw new Error('Simulated git clone failure');
50
- }
51
- throw new Error('unknown error');
52
- });
53
- await expect((0, maybeSetupRepo_1.maybeSetupRepo)({
54
- repoName: 'kibana',
55
- repoOwner: 'elastic',
56
- cwd: '/path/to/source/repo',
57
- })).rejects.toThrowError('Simulated git clone failure');
58
- expect(del_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories/elastic/kibana', { force: true });
59
- });
60
- });
61
- describe('while cloning the repo', () => {
62
- it('updates the progress', async () => {
63
- let onCloneComplete;
64
- let dataHandler;
65
- const oraMock = (0, mocks_1.getOraMock)();
66
- const spinnerTextSpy = jest.spyOn(oraMock, 'text', 'set');
67
- const spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
68
- jest
69
- .spyOn(git, 'getSourceRepoPath')
70
- .mockResolvedValue('/path/to/source/repo');
71
- jest
72
- .spyOn(childProcess, 'execAsCallback')
73
- //@ts-expect-error
74
- .mockImplementation((cmdString, cmdOptions, onComplete) => {
75
- // callback should be called to finalize the operation
76
- if (onComplete) {
77
- //@ts-expect-error
78
- onCloneComplete = onComplete;
79
- }
80
- return {
81
- stderr: {
82
- on: (name, handler) => {
83
- dataHandler = handler;
84
- },
85
- },
86
- };
87
- });
88
- setTimeout(() => {
89
- dataHandler('Receiving objects: 1%');
90
- dataHandler('Receiving objects: 10%');
91
- dataHandler('Receiving objects: 20%');
92
- dataHandler('Receiving objects: 100%');
93
- dataHandler('Updating files: 1%');
94
- dataHandler('Updating files: 10%');
95
- dataHandler('Updating files: 20%');
96
- dataHandler('Updating files: 100%');
97
- onCloneComplete();
98
- }, 50);
99
- await (0, maybeSetupRepo_1.maybeSetupRepo)({
100
- repoName: 'kibana',
101
- repoOwner: 'elastic',
102
- cwd: '/path/to/source/repo',
103
- });
104
- expect(spinnerTextSpy.mock.calls.map((call) => call[0]))
105
- .toMatchInlineSnapshot(`
106
- Array [
107
- "0% Cloning repository from /path/to/source/repo (one-time operation)",
108
- "1% Cloning repository from /path/to/source/repo (one-time operation)",
109
- "9% Cloning repository from /path/to/source/repo (one-time operation)",
110
- "18% Cloning repository from /path/to/source/repo (one-time operation)",
111
- "90% Cloning repository from /path/to/source/repo (one-time operation)",
112
- "90% Cloning repository from /path/to/source/repo (one-time operation)",
113
- "91% Cloning repository from /path/to/source/repo (one-time operation)",
114
- "92% Cloning repository from /path/to/source/repo (one-time operation)",
115
- "100% Cloning repository from /path/to/source/repo (one-time operation)",
116
- ]
117
- `);
118
- expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from /path/to/source/repo (one-time operation)');
119
- });
120
- });
121
- describe('if repo already exists', () => {
122
- beforeEach(() => {
123
- jest
124
- .spyOn(childProcess, 'execAsCallback')
125
- //@ts-expect-error
126
- .mockImplementation((cmdString, cmdOptions, callback) => {
127
- //@ts-expect-error
128
- callback();
129
- return {
130
- stderr: { on: () => null },
131
- };
132
- });
133
- });
134
- it('should re-create remotes for both source repo and fork', async () => {
135
- await (0, maybeSetupRepo_1.maybeSetupRepo)({
136
- accessToken: 'myAccessToken',
137
- authenticatedUsername: 'sqren_authenticated',
138
- repoName: 'kibana',
139
- repoOwner: 'elastic',
140
- cwd: '/path/to/source/repo',
141
- });
142
- expect(execSpy.mock.calls.map(([cmd, { cwd }]) => ({ cmd, cwd }))).toEqual([
143
- {
144
- cmd: 'git rev-parse --show-toplevel',
145
- cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
146
- },
147
- {
148
- cmd: 'git remote --verbose',
149
- cwd: '/path/to/source/repo',
150
- },
151
- {
152
- cmd: 'git remote rm origin',
153
- cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
154
- },
155
- {
156
- cmd: 'git remote rm sqren_authenticated',
157
- cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
158
- },
159
- {
160
- cmd: 'git remote add sqren_authenticated https://x-access-token:myAccessToken@github.com/sqren_authenticated/kibana.git',
161
- cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
162
- },
163
- {
164
- cmd: 'git remote rm elastic',
165
- cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
166
- },
167
- {
168
- cmd: 'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
169
- cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
170
- },
171
- ]);
172
- });
173
- });
174
- describe('if repo does not exists locally', () => {
175
- beforeEach(() => {
176
- jest
177
- .spyOn(childProcess, 'execAsCallback')
178
- //@ts-expect-error
179
- .mockImplementation((cmdString, cmdOptions, callback) => {
180
- //@ts-expect-error
181
- callback();
182
- return {
183
- stderr: { on: () => null },
184
- };
185
- });
186
- });
187
- it('should clone it from github.com', async () => {
188
- await (0, maybeSetupRepo_1.maybeSetupRepo)({
189
- accessToken: 'myAccessToken',
190
- gitHostname: 'github.com',
191
- repoName: 'kibana',
192
- repoOwner: 'elastic',
193
- cwd: '/path/to/source/repo',
194
- });
195
- expect(childProcess.execAsCallback).toHaveBeenCalledWith('git clone https://x-access-token:myAccessToken@github.com/elastic/kibana.git /myHomeDir/.backport/repositories/elastic/kibana --progress', expect.any(Object), expect.any(Function));
196
- });
197
- });
198
- describe('if repo does exist locally', () => {
199
- beforeEach(() => {
200
- jest
201
- .spyOn(git, 'getSourceRepoPath')
202
- .mockResolvedValue('/path/to/source/repo');
203
- jest
204
- .spyOn(childProcess, 'execAsCallback')
205
- //@ts-expect-error
206
- .mockImplementation((cmdString, cmdOptions, callback) => {
207
- //@ts-expect-error
208
- callback();
209
- return {
210
- stderr: { on: () => null },
211
- };
212
- });
213
- });
214
- it('should clone it from local folder', async () => {
215
- await (0, maybeSetupRepo_1.maybeSetupRepo)({
216
- repoName: 'kibana',
217
- repoOwner: 'elastic',
218
- cwd: '/path/to/source/repo',
219
- });
220
- expect(childProcess.execAsCallback).toHaveBeenCalledWith('git clone /path/to/source/repo /myHomeDir/.backport/repositories/elastic/kibana --progress', expect.any(Object), expect.any(Function));
221
- });
222
- });
223
- describe('if `repoPath` is a parent of current working directory (cwd)', () => {
224
- beforeEach(() => {
225
- jest
226
- .spyOn(git, 'getSourceRepoPath')
227
- .mockResolvedValue('/path/to/source/repo');
228
- jest.spyOn(childProcess, 'execAsCallback');
229
- });
230
- it('should clone it from local folder', async () => {
231
- await expect(() => (0, maybeSetupRepo_1.maybeSetupRepo)({
232
- repoName: 'kibana',
233
- repoOwner: 'elastic',
234
- cwd: '/myHomeDir/.backport/repositories/elastic/kibana/foo',
235
- })).rejects.toThrowError('Refusing to clone repo into "/myHomeDir/.backport/repositories/elastic/kibana" when current working directory is "/myHomeDir/.backport/repositories/elastic/kibana/foo". Please change backport directory via `--dir` option or run backport from another location');
236
- });
237
- });
238
- });
package/dist/ui/ora.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import oraOriginal from 'ora';
2
- export declare function ora(ci: boolean | undefined, text?: string | undefined): oraOriginal.Ora;
package/dist/ui/ora.js DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ora = void 0;
7
- const ora_1 = __importDefault(require("ora"));
8
- /* eslint-disable @typescript-eslint/no-empty-function */
9
- const oraMock = {
10
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
- start: (text) => oraMock,
12
- succeed: () => { },
13
- stop: () => { },
14
- fail: () => { },
15
- stopAndPersist: () => { },
16
- set text(value) { },
17
- };
18
- function ora(ci, text) {
19
- return ci ? oraMock : (0, ora_1.default)({ text });
20
- }
21
- exports.ora = ora;
@@ -1,2 +0,0 @@
1
- import { ValidConfigOptions } from '../options/options';
2
- export declare function setupRepo(options: ValidConfigOptions): Promise<void>;
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setupRepo = void 0;
4
- const del = require("del");
5
- const BackportError_1 = require("../services/BackportError");
6
- const env_1 = require("../services/env");
7
- const git_1 = require("../services/git");
8
- const ora_1 = require("./ora");
9
- async function setupRepo(options) {
10
- const repoPath = (0, env_1.getRepoPath)(options);
11
- const isAlreadyCloned = await getIsRepoCloned(options);
12
- if (options.cwd.includes(repoPath)) {
13
- throw new BackportError_1.BackportError(`Refusing to clone repo into "${repoPath}" when current working directory is "${options.cwd}". Please change backport directory via \`--dir\` option or run backport from another location`);
14
- }
15
- // clone repo if folder does not already exists
16
- if (!isAlreadyCloned) {
17
- const spinner = (0, ora_1.ora)(options.ci).start();
18
- try {
19
- const localRepoPath = await (0, git_1.getLocalSourceRepoPath)(options);
20
- const remoteRepoPath = (0, git_1.getRemoteUrl)(options, options.repoOwner);
21
- const sourcePath = localRepoPath ? localRepoPath : remoteRepoPath;
22
- // show the full path for local repos, but only the host name for remote repos (to avoid showing the access token)
23
- const sourcePathHumanReadable = !localRepoPath
24
- ? options.gitHostname
25
- : sourcePath;
26
- const spinnerCloneText = `Cloning repository from ${sourcePathHumanReadable} (one-time operation)`;
27
- spinner.text = `0% ${spinnerCloneText}`;
28
- await del(repoPath, { force: true });
29
- await (0, git_1.cloneRepo)({ sourcePath, targetPath: repoPath }, (progress) => {
30
- spinner.text = `${progress}% ${spinnerCloneText}`;
31
- });
32
- spinner.succeed(`100% ${spinnerCloneText}`);
33
- }
34
- catch (e) {
35
- spinner.fail();
36
- await del(repoPath, { force: true });
37
- throw e;
38
- }
39
- }
40
- // delete default "origin" remote to avoid confusion
41
- await (0, git_1.deleteRemote)(options, 'origin');
42
- // ensure remote are setup with latest accessToken
43
- await (0, git_1.deleteRemote)(options, options.repoForkOwner);
44
- await (0, git_1.addRemote)(options, options.repoForkOwner);
45
- // add remote for non-fork repo (if the above is a fork)
46
- if (options.repoForkOwner !== options.repoOwner) {
47
- await (0, git_1.deleteRemote)(options, options.repoOwner);
48
- await (0, git_1.addRemote)(options, options.repoOwner);
49
- }
50
- }
51
- exports.setupRepo = setupRepo;
52
- async function getIsRepoCloned(options) {
53
- const repoPath = (0, env_1.getRepoPath)(options);
54
- const projectRoot = await (0, git_1.getGitProjectRootPath)(repoPath);
55
- return repoPath === projectRoot;
56
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,273 +0,0 @@
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 os_1 = __importDefault(require("os"));
30
- const del_1 = __importDefault(require("del"));
31
- const childProcess = __importStar(require("../services/child-process-promisified"));
32
- const gitModule = __importStar(require("../services/git"));
33
- const mocks_1 = require("../test/mocks");
34
- const setupRepo_1 = require("./setupRepo");
35
- describe('setupRepo', () => {
36
- let spawnSpy;
37
- beforeEach(() => {
38
- jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
39
- spawnSpy = jest
40
- .spyOn(childProcess, 'spawnPromise')
41
- .mockResolvedValue({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
42
- });
43
- afterEach(() => {
44
- jest.restoreAllMocks();
45
- });
46
- describe('if an error occurs while cloning', () => {
47
- it('should delete repo', async () => {
48
- expect.assertions(2);
49
- jest
50
- .spyOn(childProcess, 'spawnOriginal')
51
- .mockImplementation((cmd, cmdArgs) => {
52
- if (cmdArgs.includes('clone')) {
53
- throw new Error('Simulated git clone failure');
54
- }
55
- throw new Error('unknown error');
56
- });
57
- await expect((0, setupRepo_1.setupRepo)({
58
- repoName: 'kibana',
59
- repoOwner: 'elastic',
60
- cwd: '/path/to/source/repo',
61
- })).rejects.toThrowError('Simulated git clone failure');
62
- expect(del_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories/elastic/kibana', { force: true });
63
- });
64
- });
65
- describe('while cloning the repo', () => {
66
- it('updates the progress', async () => {
67
- let onClose;
68
- let onData;
69
- const oraMock = (0, mocks_1.getOraMock)();
70
- const spinnerTextSpy = jest.spyOn(oraMock, 'text', 'set');
71
- const spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
72
- jest
73
- .spyOn(gitModule, 'getLocalSourceRepoPath')
74
- .mockResolvedValue(undefined);
75
- jest
76
- .spyOn(childProcess, 'spawnOriginal')
77
- //@ts-expect-error
78
- .mockImplementation(() => {
79
- return {
80
- on: (name, cb) => {
81
- if (name === 'close') {
82
- onClose = cb;
83
- }
84
- },
85
- stderr: {
86
- on: (name, handler) => {
87
- if (name === 'data') {
88
- onData = handler;
89
- }
90
- },
91
- },
92
- };
93
- });
94
- setTimeout(() => {
95
- onData('Receiving objects: 1%');
96
- onData('Receiving objects: 10%');
97
- onData('Receiving objects: 20%');
98
- onData('Receiving objects: 100%');
99
- onData('Updating files: 1%');
100
- onData('Updating files: 10%');
101
- onData('Updating files: 20%');
102
- onData('Updating files: 100%');
103
- onClose(0);
104
- }, 50);
105
- await (0, setupRepo_1.setupRepo)({
106
- repoName: 'kibana',
107
- repoOwner: 'elastic',
108
- gitHostname: 'github.com',
109
- cwd: '/path/to/source/repo',
110
- });
111
- expect(spinnerTextSpy.mock.calls.map((call) => call[0]))
112
- .toMatchInlineSnapshot(`
113
- Array [
114
- "0% Cloning repository from github.com (one-time operation)",
115
- "1% Cloning repository from github.com (one-time operation)",
116
- "9% Cloning repository from github.com (one-time operation)",
117
- "18% Cloning repository from github.com (one-time operation)",
118
- "90% Cloning repository from github.com (one-time operation)",
119
- "90% Cloning repository from github.com (one-time operation)",
120
- "91% Cloning repository from github.com (one-time operation)",
121
- "92% Cloning repository from github.com (one-time operation)",
122
- "100% Cloning repository from github.com (one-time operation)",
123
- ]
124
- `);
125
- expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from github.com (one-time operation)');
126
- });
127
- });
128
- describe('if repo is already cloned', () => {
129
- function mockGitProjectRootPath(value) {
130
- return (jest
131
- .spyOn(childProcess, 'spawnPromise')
132
- //@ts-expect-error
133
- .mockImplementationOnce(async (cmd, cmdArgs) => {
134
- if (cmdArgs.includes('rev-parse')) {
135
- return {
136
- stdout: value,
137
- };
138
- }
139
- }));
140
- }
141
- beforeEach(async () => {
142
- jest.clearAllMocks();
143
- mockGitProjectRootPath('/myHomeDir/.backport/repositories/elastic/kibana');
144
- jest.spyOn(gitModule, 'cloneRepo');
145
- await (0, setupRepo_1.setupRepo)({
146
- accessToken: 'myAccessToken',
147
- authenticatedUsername: 'sqren_authenticated',
148
- cwd: '/path/to/source/repo',
149
- fork: true,
150
- repoForkOwner: 'sqren',
151
- repoName: 'kibana',
152
- repoOwner: 'elastic',
153
- });
154
- });
155
- it('should not delete the existing repo', () => {
156
- expect(del_1.default).not.toHaveBeenCalled();
157
- });
158
- it('should not clone repo', () => {
159
- expect(gitModule.cloneRepo).not.toHaveBeenCalled();
160
- });
161
- it('should re-create remotes for both source repo and fork', () => {
162
- expect(spawnSpy.mock.calls.map(([cmd, cmdArgs, cwd]) => ({
163
- cmd: `${cmd} ${cmdArgs.join(' ')}`,
164
- cwd,
165
- }))).toEqual([
166
- {
167
- cmd: 'git rev-parse --show-toplevel',
168
- cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
169
- },
170
- {
171
- cmd: 'git remote rm origin',
172
- cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
173
- },
174
- {
175
- cmd: 'git remote rm sqren',
176
- cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
177
- },
178
- {
179
- cmd: 'git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git',
180
- cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
181
- },
182
- {
183
- cmd: 'git remote rm elastic',
184
- cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
185
- },
186
- {
187
- cmd: 'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
188
- cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
189
- },
190
- ]);
191
- });
192
- });
193
- function mockGitClone() {
194
- jest
195
- .spyOn(childProcess, 'spawnOriginal')
196
- //@ts-expect-error
197
- .mockImplementation((cmd, cmdArgs) => {
198
- if (cmdArgs.includes('clone')) {
199
- return {
200
- on: (name, cb) => {
201
- if (name === 'close') {
202
- //@ts-expect-error
203
- cb(0);
204
- }
205
- },
206
- stderr: { on: () => null },
207
- };
208
- }
209
- });
210
- }
211
- describe('if repo does not exists locally', () => {
212
- let spinnerSuccessSpy;
213
- beforeEach(async () => {
214
- const oraMock = (0, mocks_1.getOraMock)();
215
- spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
216
- mockGitClone();
217
- await (0, setupRepo_1.setupRepo)({
218
- accessToken: 'myAccessToken',
219
- gitHostname: 'github.com',
220
- repoName: 'kibana',
221
- repoOwner: 'elastic',
222
- cwd: '/path/to/source/repo',
223
- });
224
- });
225
- it('should clone it from github.com', async () => {
226
- expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from github.com (one-time operation)');
227
- expect(childProcess.spawnOriginal).toHaveBeenCalledWith('git', [
228
- 'clone',
229
- 'https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
230
- '/myHomeDir/.backport/repositories/elastic/kibana',
231
- '--progress',
232
- ]);
233
- });
234
- });
235
- describe('if repo exists locally', () => {
236
- let spinnerSuccessSpy;
237
- beforeEach(async () => {
238
- const oraMock = (0, mocks_1.getOraMock)();
239
- spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
240
- jest
241
- .spyOn(gitModule, 'getLocalSourceRepoPath')
242
- .mockResolvedValue('/path/to/source/repo');
243
- jest
244
- .spyOn(gitModule, 'getGitConfig')
245
- .mockResolvedValue('email-or-username');
246
- mockGitClone();
247
- await (0, setupRepo_1.setupRepo)({
248
- repoName: 'kibana',
249
- repoOwner: 'elastic',
250
- cwd: '/path/to/source/repo',
251
- });
252
- });
253
- it('should clone it from local folder', async () => {
254
- expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from /path/to/source/repo (one-time operation)');
255
- expect(childProcess.spawnOriginal).toHaveBeenCalledWith('git', [
256
- 'clone',
257
- '/path/to/source/repo',
258
- '/myHomeDir/.backport/repositories/elastic/kibana',
259
- '--progress',
260
- ]);
261
- });
262
- });
263
- describe('if `repoPath` is a parent of current working directory (cwd)', () => {
264
- it('should clone it from local folder', async () => {
265
- await expect(() => (0, setupRepo_1.setupRepo)({
266
- repoName: 'kibana',
267
- repoOwner: 'elastic',
268
- cwd: '/myHomeDir/.backport/repositories/owner/repo/foo',
269
- dir: '/myHomeDir/.backport/repositories/owner/repo',
270
- })).rejects.toThrowError('Refusing to clone repo into "/myHomeDir/.backport/repositories/owner/repo" when current working directory is "/myHomeDir/.backport/repositories/owner/repo/foo". Please change backport directory via `--dir` option or run backport from another location');
271
- });
272
- });
273
- });
@@ -1,2 +0,0 @@
1
- import { Commit } from '../entrypoint.module';
2
- export declare function filterUnmergedCommits(commit: Commit): boolean;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.filterUnmergedCommits = void 0;
4
- function filterUnmergedCommits(commit) {
5
- return commit.expectedTargetPullRequests.some((pr) => pr.state !== 'MERGED');
6
- }
7
- exports.filterUnmergedCommits = filterUnmergedCommits;