backport 5.6.6 → 6.1.2
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 +186 -50
- package/dist/entrypoint.cli.js +3 -1
- package/dist/entrypoint.module.d.ts +18 -5
- package/dist/entrypoint.module.js +42 -12
- package/dist/entrypoint.module.private.test.d.ts +1 -0
- package/dist/entrypoint.module.private.test.js +34 -0
- package/dist/ink.d.ts +1 -0
- package/dist/ink.js +49 -0
- package/dist/main.d.ts +11 -6
- package/dist/main.js +40 -25
- package/dist/options/ConfigOptions.d.ts +28 -13
- package/dist/options/cliArgs.d.ts +36 -35
- package/dist/options/cliArgs.js +91 -52
- package/dist/options/cliArgs.test.js +35 -43
- package/dist/options/config/config.d.ts +35 -57
- package/dist/options/config/config.js +5 -39
- package/dist/options/config/config.test.js +11 -27
- package/dist/options/config/getOptionsFromGit.d.ts +3 -2
- package/dist/options/config/getOptionsFromGit.js +1 -3
- package/dist/options/config/globalConfig.d.ts +2 -51
- package/dist/options/config/globalConfig.js +9 -12
- package/dist/options/config/globalConfig.test.js +7 -5
- package/dist/options/config/projectConfig.d.ts +2 -51
- package/dist/options/config/projectConfig.js +2 -2
- package/dist/options/config/projectConfig.test.js +53 -16
- package/dist/options/config/readConfigFile.d.ts +44 -41
- package/dist/options/config/readConfigFile.js +30 -4
- package/dist/options/options.d.ts +59 -31
- package/dist/options/options.js +103 -10
- package/dist/options/options.test.js +266 -79
- package/dist/options/parseRequiredOptions.d.ts +19 -14
- package/dist/options/parseRequiredOptions.js +9 -15
- package/dist/options/parseRequiredOptions.test.js +30 -26
- package/dist/runSequentially.d.ts +20 -0
- package/dist/runSequentially.js +41 -0
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +196 -0
- package/dist/runWithOptions.js +7 -14
- package/dist/runWithOptions.test.js +138 -17
- package/dist/scripts/generate-gql.d.ts +1 -0
- package/dist/scripts/generate-gql.js +15 -0
- package/dist/scripts/postinstall.js +4 -4
- package/dist/scripts/postinstall.test.js +9 -2
- package/dist/scripts/runPostinstall.js +1 -1
- package/dist/services/HandledError.d.ts +11 -1
- package/dist/services/HandledError.js +2 -1
- package/dist/services/child-process-promisified.d.ts +1 -1
- package/dist/services/child-process-promisified.js +1 -1
- package/dist/services/env.js +5 -5
- package/dist/services/env.test.js +11 -4
- package/dist/services/fs-promisified.js +4 -4
- package/dist/services/getExpectedTarget.d.ts +9 -0
- package/dist/services/getExpectedTarget.js +77 -0
- package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/getExpectedTargetPullRequests.js +77 -0
- package/dist/services/git.d.ts +20 -6
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +168 -0
- package/dist/services/git.js +93 -67
- package/dist/services/git.test.js +68 -68
- package/dist/services/github/commitFormatters.d.ts +3 -7
- package/dist/services/github/commitFormatters.js +10 -19
- package/dist/services/github/commitFormatters.test.js +2 -24
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -8
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +6 -8
- package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
- package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
- package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
- package/dist/services/github/v3/createPullRequest.d.ts +3 -2
- package/dist/services/github/v3/createPullRequest.js +31 -25
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +110 -0
- package/dist/services/github/v3/createStatusComment.d.ts +11 -0
- package/dist/services/github/v3/createStatusComment.js +95 -0
- package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/services/github/v3/createStatusComment.test.js +209 -0
- package/dist/services/github/v4/FetchPullRequestId.js +1 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +2 -2
- package/dist/services/github/v4/apiRequestV4.js +6 -8
- package/dist/services/github/v4/apiRequestV4.test.js +7 -7
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +3 -4
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +9 -8
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +93 -33
- package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
- package/dist/services/github/v4/fetchAuthorId.js +6 -7
- package/dist/services/github/v4/fetchAuthorId.private.test.js +6 -9
- package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
- package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +4 -4
- package/dist/services/github/v4/fetchCommitBySha.js +14 -12
- package/dist/services/github/v4/fetchCommitBySha.private.test.js +4 -4
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +12 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +70 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +12 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +27 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +88 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +128 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +125 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +77 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
- package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +2 -1
- package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +78 -5
- package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
- package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
- package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -5
- package/dist/services/github/v4/fetchMergedPullRequests.d.ts +18 -19
- package/dist/services/github/v4/fetchMergedPullRequests.js +22 -69
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
- package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchProjectConfig.js +56 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +2 -3
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +3 -3
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
- package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
- package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +67 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +19 -11
- package/dist/services/github/v4/getOptionsFromGithub/index.js +52 -22
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +46 -7
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +16 -16
- package/dist/services/github/v4/getOptionsFromGithub/query.js +16 -15
- package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
- package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
- package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +2 -0
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
- package/dist/services/logger.d.ts +3 -3
- package/dist/services/logger.js +16 -15
- package/dist/services/prompt.test.d.ts +1 -0
- package/dist/services/prompt.test.js +87 -0
- package/dist/services/prompts.d.ts +10 -4
- package/dist/services/prompts.js +85 -22
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +413 -0
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +82 -0
- package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +229 -0
- package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit/sourceCommit.js +86 -0
- package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
- package/dist/services/sourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit.js +86 -0
- package/dist/services/sourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit.test.js +280 -0
- package/dist/test/inquirer.private.test.js +55 -51
- package/dist/test/integration/createSpies.js +6 -6
- package/dist/test/integration/envConstants.js +5 -6
- package/dist/test/integration/helpers.js +1 -1
- package/dist/test/integration/integration.private.test.d.ts +1 -0
- package/dist/test/integration/integration.private.test.js +327 -0
- package/dist/test/integration/integration.test.js +28 -29
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +37 -0
- package/dist/test/nockHelpers.d.ts +1 -1
- package/dist/test/nockHelpers.js +7 -11
- package/dist/test/private/getDevAccessToken.js +1 -1
- package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
- package/dist/test/setupFiles/automatic-mocks.js +1 -51
- package/dist/types/Commit.d.ts +85 -0
- package/dist/types/Commit.js +139 -0
- package/dist/types/commitNode.d.ts +89 -0
- package/dist/types/commitNode.js +139 -0
- package/dist/types/commitNode.test.d.ts +1 -0
- package/dist/types/commitNode.test.js +255 -0
- package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
- package/dist/types/commitWithAssociatedPullRequests.js +145 -0
- package/dist/ui/cherrypickAndCreatePullRequest.test.js +346 -76
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +2 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +95 -67
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
- package/dist/ui/getCommits.d.ts +1 -1
- package/dist/ui/getCommits.js +55 -25
- package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/ui/getCommitsWithoutBackports.js +53 -0
- package/dist/ui/getTargetBranches.d.ts +3 -2
- package/dist/ui/getTargetBranches.js +33 -18
- package/dist/ui/getTargetBranches.test.js +75 -99
- package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
- package/dist/ui/getTargetBranchesFromLabels.js +40 -0
- package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
- package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
- package/dist/ui/maybeSetupRepo.js +11 -10
- package/dist/ui/maybeSetupRepo.test.js +54 -4
- package/dist/utils/excludeUndefined.d.ts +6 -0
- package/dist/utils/excludeUndefined.js +7 -0
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/package.json +37 -51
- package/yarn.lock +2414 -2993
|
@@ -5,8 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getBackportBranchName = exports.cherrypickAndCreateTargetPullRequest = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const
|
|
9
|
-
const lodash_isempty_1 = __importDefault(require("lodash.isempty"));
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
10
9
|
const ora = require("ora");
|
|
11
10
|
const HandledError_1 = require("../services/HandledError");
|
|
12
11
|
const child_process_promisified_1 = require("../services/child-process-promisified");
|
|
@@ -15,22 +14,24 @@ const git_1 = require("../services/git");
|
|
|
15
14
|
const commitFormatters_1 = require("../services/github/commitFormatters");
|
|
16
15
|
const addAssigneesToPullRequest_1 = require("../services/github/v3/addAssigneesToPullRequest");
|
|
17
16
|
const addLabelsToPullRequest_1 = require("../services/github/v3/addLabelsToPullRequest");
|
|
17
|
+
const addReviewersToPullRequest_1 = require("../services/github/v3/addReviewersToPullRequest");
|
|
18
18
|
const createPullRequest_1 = require("../services/github/v3/createPullRequest");
|
|
19
19
|
const enablePullRequestAutoMerge_1 = require("../services/github/v4/enablePullRequestAutoMerge");
|
|
20
20
|
const logger_1 = require("../services/logger");
|
|
21
21
|
const prompts_1 = require("../services/prompts");
|
|
22
22
|
const sequentially_1 = require("../services/sequentially");
|
|
23
|
+
const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
|
|
23
24
|
async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBranch, }) {
|
|
24
25
|
const backportBranch = getBackportBranchName(targetBranch, commits);
|
|
25
|
-
const repoForkOwner = git_1.getRepoForkOwner(options);
|
|
26
|
-
logger_1.consoleLog(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
|
|
26
|
+
const repoForkOwner = (0, git_1.getRepoForkOwner)(options);
|
|
27
|
+
(0, logger_1.consoleLog)(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
|
|
27
28
|
const prPayload = {
|
|
28
29
|
owner: options.repoOwner,
|
|
29
30
|
repo: options.repoName,
|
|
30
|
-
title: createPullRequest_1.getTitle({ options, commits, targetBranch }),
|
|
31
|
-
body: createPullRequest_1.
|
|
31
|
+
title: (0, createPullRequest_1.getTitle)({ options, commits, targetBranch }),
|
|
32
|
+
body: (0, createPullRequest_1.getPullRequestBody)({ options, commits, targetBranch }),
|
|
32
33
|
head: `${repoForkOwner}:${backportBranch}`,
|
|
33
|
-
base: targetBranch,
|
|
34
|
+
base: targetBranch, // eg. 7.x
|
|
34
35
|
};
|
|
35
36
|
const targetPullRequest = await backportViaFilesystem({
|
|
36
37
|
options,
|
|
@@ -40,40 +41,47 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
|
|
|
40
41
|
commits,
|
|
41
42
|
});
|
|
42
43
|
// add assignees to target pull request
|
|
44
|
+
const assignees = options.autoAssign
|
|
45
|
+
? [options.authenticatedUsername]
|
|
46
|
+
: options.assignees;
|
|
43
47
|
if (options.assignees.length > 0) {
|
|
44
|
-
await addAssigneesToPullRequest_1.addAssigneesToPullRequest(options, targetPullRequest.number,
|
|
48
|
+
await (0, addAssigneesToPullRequest_1.addAssigneesToPullRequest)(options, targetPullRequest.number, assignees);
|
|
49
|
+
}
|
|
50
|
+
// add reviewers to target pull request
|
|
51
|
+
if (options.reviewers.length > 0) {
|
|
52
|
+
await (0, addReviewersToPullRequest_1.addReviewersToPullRequest)(options, targetPullRequest.number, options.reviewers);
|
|
45
53
|
}
|
|
46
54
|
// add labels to target pull request
|
|
47
55
|
if (options.targetPRLabels.length > 0) {
|
|
48
|
-
await addLabelsToPullRequest_1.addLabelsToPullRequest(options, targetPullRequest.number, options.targetPRLabels);
|
|
56
|
+
await (0, addLabelsToPullRequest_1.addLabelsToPullRequest)(options, targetPullRequest.number, options.targetPRLabels);
|
|
49
57
|
}
|
|
50
58
|
// make PR auto mergable
|
|
51
59
|
if (options.autoMerge) {
|
|
52
|
-
await enablePullRequestAutoMerge_1.enablePullRequestAutoMerge(options, targetPullRequest.number);
|
|
60
|
+
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)(options, targetPullRequest.number);
|
|
53
61
|
}
|
|
54
62
|
// add labels to source pull requests
|
|
55
63
|
if (options.sourcePRLabels.length > 0) {
|
|
56
64
|
const promises = commits.map((commit) => {
|
|
57
65
|
if (commit.pullNumber) {
|
|
58
|
-
return addLabelsToPullRequest_1.addLabelsToPullRequest(options, commit.pullNumber, options.sourcePRLabels);
|
|
66
|
+
return (0, addLabelsToPullRequest_1.addLabelsToPullRequest)(options, commit.pullNumber, options.sourcePRLabels);
|
|
59
67
|
}
|
|
60
68
|
});
|
|
61
69
|
await Promise.all(promises);
|
|
62
70
|
}
|
|
63
|
-
logger_1.consoleLog(`View pull request: ${targetPullRequest.url}`);
|
|
71
|
+
(0, logger_1.consoleLog)(`View pull request: ${targetPullRequest.url}`);
|
|
64
72
|
return targetPullRequest;
|
|
65
73
|
}
|
|
66
74
|
exports.cherrypickAndCreateTargetPullRequest = cherrypickAndCreateTargetPullRequest;
|
|
67
75
|
async function backportViaFilesystem({ options, prPayload, commits, targetBranch, backportBranch, }) {
|
|
68
76
|
logger_1.logger.info('Backporting via filesystem');
|
|
69
|
-
await git_1.createBackportBranch({ options, targetBranch, backportBranch });
|
|
70
|
-
await sequentially_1.sequentially(commits, (commit) => waitForCherrypick(options, commit, targetBranch));
|
|
77
|
+
await (0, git_1.createBackportBranch)({ options, targetBranch, backportBranch });
|
|
78
|
+
await (0, sequentially_1.sequentially)(commits, (commit) => waitForCherrypick(options, commit, targetBranch));
|
|
71
79
|
if (options.resetAuthor) {
|
|
72
|
-
await git_1.setCommitAuthor(options, options.
|
|
80
|
+
await (0, git_1.setCommitAuthor)(options, options.authenticatedUsername);
|
|
73
81
|
}
|
|
74
|
-
await git_1.pushBackportBranch({ options, backportBranch });
|
|
75
|
-
await git_1.deleteBackportBranch({ options, backportBranch });
|
|
76
|
-
return createPullRequest_1.createPullRequest({ options, prPayload });
|
|
82
|
+
await (0, git_1.pushBackportBranch)({ options, backportBranch });
|
|
83
|
+
await (0, git_1.deleteBackportBranch)({ options, backportBranch });
|
|
84
|
+
return (0, createPullRequest_1.createPullRequest)({ options, prPayload });
|
|
77
85
|
}
|
|
78
86
|
/*
|
|
79
87
|
* Returns the name of the backport branch without remote name
|
|
@@ -87,21 +95,21 @@ function getBackportBranchName(targetBranch, commits) {
|
|
|
87
95
|
const refValues = commits
|
|
88
96
|
.map((commit) => commit.pullNumber
|
|
89
97
|
? `pr-${commit.pullNumber}`
|
|
90
|
-
: `commit-${commitFormatters_1.getShortSha(commit.sha)}`)
|
|
98
|
+
: `commit-${(0, commitFormatters_1.getShortSha)(commit.sha)}`)
|
|
91
99
|
.join('_')
|
|
92
100
|
.slice(0, 200);
|
|
93
101
|
return `backport/${targetBranch}/${refValues}`;
|
|
94
102
|
}
|
|
95
103
|
exports.getBackportBranchName = getBackportBranchName;
|
|
96
104
|
async function waitForCherrypick(options, commit, targetBranch) {
|
|
97
|
-
const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright(commit.
|
|
105
|
+
const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.originalMessage))}`;
|
|
98
106
|
const cherrypickSpinner = ora(spinnerText).start();
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
107
|
+
let conflictingFiles;
|
|
108
|
+
let unstagedFiles;
|
|
109
|
+
let needsResolving;
|
|
103
110
|
try {
|
|
104
|
-
|
|
111
|
+
await (0, git_1.fetchBranch)(options, commit.sourceBranch);
|
|
112
|
+
({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)(options, commit.sha));
|
|
105
113
|
// no conflicts encountered
|
|
106
114
|
if (!needsResolving) {
|
|
107
115
|
cherrypickSpinner.succeed();
|
|
@@ -117,10 +125,9 @@ async function waitForCherrypick(options, commit, targetBranch) {
|
|
|
117
125
|
// resolve conflicts automatically
|
|
118
126
|
if (options.autoFixConflicts) {
|
|
119
127
|
const autoResolveSpinner = ora('Attempting to resolve conflicts automatically').start();
|
|
120
|
-
const
|
|
121
|
-
const repoPath = env_1.getRepoPath(options);
|
|
128
|
+
const repoPath = (0, env_1.getRepoPath)(options);
|
|
122
129
|
const didAutoFix = await options.autoFixConflicts({
|
|
123
|
-
files:
|
|
130
|
+
files: conflictingFiles.map((f) => f.absolute),
|
|
124
131
|
directory: repoPath,
|
|
125
132
|
logger: logger_1.logger,
|
|
126
133
|
targetBranch,
|
|
@@ -132,23 +139,42 @@ async function waitForCherrypick(options, commit, targetBranch) {
|
|
|
132
139
|
}
|
|
133
140
|
autoResolveSpinner.fail();
|
|
134
141
|
}
|
|
142
|
+
const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
|
|
143
|
+
options,
|
|
144
|
+
commit,
|
|
145
|
+
targetBranch,
|
|
146
|
+
conflictingFiles: conflictingFiles.map((f) => f.relative).slice(0, 50),
|
|
147
|
+
});
|
|
135
148
|
if (options.ci) {
|
|
136
|
-
throw new HandledError_1.HandledError(
|
|
149
|
+
throw new HandledError_1.HandledError(`Commit could not be cherrypicked due to conflicts`, {
|
|
150
|
+
type: 'commitsWithoutBackports',
|
|
151
|
+
commitsWithoutBackports,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
(0, logger_1.consoleLog)(chalk_1.default.bold('\nThe commit could not be backported due to conflicts\n'));
|
|
155
|
+
if (commitsWithoutBackports.length > 0) {
|
|
156
|
+
(0, logger_1.consoleLog)(chalk_1.default.italic(`Hint: Before fixing the conflicts manually you should consider backporting the following commits to "${targetBranch}":`));
|
|
157
|
+
(0, logger_1.consoleLog)(`${commitsWithoutBackports.map((c) => c.formatted).join('\n')}\n\n`);
|
|
137
158
|
}
|
|
138
159
|
/*
|
|
139
160
|
* Commit could not be cleanly cherrypicked: Initiating conflict resolution
|
|
140
161
|
*/
|
|
141
162
|
if (options.editor) {
|
|
142
|
-
const repoPath = env_1.getRepoPath(options);
|
|
143
|
-
await child_process_promisified_1.exec(`${options.editor} ${repoPath}`, {});
|
|
163
|
+
const repoPath = (0, env_1.getRepoPath)(options);
|
|
164
|
+
await (0, child_process_promisified_1.exec)(`${options.editor} ${repoPath}`, {});
|
|
144
165
|
}
|
|
145
166
|
// list files with conflict markers + unstaged files and require user to resolve them
|
|
146
|
-
await listConflictingAndUnstagedFiles(
|
|
167
|
+
await listConflictingAndUnstagedFiles({
|
|
168
|
+
retries: 0,
|
|
169
|
+
options,
|
|
170
|
+
conflictingFiles: conflictingFiles.map((f) => f.absolute),
|
|
171
|
+
unstagedFiles,
|
|
172
|
+
});
|
|
147
173
|
// Conflicts should be resolved and files staged at this point
|
|
148
174
|
const stagingSpinner = ora(`Finalizing cherrypick`).start();
|
|
149
175
|
try {
|
|
150
176
|
// Run `git commit`
|
|
151
|
-
await git_1.commitChanges(commit, options);
|
|
177
|
+
await (0, git_1.commitChanges)(commit, options);
|
|
152
178
|
stagingSpinner.succeed();
|
|
153
179
|
}
|
|
154
180
|
catch (e) {
|
|
@@ -156,43 +182,45 @@ async function waitForCherrypick(options, commit, targetBranch) {
|
|
|
156
182
|
throw e;
|
|
157
183
|
}
|
|
158
184
|
}
|
|
159
|
-
async function listConflictingAndUnstagedFiles(options) {
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
: '';
|
|
179
|
-
const unstagedSection = hasUnstagedFiles
|
|
180
|
-
? `Unstaged files:\n${chalk_1.default.reset(unstagedFiles.map((file) => ` - ${file}`).join('\n'))}`
|
|
181
|
-
: '';
|
|
182
|
-
const res = await prompts_1.confirmPrompt(`${chalk_1.default.reset(`Please fix the issues in: ${env_1.getRepoPath(options)}`)}
|
|
185
|
+
async function listConflictingAndUnstagedFiles({ retries, options, conflictingFiles, unstagedFiles, }) {
|
|
186
|
+
const hasUnstagedFiles = !(0, lodash_1.isEmpty)((0, lodash_1.difference)(unstagedFiles, conflictingFiles));
|
|
187
|
+
const hasConflictingFiles = !(0, lodash_1.isEmpty)(conflictingFiles);
|
|
188
|
+
if (!hasConflictingFiles && !hasUnstagedFiles) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
// add divider between prompts
|
|
192
|
+
if (retries > 0) {
|
|
193
|
+
(0, logger_1.consoleLog)('\n----------------------------------------\n');
|
|
194
|
+
}
|
|
195
|
+
const header = chalk_1.default.reset(`Fix the following conflicts manually:`);
|
|
196
|
+
// show conflict section if there are conflicting files
|
|
197
|
+
const conflictSection = hasConflictingFiles
|
|
198
|
+
? `Conflicting files:\n${chalk_1.default.reset(conflictingFiles.map((file) => ` - ${file}`).join('\n'))}`
|
|
199
|
+
: '';
|
|
200
|
+
const unstagedSection = hasUnstagedFiles
|
|
201
|
+
? `Unstaged files:\n${chalk_1.default.reset(unstagedFiles.map((file) => ` - ${file}`).join('\n'))}`
|
|
202
|
+
: '';
|
|
203
|
+
const res = await (0, prompts_1.confirmPrompt)(`${header}
|
|
183
204
|
|
|
184
205
|
${conflictSection}
|
|
185
206
|
${unstagedSection}
|
|
186
207
|
|
|
187
208
|
Press ENTER when the conflicts are resolved and files are staged`);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
209
|
+
if (!res) {
|
|
210
|
+
throw new HandledError_1.HandledError('Aborted');
|
|
211
|
+
}
|
|
212
|
+
const MAX_RETRIES = 100;
|
|
213
|
+
if (retries++ > MAX_RETRIES) {
|
|
214
|
+
throw new Error(`Maximum number of retries (${MAX_RETRIES}) exceeded`);
|
|
215
|
+
}
|
|
216
|
+
const [_conflictingFiles, _unstagedFiles] = await Promise.all([
|
|
217
|
+
(0, git_1.getConflictingFiles)(options),
|
|
218
|
+
(0, git_1.getUnstagedFiles)(options),
|
|
219
|
+
]);
|
|
220
|
+
await listConflictingAndUnstagedFiles({
|
|
221
|
+
retries,
|
|
222
|
+
options,
|
|
223
|
+
conflictingFiles: _conflictingFiles.map((file) => file.absolute),
|
|
224
|
+
unstagedFiles: _unstagedFiles,
|
|
225
|
+
});
|
|
198
226
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|