backport 8.3.1 → 8.4.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 (202) hide show
  1. package/dist/lib/child-process-promisified.js +2 -2
  2. package/dist/lib/git.js +1 -0
  3. package/dist/lib/git.test.js +26 -0
  4. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -0
  5. package/dist/options/ConfigOptions.d.ts +1 -0
  6. package/dist/options/cliArgs.d.ts +1 -0
  7. package/dist/options/cliArgs.js +5 -0
  8. package/dist/options/config/config.d.ts +1 -0
  9. package/dist/options/config/readConfigFile.d.ts +1 -0
  10. package/dist/options/options.d.ts +2 -0
  11. package/dist/options/options.js +1 -0
  12. package/dist/options/options.test.js +1 -0
  13. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -0
  14. package/dist/utils/packageVersion.d.ts +1 -1
  15. package/dist/utils/packageVersion.js +1 -1
  16. package/package.json +3 -4
  17. package/dist/entrypoint.cli.private.test.d.ts +0 -1
  18. package/dist/entrypoint.cli.private.test.js +0 -47
  19. package/dist/errors/BackportError.d.ts +0 -19
  20. package/dist/errors/BackportError.js +0 -29
  21. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  22. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  23. package/dist/runSequentially.test.d.ts +0 -1
  24. package/dist/runSequentially.test.js +0 -243
  25. package/dist/services/BackportError.d.ts +0 -19
  26. package/dist/services/BackportError.js +0 -29
  27. package/dist/services/HandledBackportError.d.ts +0 -19
  28. package/dist/services/HandledBackportError.js +0 -29
  29. package/dist/services/HandledError.d.ts +0 -19
  30. package/dist/services/HandledError.js +0 -29
  31. package/dist/services/child-process-promisified.d.ts +0 -25
  32. package/dist/services/child-process-promisified.js +0 -58
  33. package/dist/services/env.d.ts +0 -7
  34. package/dist/services/env.js +0 -30
  35. package/dist/services/env.test.d.ts +0 -1
  36. package/dist/services/env.test.js +0 -21
  37. package/dist/services/git.d.ts +0 -77
  38. package/dist/services/git.integration.test.d.ts +0 -1
  39. package/dist/services/git.integration.test.js +0 -616
  40. package/dist/services/git.js +0 -439
  41. package/dist/services/git.private.test.d.ts +0 -1
  42. package/dist/services/git.private.test.js +0 -618
  43. package/dist/services/git.test.d.ts +0 -1
  44. package/dist/services/git.test.js +0 -580
  45. package/dist/services/github/commitFormatters.d.ts +0 -3
  46. package/dist/services/github/commitFormatters.js +0 -17
  47. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  48. package/dist/services/github/commitFormatters.test.js +0 -11
  49. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +0 -2
  50. package/dist/services/github/v3/addAssigneesToPullRequest.js +0 -32
  51. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  52. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  53. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +0 -2
  54. package/dist/services/github/v3/addLabelsToPullRequest.js +0 -30
  55. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +0 -2
  56. package/dist/services/github/v3/addReviewersToPullRequest.js +0 -32
  57. package/dist/services/github/v3/createPullRequest.d.ts +0 -29
  58. package/dist/services/github/v3/createPullRequest.js +0 -91
  59. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  60. package/dist/services/github/v3/createPullRequest.test.js +0 -377
  61. package/dist/services/github/v3/createStatusComment.d.ts +0 -11
  62. package/dist/services/github/v3/createStatusComment.js +0 -131
  63. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  64. package/dist/services/github/v3/createStatusComment.test.js +0 -409
  65. package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +0 -14
  66. package/dist/services/github/v3/getGithubV3ErrorMessage.js +0 -16
  67. package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -2
  68. package/dist/services/github/v4/FetchPullRequestId.js +0 -36
  69. package/dist/services/github/v4/apiRequestV4.d.ts +0 -31
  70. package/dist/services/github/v4/apiRequestV4.js +0 -71
  71. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  72. package/dist/services/github/v4/apiRequestV4.test.js +0 -109
  73. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -2
  74. package/dist/services/github/v4/disablePullRequestAutoMerge.js +0 -32
  75. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -2
  76. package/dist/services/github/v4/enablePullRequestAutoMerge.js +0 -50
  77. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  78. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  79. package/dist/services/github/v4/fetchAuthorId.d.ts +0 -10
  80. package/dist/services/github/v4/fetchAuthorId.js +0 -28
  81. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  82. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -25
  83. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  84. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
  85. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -11
  86. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -58
  87. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  88. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -136
  89. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -11
  90. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +0 -48
  91. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  92. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -118
  93. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -29
  94. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +0 -110
  95. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  96. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -196
  97. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  98. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -157
  99. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +0 -3
  100. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +0 -61
  101. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  102. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -107
  103. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +0 -12
  104. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +0 -69
  105. package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -9
  106. package/dist/services/github/v4/fetchExistingPullRequest.js +0 -64
  107. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  108. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -44
  109. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -2
  110. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +0 -39
  111. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +0 -8
  112. package/dist/services/github/v4/fetchRemoteProjectConfig.js +0 -49
  113. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  114. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -49
  115. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +0 -69
  116. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -73
  117. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  118. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -116
  119. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +0 -16
  120. package/dist/services/github/v4/getOptionsFromGithub/query.js +0 -29
  121. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +0 -29
  122. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +0 -61
  123. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  124. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -72
  125. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  126. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -176
  127. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +0 -6
  128. package/dist/services/github/v4/throwOnInvalidAccessToken.js +0 -45
  129. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  130. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  131. package/dist/services/logger.d.ts +0 -9
  132. package/dist/services/logger.js +0 -74
  133. package/dist/services/prompt.test.d.ts +0 -1
  134. package/dist/services/prompt.test.js +0 -139
  135. package/dist/services/prompts.d.ts +0 -17
  136. package/dist/services/prompts.js +0 -132
  137. package/dist/services/remoteConfig.d.ts +0 -20
  138. package/dist/services/remoteConfig.js +0 -52
  139. package/dist/services/sequentially.d.ts +0 -1
  140. package/dist/services/sequentially.js +0 -10
  141. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
  142. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +0 -102
  143. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  144. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -467
  145. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +0 -26
  146. package/dist/services/sourceCommit/getMockSourceCommit.js +0 -103
  147. package/dist/services/sourceCommit/parseSourceCommit.d.ts +0 -108
  148. package/dist/services/sourceCommit/parseSourceCommit.js +0 -123
  149. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  150. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -226
  151. package/dist/services/test.d.ts +0 -1
  152. package/dist/services/test.js +0 -23
  153. package/dist/state.d.ts +0 -0
  154. package/dist/state.js +0 -1
  155. package/dist/test/ExecError.d.ts +0 -16
  156. package/dist/test/ExecError.js +0 -15
  157. package/dist/test/e2e/cli/cli.private.test.d.ts +0 -1
  158. package/dist/test/e2e/cli/cli.private.test.js +0 -222
  159. package/dist/test/e2e/cli/date-filters.d.ts +0 -1
  160. package/dist/test/e2e/cli/date-filters.js +0 -43
  161. package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +0 -1
  162. package/dist/test/e2e/cli/interactive-error-handling.private.test.js +0 -80
  163. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +0 -1
  164. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +0 -198
  165. package/dist/test/e2e/cli.e2e.private.test.d.ts +0 -1
  166. package/dist/test/e2e/cli.e2e.private.test.js +0 -433
  167. package/dist/test/e2e/module/module.mutation.test.d.ts +0 -1
  168. package/dist/test/e2e/module/module.mutation.test.js +0 -369
  169. package/dist/test/e2e/module.e2e.mutation.test.d.ts +0 -1
  170. package/dist/test/e2e/module.e2e.mutation.test.js +0 -369
  171. package/dist/test/e2e/module.e2e.private.test.d.ts +0 -1
  172. package/dist/test/e2e/module.e2e.private.test.js +0 -369
  173. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -13
  174. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +0 -243
  175. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  176. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -320
  177. package/dist/ui/getCommits.d.ts +0 -2
  178. package/dist/ui/getCommits.js +0 -75
  179. package/dist/ui/getCommitsWithoutBackports.d.ts +0 -11
  180. package/dist/ui/getCommitsWithoutBackports.js +0 -68
  181. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  182. package/dist/ui/getCommitsWithoutBackports.test.js +0 -335
  183. package/dist/ui/getGitConfigAuthor.d.ts +0 -6
  184. package/dist/ui/getGitConfigAuthor.js +0 -15
  185. package/dist/ui/getTargetBranches.d.ts +0 -5
  186. package/dist/ui/getTargetBranches.js +0 -67
  187. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  188. package/dist/ui/getTargetBranches.test.js +0 -204
  189. package/dist/ui/maybeSetupRepo.d.ts +0 -2
  190. package/dist/ui/maybeSetupRepo.js +0 -53
  191. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  192. package/dist/ui/maybeSetupRepo.test.js +0 -238
  193. package/dist/ui/ora.d.ts +0 -2
  194. package/dist/ui/ora.js +0 -21
  195. package/dist/ui/setupRepo.d.ts +0 -2
  196. package/dist/ui/setupRepo.js +0 -56
  197. package/dist/ui/setupRepo.test.d.ts +0 -1
  198. package/dist/ui/setupRepo.test.js +0 -273
  199. package/dist/utils/filterMissingCommits.d.ts +0 -2
  200. package/dist/utils/filterMissingCommits.js +0 -7
  201. package/dist/utils/redact.d.ts +0 -1
  202. 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;