backport 7.4.0 → 8.2.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.
- package/README.md +15 -16
- package/dist/backportRun.d.ts +12 -6
- package/dist/backportRun.js +64 -62
- package/dist/entrypoint.cli.js +4 -8
- package/dist/entrypoint.module.d.ts +13 -6
- package/dist/entrypoint.module.js +14 -20
- package/dist/entrypoint.module.private.test.js +47 -346
- package/dist/errors/BackportError.d.ts +19 -0
- package/dist/errors/BackportError.js +29 -0
- package/dist/lib/BackportError.d.ts +19 -0
- package/dist/lib/BackportError.js +29 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +11 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +242 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +321 -0
- package/dist/lib/child-process-promisified.d.ts +25 -0
- package/dist/lib/child-process-promisified.js +60 -0
- package/dist/lib/env.d.ts +9 -0
- package/dist/lib/env.js +33 -0
- package/dist/lib/env.test.d.ts +1 -0
- package/dist/lib/env.test.js +26 -0
- package/dist/lib/getCommits.d.ts +2 -0
- package/dist/lib/getCommits.js +75 -0
- package/dist/lib/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/lib/getCommitsWithoutBackports.js +68 -0
- package/dist/lib/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/lib/getCommitsWithoutBackports.test.js +335 -0
- package/dist/lib/getGitConfigAuthor.d.ts +6 -0
- package/dist/lib/getGitConfigAuthor.js +15 -0
- package/dist/lib/getTargetBranches.d.ts +5 -0
- package/dist/lib/getTargetBranches.js +67 -0
- package/dist/lib/getTargetBranches.test.d.ts +1 -0
- package/dist/lib/getTargetBranches.test.js +210 -0
- package/dist/lib/git.d.ts +77 -0
- package/dist/lib/git.js +439 -0
- package/dist/lib/git.private.test.d.ts +1 -0
- package/dist/lib/git.private.test.js +618 -0
- package/dist/lib/git.test.d.ts +1 -0
- package/dist/lib/git.test.js +580 -0
- package/dist/lib/github/commitFormatters.d.ts +3 -0
- package/dist/lib/github/commitFormatters.js +17 -0
- package/dist/lib/github/commitFormatters.test.d.ts +1 -0
- package/dist/lib/github/commitFormatters.test.js +11 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.js +32 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +27 -0
- package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addLabelsToPullRequest.js +30 -0
- package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addReviewersToPullRequest.js +32 -0
- package/dist/lib/github/v3/createPullRequest.d.ts +29 -0
- package/dist/lib/github/v3/createPullRequest.js +91 -0
- package/dist/lib/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/lib/github/v3/createPullRequest.test.js +377 -0
- package/dist/lib/github/v3/createStatusComment.d.ts +11 -0
- package/dist/lib/github/v3/createStatusComment.js +138 -0
- package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/lib/github/v3/createStatusComment.test.js +566 -0
- package/dist/lib/github/v3/getGithubV3ErrorMessage.d.ts +14 -0
- package/dist/lib/github/v3/getGithubV3ErrorMessage.js +16 -0
- package/dist/lib/github/v4/FetchPullRequestId.d.ts +2 -0
- package/dist/lib/github/v4/FetchPullRequestId.js +36 -0
- package/dist/lib/github/v4/apiRequestV4.d.ts +31 -0
- package/dist/lib/github/v4/apiRequestV4.js +71 -0
- package/dist/lib/github/v4/apiRequestV4.test.d.ts +1 -0
- package/dist/lib/github/v4/apiRequestV4.test.js +109 -0
- package/dist/lib/github/v4/disablePullRequestAutoMerge.d.ts +2 -0
- package/dist/lib/github/v4/disablePullRequestAutoMerge.js +32 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.d.ts +2 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.js +50 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
- package/dist/lib/github/v4/fetchAuthorId.d.ts +10 -0
- package/dist/lib/github/v4/fetchAuthorId.js +28 -0
- package/dist/lib/github/v4/fetchAuthorId.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchAuthorId.private.test.js +25 -0
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +11 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +58 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +136 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.d.ts +11 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +48 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +118 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +29 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +110 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +196 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +107 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +12 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +69 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.d.ts +9 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.js +64 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.private.test.js +44 -0
- package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.d.ts +2 -0
- package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.js +39 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.js +49 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.js +49 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +72 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +78 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +116 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +16 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.js +29 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.js +61 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +72 -0
- package/dist/lib/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
- package/dist/lib/github/v4/mocks/commitsByAuthorMock.js +176 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.d.ts +7 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.js +45 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.test.js +87 -0
- package/dist/lib/github/v4/validateTargetBranches.d.ts +14 -0
- package/dist/lib/github/v4/validateTargetBranches.js +46 -0
- package/dist/lib/github/v4/validateTargetBranches.private.test.d.ts +1 -0
- package/dist/lib/github/v4/validateTargetBranches.private.test.js +51 -0
- package/dist/lib/logger.d.ts +11 -0
- package/dist/lib/logger.js +80 -0
- package/dist/lib/ora.d.ts +2 -0
- package/dist/lib/ora.js +21 -0
- package/dist/lib/prompt.test.d.ts +1 -0
- package/dist/lib/prompt.test.js +139 -0
- package/dist/lib/prompts.d.ts +17 -0
- package/dist/lib/prompts.js +132 -0
- package/dist/lib/remoteConfig.d.ts +20 -0
- package/dist/lib/remoteConfig.js +52 -0
- package/dist/lib/sequentially.d.ts +1 -0
- package/dist/lib/sequentially.js +10 -0
- package/dist/lib/setupRepo.d.ts +2 -0
- package/dist/lib/setupRepo.js +56 -0
- package/dist/lib/setupRepo.test.d.ts +1 -0
- package/dist/lib/setupRepo.test.js +278 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
- package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
- package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
- package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
- package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
- package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
- package/dist/options/ConfigOptions.d.ts +4 -2
- package/dist/options/cliArgs.d.ts +14 -6
- package/dist/options/cliArgs.js +50 -22
- package/dist/options/cliArgs.test.js +128 -4
- package/dist/options/config/config.d.ts +5 -4
- package/dist/options/config/config.js +3 -5
- package/dist/options/config/config.test.js +0 -1
- package/dist/options/config/globalConfig.d.ts +5 -3
- package/dist/options/config/globalConfig.js +17 -14
- package/dist/options/config/readConfigFile.d.ts +5 -3
- package/dist/options/config/readConfigFile.js +2 -2
- package/dist/options/options.d.ts +41 -5
- package/dist/options/options.js +24 -24
- package/dist/options/options.test.js +117 -55
- package/dist/runSequentially.d.ts +14 -9
- package/dist/runSequentially.js +27 -12
- package/dist/scripts/postinstall.js +4 -3
- package/dist/scripts/postinstall.test.js +6 -2
- package/dist/services/BackportError.d.ts +19 -0
- package/dist/services/BackportError.js +29 -0
- package/dist/services/HandledBackportError.d.ts +19 -0
- package/dist/services/HandledBackportError.js +29 -0
- package/dist/services/HandledError.d.ts +2 -2
- package/dist/services/HandledError.js +7 -7
- package/dist/services/child-process-promisified.d.ts +19 -3
- package/dist/services/child-process-promisified.js +46 -17
- package/dist/services/git.d.ts +6 -7
- package/dist/services/git.integration.test.js +381 -65
- package/dist/services/git.js +189 -123
- package/dist/services/git.private.test.d.ts +1 -0
- package/dist/services/git.private.test.js +618 -0
- package/dist/services/git.test.js +167 -124
- package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
- package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
- package/dist/services/github/v3/createPullRequest.js +4 -2
- package/dist/services/github/v3/createStatusComment.js +16 -17
- package/dist/services/github/v3/createStatusComment.test.js +20 -9
- package/dist/services/github/v4/apiRequestV4.js +2 -2
- package/dist/services/github/v4/apiRequestV4.test.js +2 -2
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +4 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +3 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +4 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +5 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +3 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +5 -1
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
- package/dist/services/logger.js +5 -1
- package/dist/services/test.d.ts +1 -0
- package/dist/services/test.js +23 -0
- package/dist/state.d.ts +0 -0
- package/dist/state.js +1 -0
- package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +27 -25
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +53 -75
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +80 -0
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +199 -0
- package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/interactive-error-handling.private.test.js +80 -0
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +198 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +28 -29
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +6 -2
- package/dist/test/e2e/cli/runBackportViaCli.js +44 -23
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +28 -21
- package/dist/test/handleUnbackportedPullRequests.private.test.js +11 -8
- package/dist/test/sandbox.js +5 -1
- package/dist/test/setupFiles/automatic-mocks.js +6 -2
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -4
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
- package/dist/ui/getCommits.js +2 -2
- package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
- package/dist/ui/getGitConfigAuthor.js +1 -1
- package/dist/ui/getTargetBranches.js +3 -3
- package/dist/ui/getTargetBranches.test.js +5 -1
- package/dist/ui/ora.d.ts +1 -8
- package/dist/ui/setupRepo.js +3 -3
- package/dist/ui/setupRepo.test.js +98 -61
- package/dist/utils/isErrnoError.d.ts +2 -0
- package/dist/utils/isErrnoError.js +7 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +19 -19
- package/yarn.lock +472 -701
package/dist/test/sandbox.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
7
|
if (k2 === undefined) k2 = k;
|
|
8
|
-
Object.
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
9
13
|
}) : (function(o, m, k, k2) {
|
|
10
14
|
if (k2 === undefined) k2 = k;
|
|
11
15
|
o[k2] = m[k];
|
|
@@ -43,7 +47,7 @@ jest.mock('del', () => {
|
|
|
43
47
|
return jest.fn(async (path) => `Attempted to delete ${path}`);
|
|
44
48
|
});
|
|
45
49
|
(0, mocks_1.mockOra)();
|
|
46
|
-
jest.mock('../../
|
|
50
|
+
jest.mock('../../lib/logger', () => {
|
|
47
51
|
const spy = jest.fn();
|
|
48
52
|
const logger = {
|
|
49
53
|
spy: spy,
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.cherrypickAndCreateTargetPullRequest = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const lodash_1 = require("lodash");
|
|
9
|
-
const
|
|
9
|
+
const BackportError_1 = require("../services/BackportError");
|
|
10
10
|
const child_process_promisified_1 = require("../services/child-process-promisified");
|
|
11
11
|
const env_1 = require("../services/env");
|
|
12
12
|
const git_1 = require("../services/git");
|
|
@@ -150,7 +150,7 @@ async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor)
|
|
|
150
150
|
conflictingFiles: conflictingFilesRelative,
|
|
151
151
|
});
|
|
152
152
|
if (options.ci) {
|
|
153
|
-
throw new
|
|
153
|
+
throw new BackportError_1.BackportError({
|
|
154
154
|
code: 'merge-conflict-exception',
|
|
155
155
|
commitsWithoutBackports,
|
|
156
156
|
conflictingFiles: conflictingFilesRelative,
|
|
@@ -166,7 +166,7 @@ async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor)
|
|
|
166
166
|
* Commit could not be cleanly cherrypicked: Initiating conflict resolution
|
|
167
167
|
*/
|
|
168
168
|
if (options.editor) {
|
|
169
|
-
await (0, child_process_promisified_1.
|
|
169
|
+
await (0, child_process_promisified_1.spawnPromise)(options.editor, [repoPath], options.cwd);
|
|
170
170
|
}
|
|
171
171
|
// list files with conflict markers + unstaged files and require user to resolve them
|
|
172
172
|
await listConflictingAndUnstagedFiles({
|
|
@@ -212,7 +212,7 @@ ${unstagedSection}
|
|
|
212
212
|
|
|
213
213
|
Press ENTER when the conflicts are resolved and files are staged`);
|
|
214
214
|
if (!didConfirm) {
|
|
215
|
-
throw new
|
|
215
|
+
throw new BackportError_1.BackportError({ code: 'abort-exception' });
|
|
216
216
|
}
|
|
217
217
|
const MAX_RETRIES = 100;
|
|
218
218
|
if (retries++ > MAX_RETRIES) {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -26,10 +30,7 @@ const os_1 = __importDefault(require("os"));
|
|
|
26
30
|
const nock_1 = __importDefault(require("nock"));
|
|
27
31
|
const ora_1 = __importDefault(require("ora"));
|
|
28
32
|
const childProcess = __importStar(require("../services/child-process-promisified"));
|
|
29
|
-
const commitsByAuthorMock_1 = require("../services/github/v4/mocks/commitsByAuthorMock");
|
|
30
33
|
const logger = __importStar(require("../services/logger"));
|
|
31
|
-
const prompts = __importStar(require("../services/prompts"));
|
|
32
|
-
const ExecError_1 = require("../test/ExecError");
|
|
33
34
|
const nockHelpers_1 = require("../test/nockHelpers");
|
|
34
35
|
const cherrypickAndCreateTargetPullRequest_1 = require("./cherrypickAndCreateTargetPullRequest");
|
|
35
36
|
describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
@@ -39,9 +40,9 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
39
40
|
beforeEach(() => {
|
|
40
41
|
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
41
42
|
execSpy = jest
|
|
42
|
-
.spyOn(childProcess, '
|
|
43
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
43
44
|
// mock all exec commands to respond without errors
|
|
44
|
-
.mockResolvedValue({ stdout: '', stderr: '' });
|
|
45
|
+
.mockResolvedValue({ stdout: '', stderr: '', code: 0, cmdArgs: [] });
|
|
45
46
|
consoleLogSpy = jest.spyOn(logger, 'consoleLog');
|
|
46
47
|
// ensure labels are added
|
|
47
48
|
addLabelsScope = (0, nock_1.default)('https://api.github.com')
|
|
@@ -249,14 +250,8 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
249
250
|
});
|
|
250
251
|
describe('when cherry-picking fails', () => {
|
|
251
252
|
let res;
|
|
252
|
-
let promptSpy;
|
|
253
|
-
let execSpy;
|
|
254
|
-
let commitsByAuthorCalls;
|
|
255
253
|
let createPullRequestCalls;
|
|
256
254
|
beforeEach(async () => {
|
|
257
|
-
// spies
|
|
258
|
-
promptSpy = jest.spyOn(prompts, 'confirmPrompt').mockResolvedValue(true);
|
|
259
|
-
execSpy = setupExecSpyForCherryPick();
|
|
260
255
|
const options = {
|
|
261
256
|
assignees: [],
|
|
262
257
|
authenticatedUsername: 'sqren_authenticated',
|
|
@@ -276,12 +271,6 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
276
271
|
.post('/repos/elastic/kibana/pulls')
|
|
277
272
|
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
|
278
273
|
createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
|
|
279
|
-
commitsByAuthorCalls =
|
|
280
|
-
(0, nockHelpers_1.mockGqlRequest)({
|
|
281
|
-
name: 'CommitsByAuthor',
|
|
282
|
-
statusCode: 200,
|
|
283
|
-
body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
|
|
284
|
-
});
|
|
285
274
|
res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
|
|
286
275
|
options,
|
|
287
276
|
commits: [
|
|
@@ -327,146 +316,5 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
327
316
|
it('returns the expected response', () => {
|
|
328
317
|
expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
|
|
329
318
|
});
|
|
330
|
-
it('shows the right prompts', () => {
|
|
331
|
-
expect(promptSpy.mock.calls.length).toBe(4);
|
|
332
|
-
expect(promptSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
|
|
333
|
-
"Fix the following conflicts manually:
|
|
334
|
-
|
|
335
|
-
Conflicting files:
|
|
336
|
-
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
Press ENTER when the conflicts are resolved and files are staged"
|
|
340
|
-
`);
|
|
341
|
-
expect(promptSpy.mock.calls[1][0]).toMatchInlineSnapshot(`
|
|
342
|
-
"Fix the following conflicts manually:
|
|
343
|
-
|
|
344
|
-
Conflicting files:
|
|
345
|
-
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
Press ENTER when the conflicts are resolved and files are staged"
|
|
349
|
-
`);
|
|
350
|
-
expect(promptSpy.mock.calls[2][0]).toMatchInlineSnapshot(`
|
|
351
|
-
"Fix the following conflicts manually:
|
|
352
|
-
|
|
353
|
-
Conflicting files:
|
|
354
|
-
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
Press ENTER when the conflicts are resolved and files are staged"
|
|
358
|
-
`);
|
|
359
|
-
});
|
|
360
|
-
it('commitsByAuthor is called with correct arguments', () => {
|
|
361
|
-
expect(commitsByAuthorCalls[0].variables).toMatchInlineSnapshot(`
|
|
362
|
-
Object {
|
|
363
|
-
"authorId": null,
|
|
364
|
-
"commitPath": "conflicting-file.txt",
|
|
365
|
-
"dateSince": null,
|
|
366
|
-
"dateUntil": "2021-08-18T16:11:38Z",
|
|
367
|
-
"maxNumber": 10,
|
|
368
|
-
"repoName": "kibana",
|
|
369
|
-
"repoOwner": "elastic",
|
|
370
|
-
"sourceBranch": "myDefaultSourceBranch",
|
|
371
|
-
}
|
|
372
|
-
`);
|
|
373
|
-
});
|
|
374
|
-
it('calls exec correctly', () => {
|
|
375
|
-
expect(execSpy.mock.calls).toMatchSnapshot();
|
|
376
|
-
});
|
|
377
|
-
it('calls ora correctly', () => {
|
|
378
|
-
expect(ora_1.default.mock.calls.map((call) => call[0].text))
|
|
379
|
-
.toMatchInlineSnapshot(`
|
|
380
|
-
Array [
|
|
381
|
-
"Pulling latest changes",
|
|
382
|
-
"Cherry-picking: My original commit message",
|
|
383
|
-
"Finalizing cherrypick",
|
|
384
|
-
"Pushing branch \\"sqren:backport/6.x/commit-mySha\\"",
|
|
385
|
-
undefined,
|
|
386
|
-
"Creating pull request",
|
|
387
|
-
"Adding labels: backport",
|
|
388
|
-
]
|
|
389
|
-
`);
|
|
390
|
-
});
|
|
391
|
-
it('logs correctly', async () => {
|
|
392
|
-
expect(consoleLogSpy.mock.calls.map((call) => call[0]).join(''))
|
|
393
|
-
.toMatchInlineSnapshot(`
|
|
394
|
-
"
|
|
395
|
-
Backporting to 6.x:
|
|
396
|
-
The commit could not be backported due to conflicts
|
|
397
|
-
Please fix the conflicts in /myHomeDir/.backport/repositories/elastic/kibana
|
|
398
|
-
----------------------------------------
|
|
399
|
-
|
|
400
|
-
----------------------------------------
|
|
401
|
-
|
|
402
|
-
----------------------------------------
|
|
403
|
-
View pull request: myHtmlUrl"
|
|
404
|
-
`);
|
|
405
|
-
});
|
|
406
319
|
});
|
|
407
320
|
});
|
|
408
|
-
function setupExecSpyForCherryPick() {
|
|
409
|
-
let conflictingFilesCheck = 0;
|
|
410
|
-
let unstagedFilesCheck = 0;
|
|
411
|
-
return jest
|
|
412
|
-
.spyOn(childProcess, 'exec')
|
|
413
|
-
.mockImplementation(async (cmd) => {
|
|
414
|
-
// createFeatureBranch
|
|
415
|
-
if (cmd.includes('git checkout -B')) {
|
|
416
|
-
return { stdout: 'create feature branch succeeded', stderr: '' };
|
|
417
|
-
}
|
|
418
|
-
// git fetch
|
|
419
|
-
if (cmd.startsWith('git fetch')) {
|
|
420
|
-
return { stderr: '', stdout: '' };
|
|
421
|
-
}
|
|
422
|
-
// emulate cherrypick exception
|
|
423
|
-
if (cmd.includes('cherry-pick -x mySha')) {
|
|
424
|
-
throw new ExecError_1.ExecError({ cmd, code: 128 });
|
|
425
|
-
}
|
|
426
|
-
// getIsCommitInBranch
|
|
427
|
-
if (cmd.startsWith('git merge-base --is-ancestor')) {
|
|
428
|
-
return { stderr: '', stdout: '' };
|
|
429
|
-
}
|
|
430
|
-
// getConflictingFiles
|
|
431
|
-
if (cmd === 'git --no-pager diff --check') {
|
|
432
|
-
conflictingFilesCheck++;
|
|
433
|
-
if (conflictingFilesCheck >= 4) {
|
|
434
|
-
return { stderr: '', stdout: '' };
|
|
435
|
-
}
|
|
436
|
-
throw new ExecError_1.ExecError({
|
|
437
|
-
code: 2,
|
|
438
|
-
cmd,
|
|
439
|
-
stdout: `conflicting-file.txt:1: leftover conflict marker\nconflicting-file.txt:3: leftover conflict marker\nconflicting-file.txt:5: leftover conflict marker\n`,
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
// getUnstagedFiles
|
|
443
|
-
if (cmd === 'git --no-pager diff --name-only') {
|
|
444
|
-
unstagedFilesCheck++;
|
|
445
|
-
if (unstagedFilesCheck >= 5) {
|
|
446
|
-
return { stderr: '', stdout: '' };
|
|
447
|
-
}
|
|
448
|
-
return { stdout: `conflicting-file.txt\n`, stderr: '' };
|
|
449
|
-
}
|
|
450
|
-
// addUnstagedFiles
|
|
451
|
-
if (cmd === 'git add --update') {
|
|
452
|
-
return { stdout: ``, stderr: '' };
|
|
453
|
-
}
|
|
454
|
-
// finalizeCherrypick
|
|
455
|
-
if (cmd.includes('git commit --no-edit')) {
|
|
456
|
-
return { stdout: ``, stderr: '' };
|
|
457
|
-
}
|
|
458
|
-
// pushFeatureBranch
|
|
459
|
-
if (cmd.startsWith('git push ')) {
|
|
460
|
-
return { stdout: ``, stderr: '' };
|
|
461
|
-
}
|
|
462
|
-
// deleteFeatureBranch
|
|
463
|
-
if (cmd.includes('git branch -D ')) {
|
|
464
|
-
return { stdout: ``, stderr: '' };
|
|
465
|
-
}
|
|
466
|
-
// getIsMergeCommit
|
|
467
|
-
if (cmd.startsWith('git rev-list -1 --merges')) {
|
|
468
|
-
return { stdout: ``, stderr: '' };
|
|
469
|
-
}
|
|
470
|
-
throw new Error(`Missing exec mock for "${cmd}"`);
|
|
471
|
-
});
|
|
472
|
-
}
|
package/dist/ui/getCommits.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getCommits = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const
|
|
8
|
+
const BackportError_1 = require("../services/BackportError");
|
|
9
9
|
const commitFormatters_1 = require("../services/github/commitFormatters");
|
|
10
10
|
const fetchCommitByPullNumber_1 = require("../services/github/v4/fetchCommits/fetchCommitByPullNumber");
|
|
11
11
|
const fetchCommitBySha_1 = require("../services/github/v4/fetchCommits/fetchCommitBySha");
|
|
@@ -41,7 +41,7 @@ async function getCommits(options) {
|
|
|
41
41
|
return [commit];
|
|
42
42
|
}
|
|
43
43
|
if (options.ci && !options.ls) {
|
|
44
|
-
throw new
|
|
44
|
+
throw new BackportError_1.BackportError('When "--ci" flag is enabled either `--sha` or `--pr` must be specified');
|
|
45
45
|
}
|
|
46
46
|
spinner.text = options.prFilter
|
|
47
47
|
? 'Loading pull requests...'
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getGitConfigAuthor = void 0;
|
|
4
4
|
const git_1 = require("../services/git");
|
|
5
5
|
async function getGitConfigAuthor(options) {
|
|
6
|
-
const localRepoPath = await (0, git_1.
|
|
6
|
+
const localRepoPath = await (0, git_1.getLocalSourceRepoPath)(options);
|
|
7
7
|
if (!localRepoPath) {
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTargetBranchChoices = exports.getTargetBranches = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
|
-
const
|
|
5
|
+
const BackportError_1 = require("../services/BackportError");
|
|
6
6
|
const prompts_1 = require("../services/prompts");
|
|
7
7
|
function getTargetBranches(options, commits) {
|
|
8
8
|
// target branches already specified (in contrast to letting the user choose from a list)
|
|
@@ -18,7 +18,7 @@ function getTargetBranches(options, commits) {
|
|
|
18
18
|
// automatically backport to specified target branches
|
|
19
19
|
if (options.ci) {
|
|
20
20
|
if ((0, lodash_1.isEmpty)(missingTargetBranches)) {
|
|
21
|
-
throw new
|
|
21
|
+
throw new BackportError_1.BackportError({ code: 'no-branches-exception' });
|
|
22
22
|
}
|
|
23
23
|
return missingTargetBranches;
|
|
24
24
|
}
|
|
@@ -37,7 +37,7 @@ function getTargetBranchChoices(options, missingTargetBranches, sourceBranch) {
|
|
|
37
37
|
// exclude sourceBranch from targetBranchChoices
|
|
38
38
|
const targetBranchesChoices = getTargetBranchChoicesAsObject(options.targetBranchChoices).filter((choice) => choice.name !== sourceBranch);
|
|
39
39
|
if ((0, lodash_1.isEmpty)(targetBranchesChoices)) {
|
|
40
|
-
throw new
|
|
40
|
+
throw new BackportError_1.BackportError('Missing target branch choices');
|
|
41
41
|
}
|
|
42
42
|
if (!options.branchLabelMapping) {
|
|
43
43
|
return targetBranchesChoices;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/ui/ora.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
1
|
import oraOriginal from 'ora';
|
|
2
|
-
export declare function ora(ci: boolean | undefined, text?: string | undefined): oraOriginal.Ora
|
|
3
|
-
start: (text?: string | undefined) => any;
|
|
4
|
-
succeed: () => void;
|
|
5
|
-
stop: () => void;
|
|
6
|
-
fail: () => void;
|
|
7
|
-
stopAndPersist: () => void;
|
|
8
|
-
text: string;
|
|
9
|
-
};
|
|
2
|
+
export declare function ora(ci: boolean | undefined, text?: string | undefined): oraOriginal.Ora;
|
package/dist/ui/setupRepo.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setupRepo = void 0;
|
|
4
4
|
const del = require("del");
|
|
5
|
-
const
|
|
5
|
+
const BackportError_1 = require("../services/BackportError");
|
|
6
6
|
const env_1 = require("../services/env");
|
|
7
7
|
const git_1 = require("../services/git");
|
|
8
8
|
const ora_1 = require("./ora");
|
|
@@ -10,13 +10,13 @@ async function setupRepo(options) {
|
|
|
10
10
|
const repoPath = (0, env_1.getRepoPath)(options);
|
|
11
11
|
const isAlreadyCloned = await getIsRepoCloned(options);
|
|
12
12
|
if (options.cwd.includes(repoPath)) {
|
|
13
|
-
throw new
|
|
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
14
|
}
|
|
15
15
|
// clone repo if folder does not already exists
|
|
16
16
|
if (!isAlreadyCloned) {
|
|
17
17
|
const spinner = (0, ora_1.ora)(options.ci).start();
|
|
18
18
|
try {
|
|
19
|
-
const localRepoPath = await (0, git_1.
|
|
19
|
+
const localRepoPath = await (0, git_1.getLocalSourceRepoPath)(options);
|
|
20
20
|
const remoteRepoPath = (0, git_1.getRemoteUrl)(options, options.repoOwner);
|
|
21
21
|
const sourcePath = localRepoPath ? localRepoPath : remoteRepoPath;
|
|
22
22
|
// show the full path for local repos, but only the host name for remote repos (to avoid showing the access token)
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -29,12 +33,12 @@ const gitModule = __importStar(require("../services/git"));
|
|
|
29
33
|
const mocks_1 = require("../test/mocks");
|
|
30
34
|
const setupRepo_1 = require("./setupRepo");
|
|
31
35
|
describe('setupRepo', () => {
|
|
32
|
-
let
|
|
36
|
+
let spawnSpy;
|
|
33
37
|
beforeEach(() => {
|
|
34
38
|
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
35
|
-
|
|
36
|
-
.spyOn(childProcess, '
|
|
37
|
-
.mockResolvedValue({ stderr: '', stdout: '' });
|
|
39
|
+
spawnSpy = jest
|
|
40
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
41
|
+
.mockResolvedValue({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
38
42
|
});
|
|
39
43
|
afterEach(() => {
|
|
40
44
|
jest.restoreAllMocks();
|
|
@@ -42,10 +46,10 @@ describe('setupRepo', () => {
|
|
|
42
46
|
describe('if an error occurs while cloning', () => {
|
|
43
47
|
it('should delete repo', async () => {
|
|
44
48
|
expect.assertions(2);
|
|
45
|
-
|
|
46
|
-
.spyOn(childProcess, '
|
|
47
|
-
.mockImplementation((cmd) => {
|
|
48
|
-
if (
|
|
49
|
+
jest
|
|
50
|
+
.spyOn(childProcess, 'spawnOriginal')
|
|
51
|
+
.mockImplementation((cmd, cmdArgs) => {
|
|
52
|
+
if (cmdArgs.includes('clone')) {
|
|
49
53
|
throw new Error('Simulated git clone failure');
|
|
50
54
|
}
|
|
51
55
|
throw new Error('unknown error');
|
|
@@ -60,39 +64,43 @@ describe('setupRepo', () => {
|
|
|
60
64
|
});
|
|
61
65
|
describe('while cloning the repo', () => {
|
|
62
66
|
it('updates the progress', async () => {
|
|
63
|
-
let
|
|
64
|
-
let
|
|
67
|
+
let onClose;
|
|
68
|
+
let onData;
|
|
65
69
|
const oraMock = (0, mocks_1.getOraMock)();
|
|
66
70
|
const spinnerTextSpy = jest.spyOn(oraMock, 'text', 'set');
|
|
67
71
|
const spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
|
|
68
|
-
jest.spyOn(gitModule, 'getLocalRepoPath').mockResolvedValue(undefined);
|
|
69
72
|
jest
|
|
70
|
-
.spyOn(
|
|
73
|
+
.spyOn(gitModule, 'getLocalSourceRepoPath')
|
|
74
|
+
.mockResolvedValue(undefined);
|
|
75
|
+
jest
|
|
76
|
+
.spyOn(childProcess, 'spawnOriginal')
|
|
71
77
|
//@ts-expect-error
|
|
72
|
-
.mockImplementation((
|
|
73
|
-
// callback should be called to finalize the operation
|
|
74
|
-
if (onComplete) {
|
|
75
|
-
//@ts-expect-error
|
|
76
|
-
onCloneComplete = onComplete;
|
|
77
|
-
}
|
|
78
|
+
.mockImplementation(() => {
|
|
78
79
|
return {
|
|
80
|
+
on: (name, cb) => {
|
|
81
|
+
if (name === 'close') {
|
|
82
|
+
onClose = cb;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
79
85
|
stderr: {
|
|
80
86
|
on: (name, handler) => {
|
|
81
|
-
|
|
87
|
+
if (name === 'data') {
|
|
88
|
+
onData = handler;
|
|
89
|
+
}
|
|
82
90
|
},
|
|
83
91
|
},
|
|
84
92
|
};
|
|
85
93
|
});
|
|
86
94
|
setTimeout(() => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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);
|
|
96
104
|
}, 50);
|
|
97
105
|
await (0, setupRepo_1.setupRepo)({
|
|
98
106
|
repoName: 'kibana',
|
|
@@ -117,18 +125,23 @@ describe('setupRepo', () => {
|
|
|
117
125
|
expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from github.com (one-time operation)');
|
|
118
126
|
});
|
|
119
127
|
});
|
|
120
|
-
describe('if repo already
|
|
121
|
-
|
|
122
|
-
jest
|
|
123
|
-
.spyOn(childProcess, '
|
|
124
|
-
//@ts-expect-error
|
|
125
|
-
.mockImplementation((cmdString, cmdOptions, callback) => {
|
|
128
|
+
describe('if repo is already cloned', () => {
|
|
129
|
+
function mockGitProjectRootPath(value) {
|
|
130
|
+
return (jest
|
|
131
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
126
132
|
//@ts-expect-error
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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');
|
|
132
145
|
await (0, setupRepo_1.setupRepo)({
|
|
133
146
|
accessToken: 'myAccessToken',
|
|
134
147
|
authenticatedUsername: 'sqren_authenticated',
|
|
@@ -138,12 +151,22 @@ describe('setupRepo', () => {
|
|
|
138
151
|
repoName: 'kibana',
|
|
139
152
|
repoOwner: 'elastic',
|
|
140
153
|
});
|
|
141
|
-
|
|
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([
|
|
142
166
|
{
|
|
143
167
|
cmd: 'git rev-parse --show-toplevel',
|
|
144
168
|
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
145
169
|
},
|
|
146
|
-
{ cmd: 'git remote --verbose', cwd: '/path/to/source/repo' },
|
|
147
170
|
{
|
|
148
171
|
cmd: 'git remote rm origin',
|
|
149
172
|
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
@@ -167,19 +190,30 @@ describe('setupRepo', () => {
|
|
|
167
190
|
]);
|
|
168
191
|
});
|
|
169
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
|
+
}
|
|
170
211
|
describe('if repo does not exists locally', () => {
|
|
171
212
|
let spinnerSuccessSpy;
|
|
172
213
|
beforeEach(async () => {
|
|
173
214
|
const oraMock = (0, mocks_1.getOraMock)();
|
|
174
215
|
spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
|
|
175
|
-
|
|
176
|
-
.spyOn(childProcess, 'execAsCallback')
|
|
177
|
-
//@ts-expect-error
|
|
178
|
-
.mockImplementation((cmdString, cmdOptions, callback) => {
|
|
179
|
-
//@ts-expect-error
|
|
180
|
-
callback();
|
|
181
|
-
return { stderr: { on: () => null } };
|
|
182
|
-
});
|
|
216
|
+
mockGitClone();
|
|
183
217
|
await (0, setupRepo_1.setupRepo)({
|
|
184
218
|
accessToken: 'myAccessToken',
|
|
185
219
|
gitHostname: 'github.com',
|
|
@@ -190,7 +224,12 @@ describe('setupRepo', () => {
|
|
|
190
224
|
});
|
|
191
225
|
it('should clone it from github.com', async () => {
|
|
192
226
|
expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from github.com (one-time operation)');
|
|
193
|
-
expect(childProcess.
|
|
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
|
+
]);
|
|
194
233
|
});
|
|
195
234
|
});
|
|
196
235
|
describe('if repo exists locally', () => {
|
|
@@ -199,19 +238,12 @@ describe('setupRepo', () => {
|
|
|
199
238
|
const oraMock = (0, mocks_1.getOraMock)();
|
|
200
239
|
spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
|
|
201
240
|
jest
|
|
202
|
-
.spyOn(gitModule, '
|
|
241
|
+
.spyOn(gitModule, 'getLocalSourceRepoPath')
|
|
203
242
|
.mockResolvedValue('/path/to/source/repo');
|
|
204
243
|
jest
|
|
205
244
|
.spyOn(gitModule, 'getGitConfig')
|
|
206
245
|
.mockResolvedValue('email-or-username');
|
|
207
|
-
|
|
208
|
-
.spyOn(childProcess, 'execAsCallback')
|
|
209
|
-
//@ts-expect-error
|
|
210
|
-
.mockImplementation((cmdString, cmdOptions, callback) => {
|
|
211
|
-
//@ts-expect-error
|
|
212
|
-
callback();
|
|
213
|
-
return { stderr: { on: () => null } };
|
|
214
|
-
});
|
|
246
|
+
mockGitClone();
|
|
215
247
|
await (0, setupRepo_1.setupRepo)({
|
|
216
248
|
repoName: 'kibana',
|
|
217
249
|
repoOwner: 'elastic',
|
|
@@ -220,7 +252,12 @@ describe('setupRepo', () => {
|
|
|
220
252
|
});
|
|
221
253
|
it('should clone it from local folder', async () => {
|
|
222
254
|
expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from /path/to/source/repo (one-time operation)');
|
|
223
|
-
expect(childProcess.
|
|
255
|
+
expect(childProcess.spawnOriginal).toHaveBeenCalledWith('git', [
|
|
256
|
+
'clone',
|
|
257
|
+
'/path/to/source/repo',
|
|
258
|
+
'/myHomeDir/.backport/repositories/elastic/kibana',
|
|
259
|
+
'--progress',
|
|
260
|
+
]);
|
|
224
261
|
});
|
|
225
262
|
});
|
|
226
263
|
describe('if `repoPath` is a parent of current working directory (cwd)', () => {
|