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
|
@@ -0,0 +1,132 @@
|
|
|
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.confirmPrompt = exports.promptForTargetBranches = exports.promptForCommits = exports.getChoicesForCommitPrompt = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const terminal_link_1 = __importDefault(require("terminal-link"));
|
|
11
|
+
const commitFormatters_1 = require("./github/commitFormatters");
|
|
12
|
+
async function prompt(options) {
|
|
13
|
+
const { promptResult } = (await inquirer_1.default.prompt([
|
|
14
|
+
{ ...options, name: 'promptResult' },
|
|
15
|
+
]));
|
|
16
|
+
return promptResult;
|
|
17
|
+
}
|
|
18
|
+
function getPrStateIcon(state) {
|
|
19
|
+
if (state === 'MERGED') {
|
|
20
|
+
return '🟢';
|
|
21
|
+
}
|
|
22
|
+
if (state === 'NOT_CREATED') {
|
|
23
|
+
return '🔴';
|
|
24
|
+
}
|
|
25
|
+
if (state === 'OPEN') {
|
|
26
|
+
return '🔵';
|
|
27
|
+
}
|
|
28
|
+
// unknown state
|
|
29
|
+
return '🔴';
|
|
30
|
+
}
|
|
31
|
+
function getPrStateText(state) {
|
|
32
|
+
if (state === 'MERGED') {
|
|
33
|
+
return chalk_1.default.gray('Merged');
|
|
34
|
+
}
|
|
35
|
+
if (state === 'NOT_CREATED') {
|
|
36
|
+
return chalk_1.default.gray('Backport not created');
|
|
37
|
+
}
|
|
38
|
+
if (state === 'OPEN') {
|
|
39
|
+
return chalk_1.default.gray('Open, not merged');
|
|
40
|
+
}
|
|
41
|
+
return chalk_1.default.gray('Unknown state');
|
|
42
|
+
}
|
|
43
|
+
function getPrLink(number, url) {
|
|
44
|
+
return url ? `(${(0, terminal_link_1.default)(`#${number}`, url)})` : '';
|
|
45
|
+
}
|
|
46
|
+
function getDetailedPullStatus(c) {
|
|
47
|
+
const items = c.expectedTargetPullRequests.map((pr) => {
|
|
48
|
+
const prLink = getPrLink(pr.number, pr.url);
|
|
49
|
+
return ` └ ${getPrStateIcon(pr.state)} ${pr.branch} ${prLink} ${getPrStateText(pr.state)}`;
|
|
50
|
+
});
|
|
51
|
+
const list = items.length > 0
|
|
52
|
+
? `\n${chalk_1.default.reset(items.join('\n'))}`
|
|
53
|
+
: `\n └ ${chalk_1.default.gray('No backports expected')}`;
|
|
54
|
+
return `${list}\n`;
|
|
55
|
+
}
|
|
56
|
+
function getSimplePullStatus(c) {
|
|
57
|
+
return c.expectedTargetPullRequests
|
|
58
|
+
.map(({ state, branch }) => {
|
|
59
|
+
if (state === 'MERGED') {
|
|
60
|
+
return chalk_1.default.green(branch);
|
|
61
|
+
}
|
|
62
|
+
if (state === 'NOT_CREATED') {
|
|
63
|
+
return chalk_1.default.red(branch);
|
|
64
|
+
}
|
|
65
|
+
if (state === 'OPEN') {
|
|
66
|
+
return chalk_1.default.gray(branch);
|
|
67
|
+
}
|
|
68
|
+
return chalk_1.default.gray('Unknown state');
|
|
69
|
+
})
|
|
70
|
+
.join(', ');
|
|
71
|
+
}
|
|
72
|
+
function getChoicesForCommitPrompt(commits, showDetails) {
|
|
73
|
+
return commits.map((c, i) => {
|
|
74
|
+
const leadingWhitespace = (0, lodash_1.repeat)(' ', 2 - (i + 1).toString().length);
|
|
75
|
+
const position = chalk_1.default.gray(`${i + 1}.${leadingWhitespace}`);
|
|
76
|
+
let name;
|
|
77
|
+
if (showDetails) {
|
|
78
|
+
const message = (0, commitFormatters_1.stripPullNumber)(c.sourceCommit.message);
|
|
79
|
+
const prLink = c.sourcePullRequest
|
|
80
|
+
? ` ` + getPrLink(c.sourcePullRequest.number, c.sourcePullRequest.url)
|
|
81
|
+
: '';
|
|
82
|
+
const pullStatus = getDetailedPullStatus(c);
|
|
83
|
+
name = `${position}${message}${prLink}${pullStatus}`;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const message = (0, commitFormatters_1.getFirstLine)(c.sourceCommit.message);
|
|
87
|
+
const pullStatus = getSimplePullStatus(c);
|
|
88
|
+
name = `${position}${message} ${pullStatus}`;
|
|
89
|
+
}
|
|
90
|
+
const short = c.sourcePullRequest
|
|
91
|
+
? `#${c.sourcePullRequest.number} (${(0, commitFormatters_1.getShortSha)(c.sourcePullRequest.mergeCommit.sha)})`
|
|
92
|
+
: (0, commitFormatters_1.getShortSha)(c.sourceCommit.sha);
|
|
93
|
+
return { name, short, value: c };
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
exports.getChoicesForCommitPrompt = getChoicesForCommitPrompt;
|
|
97
|
+
async function promptForCommits({ commitChoices, isMultipleChoice, showDetails, }) {
|
|
98
|
+
const choices = getChoicesForCommitPrompt(commitChoices, showDetails);
|
|
99
|
+
const res = await prompt({
|
|
100
|
+
loop: false,
|
|
101
|
+
pageSize: 30,
|
|
102
|
+
choices: choices,
|
|
103
|
+
message: 'Select commit',
|
|
104
|
+
type: isMultipleChoice ? 'checkbox' : 'list',
|
|
105
|
+
});
|
|
106
|
+
const selectedCommits = Array.isArray(res) ? res.reverse() : [res];
|
|
107
|
+
return (0, lodash_1.isEmpty)(selectedCommits)
|
|
108
|
+
? promptForCommits({ commitChoices, isMultipleChoice, showDetails })
|
|
109
|
+
: selectedCommits;
|
|
110
|
+
}
|
|
111
|
+
exports.promptForCommits = promptForCommits;
|
|
112
|
+
async function promptForTargetBranches({ targetBranchChoices, isMultipleChoice, }) {
|
|
113
|
+
const res = await prompt({
|
|
114
|
+
loop: false,
|
|
115
|
+
pageSize: 15,
|
|
116
|
+
choices: targetBranchChoices,
|
|
117
|
+
message: 'Select branch',
|
|
118
|
+
type: isMultipleChoice ? 'checkbox' : 'list',
|
|
119
|
+
});
|
|
120
|
+
const selectedBranches = Array.isArray(res) ? res : [res];
|
|
121
|
+
return (0, lodash_1.isEmpty)(selectedBranches)
|
|
122
|
+
? promptForTargetBranches({
|
|
123
|
+
targetBranchChoices,
|
|
124
|
+
isMultipleChoice,
|
|
125
|
+
})
|
|
126
|
+
: selectedBranches;
|
|
127
|
+
}
|
|
128
|
+
exports.promptForTargetBranches = promptForTargetBranches;
|
|
129
|
+
function confirmPrompt(message) {
|
|
130
|
+
return prompt({ message, type: 'confirm' });
|
|
131
|
+
}
|
|
132
|
+
exports.confirmPrompt = confirmPrompt;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ConfigFileOptions } from '../entrypoint.module';
|
|
2
|
+
import { GithubV4Exception } from './github/v4/apiRequestV4';
|
|
3
|
+
export declare const RemoteConfigHistoryFragment: import("graphql").DocumentNode;
|
|
4
|
+
export interface RemoteConfig {
|
|
5
|
+
committedDate: string;
|
|
6
|
+
file: {
|
|
7
|
+
object: {
|
|
8
|
+
text: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface RemoteConfigHistory {
|
|
13
|
+
remoteConfigHistory: {
|
|
14
|
+
edges: Array<{
|
|
15
|
+
remoteConfig: RemoteConfig;
|
|
16
|
+
}> | null;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export declare function parseRemoteConfig(remoteConfig: RemoteConfig): ConfigFileOptions | undefined;
|
|
20
|
+
export declare function swallowMissingConfigFileException<T>(error: GithubV4Exception<T>): T;
|
|
@@ -0,0 +1,52 @@
|
|
|
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.swallowMissingConfigFileException = exports.parseRemoteConfig = exports.RemoteConfigHistoryFragment = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const readConfigFile_1 = require("../options/config/readConfigFile");
|
|
9
|
+
const logger_1 = require("./logger");
|
|
10
|
+
exports.RemoteConfigHistoryFragment = (0, graphql_tag_1.default) `
|
|
11
|
+
fragment RemoteConfigHistoryFragment on Commit {
|
|
12
|
+
remoteConfigHistory: history(first: 1, path: ".backportrc.json") {
|
|
13
|
+
edges {
|
|
14
|
+
remoteConfig: node {
|
|
15
|
+
committedDate
|
|
16
|
+
file(path: ".backportrc.json") {
|
|
17
|
+
... on TreeEntry {
|
|
18
|
+
object {
|
|
19
|
+
... on Blob {
|
|
20
|
+
text
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
function parseRemoteConfig(remoteConfig) {
|
|
31
|
+
try {
|
|
32
|
+
return (0, readConfigFile_1.withConfigMigrations)(JSON.parse(remoteConfig.file.object.text));
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
logger_1.logger.info('Parsing remote config failed', e);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.parseRemoteConfig = parseRemoteConfig;
|
|
40
|
+
function swallowMissingConfigFileException(error) {
|
|
41
|
+
const { data, errors } = error.githubResponse.data;
|
|
42
|
+
const missingConfigError = errors?.some((error) => {
|
|
43
|
+
return error.path?.includes('remoteConfig') && error.type === 'NOT_FOUND';
|
|
44
|
+
});
|
|
45
|
+
// swallow error if it's just the config file that's missing
|
|
46
|
+
if (missingConfigError && data != null) {
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
// Throw unexpected error
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
exports.swallowMissingConfigFileException = swallowMissingConfigFileException;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sequentially<T>(items: T[], handler: (item: T) => Promise<void>): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sequentially = void 0;
|
|
4
|
+
function sequentially(items, handler) {
|
|
5
|
+
return items.reduce(async (p, item) => {
|
|
6
|
+
await p;
|
|
7
|
+
return handler(item);
|
|
8
|
+
}, Promise.resolve());
|
|
9
|
+
}
|
|
10
|
+
exports.sequentially = sequentially;
|
|
@@ -0,0 +1,56 @@
|
|
|
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("./BackportError");
|
|
6
|
+
const env_1 = require("./env");
|
|
7
|
+
const git_1 = require("./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.interactive).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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,278 @@
|
|
|
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 mocks_1 = require("../test/mocks");
|
|
32
|
+
const childProcess = __importStar(require("./child-process-promisified"));
|
|
33
|
+
const gitModule = __importStar(require("./git"));
|
|
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
|
+
interactive: true,
|
|
62
|
+
})).rejects.toThrowError('Simulated git clone failure');
|
|
63
|
+
expect(del_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories/elastic/kibana', { force: true });
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
describe('while cloning the repo', () => {
|
|
67
|
+
it('updates the progress', async () => {
|
|
68
|
+
let onClose;
|
|
69
|
+
let onData;
|
|
70
|
+
const oraMock = (0, mocks_1.getOraMock)();
|
|
71
|
+
const spinnerTextSpy = jest.spyOn(oraMock, 'text', 'set');
|
|
72
|
+
const spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
|
|
73
|
+
jest
|
|
74
|
+
.spyOn(gitModule, 'getLocalSourceRepoPath')
|
|
75
|
+
.mockResolvedValue(undefined);
|
|
76
|
+
jest
|
|
77
|
+
.spyOn(childProcess, 'spawnOriginal')
|
|
78
|
+
//@ts-expect-error
|
|
79
|
+
.mockImplementation(() => {
|
|
80
|
+
return {
|
|
81
|
+
on: (name, cb) => {
|
|
82
|
+
if (name === 'close') {
|
|
83
|
+
onClose = cb;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
stderr: {
|
|
87
|
+
on: (name, handler) => {
|
|
88
|
+
if (name === 'data') {
|
|
89
|
+
onData = handler;
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
setTimeout(() => {
|
|
96
|
+
onData('Receiving objects: 1%');
|
|
97
|
+
onData('Receiving objects: 10%');
|
|
98
|
+
onData('Receiving objects: 20%');
|
|
99
|
+
onData('Receiving objects: 100%');
|
|
100
|
+
onData('Updating files: 1%');
|
|
101
|
+
onData('Updating files: 10%');
|
|
102
|
+
onData('Updating files: 20%');
|
|
103
|
+
onData('Updating files: 100%');
|
|
104
|
+
onClose(0);
|
|
105
|
+
}, 50);
|
|
106
|
+
await (0, setupRepo_1.setupRepo)({
|
|
107
|
+
repoName: 'kibana',
|
|
108
|
+
repoOwner: 'elastic',
|
|
109
|
+
gitHostname: 'github.com',
|
|
110
|
+
cwd: '/path/to/source/repo',
|
|
111
|
+
interactive: true,
|
|
112
|
+
});
|
|
113
|
+
expect(spinnerTextSpy.mock.calls.map((call) => call[0]))
|
|
114
|
+
.toMatchInlineSnapshot(`
|
|
115
|
+
Array [
|
|
116
|
+
"0% Cloning repository from github.com (one-time operation)",
|
|
117
|
+
"1% Cloning repository from github.com (one-time operation)",
|
|
118
|
+
"9% Cloning repository from github.com (one-time operation)",
|
|
119
|
+
"18% Cloning repository from github.com (one-time operation)",
|
|
120
|
+
"90% Cloning repository from github.com (one-time operation)",
|
|
121
|
+
"90% Cloning repository from github.com (one-time operation)",
|
|
122
|
+
"91% Cloning repository from github.com (one-time operation)",
|
|
123
|
+
"92% Cloning repository from github.com (one-time operation)",
|
|
124
|
+
"100% Cloning repository from github.com (one-time operation)",
|
|
125
|
+
]
|
|
126
|
+
`);
|
|
127
|
+
expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from github.com (one-time operation)');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe('if repo is already cloned', () => {
|
|
131
|
+
function mockGitProjectRootPath(value) {
|
|
132
|
+
return (jest
|
|
133
|
+
.spyOn(childProcess, 'spawnPromise')
|
|
134
|
+
//@ts-expect-error
|
|
135
|
+
.mockImplementationOnce(async (cmd, cmdArgs) => {
|
|
136
|
+
if (cmdArgs.includes('rev-parse')) {
|
|
137
|
+
return {
|
|
138
|
+
stdout: value,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
beforeEach(async () => {
|
|
144
|
+
jest.clearAllMocks();
|
|
145
|
+
mockGitProjectRootPath('/myHomeDir/.backport/repositories/elastic/kibana');
|
|
146
|
+
jest.spyOn(gitModule, 'cloneRepo');
|
|
147
|
+
await (0, setupRepo_1.setupRepo)({
|
|
148
|
+
accessToken: 'myAccessToken',
|
|
149
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
150
|
+
cwd: '/path/to/source/repo',
|
|
151
|
+
fork: true,
|
|
152
|
+
repoForkOwner: 'sqren',
|
|
153
|
+
repoName: 'kibana',
|
|
154
|
+
repoOwner: 'elastic',
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
it('should not delete the existing repo', () => {
|
|
158
|
+
expect(del_1.default).not.toHaveBeenCalled();
|
|
159
|
+
});
|
|
160
|
+
it('should not clone repo', () => {
|
|
161
|
+
expect(gitModule.cloneRepo).not.toHaveBeenCalled();
|
|
162
|
+
});
|
|
163
|
+
it('should re-create remotes for both source repo and fork', () => {
|
|
164
|
+
expect(spawnSpy.mock.calls.map(([cmd, cmdArgs, cwd]) => ({
|
|
165
|
+
cmd: `${cmd} ${cmdArgs.join(' ')}`,
|
|
166
|
+
cwd,
|
|
167
|
+
}))).toEqual([
|
|
168
|
+
{
|
|
169
|
+
cmd: 'git rev-parse --show-toplevel',
|
|
170
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
cmd: 'git remote rm origin',
|
|
174
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
cmd: 'git remote rm sqren',
|
|
178
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
cmd: 'git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git',
|
|
182
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
cmd: 'git remote rm elastic',
|
|
186
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
cmd: 'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
|
|
190
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
191
|
+
},
|
|
192
|
+
]);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
function mockGitClone() {
|
|
196
|
+
jest
|
|
197
|
+
.spyOn(childProcess, 'spawnOriginal')
|
|
198
|
+
//@ts-expect-error
|
|
199
|
+
.mockImplementation((cmd, cmdArgs) => {
|
|
200
|
+
if (cmdArgs.includes('clone')) {
|
|
201
|
+
return {
|
|
202
|
+
on: (name, cb) => {
|
|
203
|
+
if (name === 'close') {
|
|
204
|
+
//@ts-expect-error
|
|
205
|
+
cb(0);
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
stderr: { on: () => null },
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
describe('if repo does not exists locally', () => {
|
|
214
|
+
let spinnerSuccessSpy;
|
|
215
|
+
beforeEach(async () => {
|
|
216
|
+
const oraMock = (0, mocks_1.getOraMock)();
|
|
217
|
+
spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
|
|
218
|
+
mockGitClone();
|
|
219
|
+
await (0, setupRepo_1.setupRepo)({
|
|
220
|
+
accessToken: 'myAccessToken',
|
|
221
|
+
gitHostname: 'github.com',
|
|
222
|
+
repoName: 'kibana',
|
|
223
|
+
repoOwner: 'elastic',
|
|
224
|
+
cwd: '/path/to/source/repo',
|
|
225
|
+
interactive: true,
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
it('should clone it from github.com', async () => {
|
|
229
|
+
expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from github.com (one-time operation)');
|
|
230
|
+
expect(childProcess.spawnOriginal).toHaveBeenCalledWith('git', [
|
|
231
|
+
'clone',
|
|
232
|
+
'https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
|
|
233
|
+
'/myHomeDir/.backport/repositories/elastic/kibana',
|
|
234
|
+
'--progress',
|
|
235
|
+
]);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
describe('if repo exists locally', () => {
|
|
239
|
+
let spinnerSuccessSpy;
|
|
240
|
+
beforeEach(async () => {
|
|
241
|
+
const oraMock = (0, mocks_1.getOraMock)();
|
|
242
|
+
spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
|
|
243
|
+
jest
|
|
244
|
+
.spyOn(gitModule, 'getLocalSourceRepoPath')
|
|
245
|
+
.mockResolvedValue('/path/to/source/repo');
|
|
246
|
+
jest
|
|
247
|
+
.spyOn(gitModule, 'getGitConfig')
|
|
248
|
+
.mockResolvedValue('email-or-username');
|
|
249
|
+
mockGitClone();
|
|
250
|
+
await (0, setupRepo_1.setupRepo)({
|
|
251
|
+
repoName: 'kibana',
|
|
252
|
+
repoOwner: 'elastic',
|
|
253
|
+
cwd: '/path/to/source/repo',
|
|
254
|
+
interactive: true,
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
it('should clone it from local folder', async () => {
|
|
258
|
+
expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from /path/to/source/repo (one-time operation)');
|
|
259
|
+
expect(childProcess.spawnOriginal).toHaveBeenCalledWith('git', [
|
|
260
|
+
'clone',
|
|
261
|
+
'/path/to/source/repo',
|
|
262
|
+
'/myHomeDir/.backport/repositories/elastic/kibana',
|
|
263
|
+
'--progress',
|
|
264
|
+
]);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
describe('if `repoPath` is a parent of current working directory (cwd)', () => {
|
|
268
|
+
it('should clone it from local folder', async () => {
|
|
269
|
+
await expect(() => (0, setupRepo_1.setupRepo)({
|
|
270
|
+
repoName: 'kibana',
|
|
271
|
+
repoOwner: 'elastic',
|
|
272
|
+
cwd: '/myHomeDir/.backport/repositories/owner/repo/foo',
|
|
273
|
+
dir: '/myHomeDir/.backport/repositories/owner/repo',
|
|
274
|
+
interactive: true,
|
|
275
|
+
})).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');
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ValidConfigOptions } from '../../options/options';
|
|
2
|
+
import { SourceCommitWithTargetPullRequest } from './parseSourceCommit';
|
|
3
|
+
export declare type ExpectedTargetPullRequest = {
|
|
4
|
+
url?: string;
|
|
5
|
+
number?: number;
|
|
6
|
+
branch: string;
|
|
7
|
+
state: 'OPEN' | 'CLOSED' | 'MERGED' | 'NOT_CREATED';
|
|
8
|
+
mergeCommit?: {
|
|
9
|
+
sha: string;
|
|
10
|
+
message: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare function getExpectedTargetPullRequests({ sourceCommit, latestBranchLabelMapping, }: {
|
|
14
|
+
sourceCommit: SourceCommitWithTargetPullRequest;
|
|
15
|
+
latestBranchLabelMapping: ValidConfigOptions['branchLabelMapping'];
|
|
16
|
+
}): ExpectedTargetPullRequest[];
|