backport 5.6.3 → 6.0.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 +48 -39
- package/dist/entrypoint.cli.js +1 -1
- package/dist/entrypoint.module.d.ts +6 -5
- package/dist/entrypoint.module.js +8 -6
- 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 -24
- package/dist/options/ConfigOptions.d.ts +47 -39
- package/dist/options/cliArgs.d.ts +28 -34
- package/dist/options/cliArgs.js +113 -94
- package/dist/options/cliArgs.test.js +103 -119
- package/dist/options/config/config.d.ts +81 -2
- package/dist/options/config/config.js +46 -6
- package/dist/options/config/config.test.js +24 -2
- package/dist/options/config/getOptionsFromGit.d.ts +3 -0
- package/dist/options/config/getOptionsFromGit.js +10 -0
- package/dist/options/config/globalConfig.d.ts +2 -1
- package/dist/options/config/globalConfig.js +8 -8
- package/dist/options/config/globalConfig.test.js +7 -3
- package/dist/options/config/projectConfig.d.ts +2 -1
- package/dist/options/config/projectConfig.js +3 -3
- package/dist/options/config/projectConfig.test.js +4 -4
- package/dist/options/config/readConfigFile.d.ts +2 -2
- package/dist/options/config/readConfigFile.js +3 -3
- package/dist/options/options.d.ts +40 -27
- package/dist/options/options.js +8 -16
- package/dist/options/options.test.js +66 -26
- package/dist/options/parseRequiredOptions.d.ts +71 -0
- package/dist/options/parseRequiredOptions.js +70 -0
- package/dist/options/parseRequiredOptions.test.d.ts +1 -0
- package/dist/options/parseRequiredOptions.test.js +127 -0
- 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 +235 -0
- package/dist/runWithOptions.js +7 -14
- package/dist/runWithOptions.test.js +142 -16
- 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 +2 -2
- 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 +19 -4
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +168 -0
- package/dist/services/git.js +129 -57
- package/dist/services/git.test.js +155 -51
- 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 +2 -6
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +2 -3
- 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 +33 -24
- package/dist/services/github/v3/createStatusComment.d.ts +11 -0
- package/dist/services/github/v3/createStatusComment.js +97 -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.d.ts +9 -0
- package/dist/services/github/v4/FetchPullRequestId.js +32 -0
- package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
- package/dist/services/github/v4/apiRequestV4.js +8 -10
- package/dist/services/github/v4/apiRequestV4.test.js +7 -7
- package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +9 -0
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +28 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +9 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +51 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +113 -0
- package/dist/services/github/v4/fetchAuthorId.d.ts +5 -0
- package/dist/services/github/v4/fetchAuthorId.js +1 -1
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -3
- package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
- package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +6 -6
- package/dist/services/github/v4/fetchCommitBySha.js +14 -12
- package/dist/services/github/v4/fetchCommitBySha.private.test.js +7 -5
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +5 -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 +67 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +5 -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 +16 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +90 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +130 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +127 -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/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 +81 -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 +3 -2
- package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +81 -8
- package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
- package/dist/services/github/v4/fetchDefaultBranch.d.ts +1 -1
- package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +4 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +52 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +32 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +4 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +72 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +34 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +40 -0
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +72 -0
- package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -3
- package/dist/services/github/v4/fetchMergedPullRequests.d.ts +19 -20
- package/dist/services/github/v4/fetchMergedPullRequests.js +22 -68
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +1 -1
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +8 -6
- 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/index.d.ts +61 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.js +139 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +126 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +34 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.js +44 -0
- 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 +2 -2
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +4 -1
- 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.d.ts +1 -1
- 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 +24 -24
- 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 +396 -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 +78 -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 +114 -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 +81 -45
- package/dist/test/integration/createSpies.d.ts +1 -1
- package/dist/test/integration/createSpies.js +21 -9
- 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 +308 -0
- package/dist/test/integration/integration.test.js +30 -31
- package/dist/test/nockHelpers.d.ts +2 -2
- package/dist/test/nockHelpers.js +3 -7
- package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
- package/dist/test/setupFiles/automatic-mocks.js +0 -22
- 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 +277 -59
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +135 -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/getTargetBranches.d.ts +2 -2
- package/dist/ui/getTargetBranches.js +16 -17
- 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 +9 -9
- package/dist/ui/maybeSetupRepo.test.js +5 -1
- package/package.json +36 -51
- package/yarn.lock +2387 -2979
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const nock_1 = __importDefault(require("nock"));
|
|
26
|
+
const ora_1 = __importDefault(require("ora"));
|
|
27
|
+
const childProcess = __importStar(require("../services/child-process-promisified"));
|
|
28
|
+
const logger = __importStar(require("../services/logger"));
|
|
29
|
+
const prompts = __importStar(require("../services/prompts"));
|
|
30
|
+
const ExecError_1 = require("../test/ExecError");
|
|
31
|
+
const nockHelpers_1 = require("../test/nockHelpers");
|
|
32
|
+
const cherrypickAndCreateTargetPullRequest_1 = require("./cherrypickAndCreateTargetPullRequest");
|
|
33
|
+
const TARGET_PULL_NUMBER = 1338;
|
|
34
|
+
describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
35
|
+
let consoleLogSpy;
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
consoleLogSpy = jest.spyOn(logger, 'consoleLog');
|
|
38
|
+
});
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
consoleLogSpy.mockClear();
|
|
41
|
+
});
|
|
42
|
+
describe('when commit has a pull request reference', () => {
|
|
43
|
+
let res;
|
|
44
|
+
let execSpy;
|
|
45
|
+
let getAddLabelsToTargetPrCalls;
|
|
46
|
+
let getAddLabelsToSourcePr1000Calls;
|
|
47
|
+
let getAddLabelsToSourcePr2000Calls;
|
|
48
|
+
let getCreatePullRequestCalls;
|
|
49
|
+
beforeEach(async () => {
|
|
50
|
+
execSpy = jest
|
|
51
|
+
.spyOn(childProcess, 'exec')
|
|
52
|
+
// mock all exec commands to respond without errors
|
|
53
|
+
.mockResolvedValue({ stdout: '', stderr: '' });
|
|
54
|
+
// ensure labels are added to target PR
|
|
55
|
+
getAddLabelsToTargetPrCalls = mockAddLabelCall(TARGET_PULL_NUMBER);
|
|
56
|
+
// ensure labels are added to source PR
|
|
57
|
+
getAddLabelsToSourcePr1000Calls = mockAddLabelCall(1000);
|
|
58
|
+
getAddLabelsToSourcePr2000Calls = mockAddLabelCall(2000);
|
|
59
|
+
getCreatePullRequestCalls = mockCreatePullRequestCall();
|
|
60
|
+
res = await cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest({
|
|
61
|
+
targetBranch: '6.x',
|
|
62
|
+
options: {
|
|
63
|
+
assignees: [],
|
|
64
|
+
githubApiBaseUrlV3: 'https://api.github.com',
|
|
65
|
+
fork: true,
|
|
66
|
+
targetPRLabels: ['backport'],
|
|
67
|
+
prDescription: 'myPrSuffix',
|
|
68
|
+
prTitle: '[{targetBranch}] {commitMessages}',
|
|
69
|
+
repoName: 'kibana',
|
|
70
|
+
repoOwner: 'elastic',
|
|
71
|
+
username: 'sqren',
|
|
72
|
+
sourceBranch: 'myDefaultSourceBranch',
|
|
73
|
+
sourcePRLabels: [],
|
|
74
|
+
targetBranchChoices: [
|
|
75
|
+
{ name: '7.0', sourcePRLabels: ['7.0.0'] },
|
|
76
|
+
{ name: '6.x', sourcePRLabels: ['6.5.1'] },
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
commits: [
|
|
80
|
+
{
|
|
81
|
+
sourceBranch: '7.x',
|
|
82
|
+
sha: 'mySha',
|
|
83
|
+
formattedMessage: 'myCommitMessage (#1000)',
|
|
84
|
+
originalMessage: 'My original commit message',
|
|
85
|
+
pullNumber: 1000,
|
|
86
|
+
sourcePRLabels: [],
|
|
87
|
+
existingTargetPullRequests: [],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
sourceBranch: '7.x',
|
|
91
|
+
sha: 'mySha2',
|
|
92
|
+
formattedMessage: 'myOtherCommitMessage (#2000)',
|
|
93
|
+
originalMessage: 'My original commit message',
|
|
94
|
+
pullNumber: 2000,
|
|
95
|
+
sourcePRLabels: [],
|
|
96
|
+
existingTargetPullRequests: [],
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
afterEach(() => {
|
|
102
|
+
execSpy.mockClear();
|
|
103
|
+
//@ts-expect-error
|
|
104
|
+
ora_1.default.mockClear();
|
|
105
|
+
});
|
|
106
|
+
it('returns the expected response', () => {
|
|
107
|
+
expect(res).toEqual({ url: 'myHtmlUrl', number: TARGET_PULL_NUMBER });
|
|
108
|
+
});
|
|
109
|
+
it('creates pull request', () => {
|
|
110
|
+
expect(getCreatePullRequestCalls()).toEqual([
|
|
111
|
+
{
|
|
112
|
+
title: '[6.x] myCommitMessage (#1000) | myOtherCommitMessage (#2000)',
|
|
113
|
+
head: 'sqren:backport/6.x/pr-1000_pr-2000',
|
|
114
|
+
base: '6.x',
|
|
115
|
+
body: 'Backports the following commits to 6.x:\n - myCommitMessage (#1000)\n - myOtherCommitMessage (#2000)\n\nmyPrSuffix',
|
|
116
|
+
},
|
|
117
|
+
]);
|
|
118
|
+
});
|
|
119
|
+
it('should make correct git commands', () => {
|
|
120
|
+
expect(execSpy.mock.calls).toMatchSnapshot();
|
|
121
|
+
});
|
|
122
|
+
it('logs correctly', () => {
|
|
123
|
+
expect(consoleLogSpy.mock.calls.length).toBe(2);
|
|
124
|
+
expect(consoleLogSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
|
|
125
|
+
"
|
|
126
|
+
Backporting to 6.x:"
|
|
127
|
+
`);
|
|
128
|
+
expect(consoleLogSpy.mock.calls[1][0]).toMatchInlineSnapshot(`"View pull request: myHtmlUrl"`);
|
|
129
|
+
});
|
|
130
|
+
it('should start the spinner with the correct text', () => {
|
|
131
|
+
expect(ora_1.default.mock.calls.map((call) => call[0]))
|
|
132
|
+
.toMatchInlineSnapshot(`
|
|
133
|
+
Array [
|
|
134
|
+
"Pulling latest changes",
|
|
135
|
+
"Cherry-picking: myCommitMessage (#1000)",
|
|
136
|
+
"Cherry-picking: myOtherCommitMessage (#2000)",
|
|
137
|
+
"Pushing branch \\"sqren:backport/6.x/pr-1000_pr-2000\\"",
|
|
138
|
+
undefined,
|
|
139
|
+
"Creating pull request",
|
|
140
|
+
"Adding labels: \\"backport\\" to #1338",
|
|
141
|
+
"Adding labels: \\"6.5.1\\" to #1000",
|
|
142
|
+
"Adding labels: \\"6.5.1\\" to #2000",
|
|
143
|
+
]
|
|
144
|
+
`);
|
|
145
|
+
});
|
|
146
|
+
it('adds labels to the target pull request', () => {
|
|
147
|
+
expect(getAddLabelsToTargetPrCalls()).toEqual([{ labels: ['backport'] }]);
|
|
148
|
+
});
|
|
149
|
+
it('adds labels to source pull requests', () => {
|
|
150
|
+
expect(getAddLabelsToSourcePr1000Calls()).toEqual([
|
|
151
|
+
{ labels: ['6.5.1'] },
|
|
152
|
+
]);
|
|
153
|
+
expect(getAddLabelsToSourcePr2000Calls()).toEqual([
|
|
154
|
+
{ labels: ['6.5.1'] },
|
|
155
|
+
]);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
describe('when sourcePRLabels includes wildcard', () => {
|
|
159
|
+
let execSpy;
|
|
160
|
+
let getAddLabelsToSourcePr1000Calls;
|
|
161
|
+
let getAddLabelsToSourcePr2000Calls;
|
|
162
|
+
beforeEach(async () => {
|
|
163
|
+
execSpy = jest
|
|
164
|
+
.spyOn(childProcess, 'exec')
|
|
165
|
+
// mock all exec commands to respond without errors
|
|
166
|
+
.mockResolvedValue({ stdout: '', stderr: '' });
|
|
167
|
+
// ensure labels are added to source PR
|
|
168
|
+
getAddLabelsToSourcePr1000Calls = mockAddLabelCall(1000);
|
|
169
|
+
getAddLabelsToSourcePr2000Calls = mockAddLabelCall(2000);
|
|
170
|
+
// mock create pull request
|
|
171
|
+
mockCreatePullRequestCall();
|
|
172
|
+
await cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest({
|
|
173
|
+
targetBranch: '6.x',
|
|
174
|
+
options: {
|
|
175
|
+
assignees: [],
|
|
176
|
+
githubApiBaseUrlV3: 'https://api.github.com',
|
|
177
|
+
fork: true,
|
|
178
|
+
targetPRLabels: ['backport'],
|
|
179
|
+
prDescription: 'myPrSuffix',
|
|
180
|
+
prTitle: '[{targetBranch}] {commitMessages}',
|
|
181
|
+
repoName: 'kibana',
|
|
182
|
+
repoOwner: 'elastic',
|
|
183
|
+
username: 'sqren',
|
|
184
|
+
sourceBranch: 'myDefaultSourceBranch',
|
|
185
|
+
sourcePRLabels: [],
|
|
186
|
+
targetBranchChoices: [
|
|
187
|
+
{ name: '7.0', sourcePRLabels: ['7.0.0'] },
|
|
188
|
+
{ name: '6.x', sourcePRLabels: ['6.5.*'] },
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
commits: [
|
|
192
|
+
{
|
|
193
|
+
sourceBranch: '7.x',
|
|
194
|
+
sha: 'mySha',
|
|
195
|
+
formattedMessage: 'myCommitMessage (#1000)',
|
|
196
|
+
originalMessage: 'My original commit message',
|
|
197
|
+
pullNumber: 1000,
|
|
198
|
+
sourcePRLabels: [],
|
|
199
|
+
existingTargetPullRequests: [],
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
sourceBranch: '7.x',
|
|
203
|
+
sha: 'mySha2',
|
|
204
|
+
formattedMessage: 'myOtherCommitMessage (#2000)',
|
|
205
|
+
originalMessage: 'My original commit message',
|
|
206
|
+
pullNumber: 2000,
|
|
207
|
+
sourcePRLabels: [],
|
|
208
|
+
existingTargetPullRequests: [],
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
afterEach(() => {
|
|
214
|
+
execSpy.mockClear();
|
|
215
|
+
//@ts-expect-error
|
|
216
|
+
ora_1.default.mockClear();
|
|
217
|
+
});
|
|
218
|
+
it('does not add labels to source pull requests', () => {
|
|
219
|
+
expect(getAddLabelsToSourcePr1000Calls()).toEqual([]);
|
|
220
|
+
expect(getAddLabelsToSourcePr2000Calls()).toEqual([]);
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
describe('when commit does not have a pull request reference', () => {
|
|
224
|
+
let res;
|
|
225
|
+
let getCreatePullRequestCalls;
|
|
226
|
+
let getAddLabelsToTargetPrCalls;
|
|
227
|
+
beforeEach(async () => {
|
|
228
|
+
// mock all exec commands to respond without errors
|
|
229
|
+
jest
|
|
230
|
+
.spyOn(childProcess, 'exec')
|
|
231
|
+
.mockResolvedValue({ stdout: '', stderr: '' });
|
|
232
|
+
getCreatePullRequestCalls = mockCreatePullRequestCall();
|
|
233
|
+
// ensure labels are added to target PR
|
|
234
|
+
getAddLabelsToTargetPrCalls = mockAddLabelCall(TARGET_PULL_NUMBER);
|
|
235
|
+
res = await cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest({
|
|
236
|
+
targetBranch: '6.x',
|
|
237
|
+
options: {
|
|
238
|
+
assignees: [],
|
|
239
|
+
githubApiBaseUrlV3: 'https://api.github.com',
|
|
240
|
+
fork: true,
|
|
241
|
+
targetPRLabels: ['backport'],
|
|
242
|
+
prTitle: '[{targetBranch}] {commitMessages}',
|
|
243
|
+
repoName: 'kibana',
|
|
244
|
+
repoOwner: 'elastic',
|
|
245
|
+
username: 'sqren',
|
|
246
|
+
sourcePRLabels: [],
|
|
247
|
+
targetBranchChoices: [
|
|
248
|
+
{ name: '7.0', sourcePRLabels: ['7.0.0'] },
|
|
249
|
+
{ name: '6.x', sourcePRLabels: ['6.5.1'] },
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
commits: [
|
|
253
|
+
{
|
|
254
|
+
sourceBranch: '7.x',
|
|
255
|
+
sha: 'mySha',
|
|
256
|
+
formattedMessage: 'myCommitMessage (mySha)',
|
|
257
|
+
originalMessage: 'My original commit message',
|
|
258
|
+
sourcePRLabels: [],
|
|
259
|
+
existingTargetPullRequests: [],
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
it('creates pull request', () => {
|
|
265
|
+
expect(getCreatePullRequestCalls()).toEqual([
|
|
266
|
+
{
|
|
267
|
+
title: '[6.x] myCommitMessage (mySha)',
|
|
268
|
+
head: 'sqren:backport/6.x/commit-mySha',
|
|
269
|
+
base: '6.x',
|
|
270
|
+
body: 'Backports the following commits to 6.x:\n - myCommitMessage (mySha)',
|
|
271
|
+
},
|
|
272
|
+
]);
|
|
273
|
+
});
|
|
274
|
+
it('returns the expected response', () => {
|
|
275
|
+
expect(res).toEqual({ url: 'myHtmlUrl', number: TARGET_PULL_NUMBER });
|
|
276
|
+
});
|
|
277
|
+
it('adds labels to the target pull request', () => {
|
|
278
|
+
expect(getAddLabelsToTargetPrCalls()).toEqual([{ labels: ['backport'] }]);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
describe('when cherry-picking fails', () => {
|
|
282
|
+
let res;
|
|
283
|
+
let promptSpy;
|
|
284
|
+
let execSpy;
|
|
285
|
+
let getCreatePullRequestCalls;
|
|
286
|
+
beforeEach(async () => {
|
|
287
|
+
// spies
|
|
288
|
+
promptSpy = jest.spyOn(prompts, 'confirmPrompt').mockResolvedValue(true);
|
|
289
|
+
execSpy = setupExecSpy();
|
|
290
|
+
getCreatePullRequestCalls = mockCreatePullRequestCall();
|
|
291
|
+
res = await cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest({
|
|
292
|
+
targetBranch: '6.x',
|
|
293
|
+
options: {
|
|
294
|
+
assignees: [],
|
|
295
|
+
fork: true,
|
|
296
|
+
targetPRLabels: ['backport'],
|
|
297
|
+
prTitle: '[{targetBranch}] {commitMessages}',
|
|
298
|
+
repoName: 'kibana',
|
|
299
|
+
repoOwner: 'elastic',
|
|
300
|
+
username: 'sqren',
|
|
301
|
+
sourceBranch: 'myDefaultSourceBranch',
|
|
302
|
+
sourcePRLabels: [],
|
|
303
|
+
targetBranchChoices: [],
|
|
304
|
+
},
|
|
305
|
+
commits: [
|
|
306
|
+
{
|
|
307
|
+
sourceBranch: '7.x',
|
|
308
|
+
sha: 'mySha',
|
|
309
|
+
formattedMessage: 'myCommitMessage (mySha)',
|
|
310
|
+
originalMessage: 'My original commit message',
|
|
311
|
+
sourcePRLabels: [],
|
|
312
|
+
existingTargetPullRequests: [],
|
|
313
|
+
},
|
|
314
|
+
],
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
afterEach(() => {
|
|
318
|
+
promptSpy.mockClear();
|
|
319
|
+
execSpy.mockClear();
|
|
320
|
+
//@ts-expect-error
|
|
321
|
+
ora_1.default.mockClear();
|
|
322
|
+
});
|
|
323
|
+
it('creates pull request', () => {
|
|
324
|
+
expect(getCreatePullRequestCalls()).toEqual([
|
|
325
|
+
{
|
|
326
|
+
title: '[6.x] myCommitMessage (mySha)',
|
|
327
|
+
head: 'sqren:backport/6.x/commit-mySha',
|
|
328
|
+
base: '6.x',
|
|
329
|
+
body: 'Backports the following commits to 6.x:\n - myCommitMessage (mySha)',
|
|
330
|
+
},
|
|
331
|
+
]);
|
|
332
|
+
});
|
|
333
|
+
it('returns the expected response', () => {
|
|
334
|
+
expect(res).toEqual({ url: 'myHtmlUrl', number: TARGET_PULL_NUMBER });
|
|
335
|
+
});
|
|
336
|
+
it('shows the right prompts', () => {
|
|
337
|
+
expect(promptSpy.mock.calls.length).toBe(3);
|
|
338
|
+
expect(promptSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
|
|
339
|
+
"Please fix the issues in: /myHomeDir/.backport/repositories/elastic/kibana
|
|
340
|
+
|
|
341
|
+
Conflicting files:
|
|
342
|
+
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
Press ENTER when the conflicts are resolved and files are staged"
|
|
346
|
+
`);
|
|
347
|
+
expect(promptSpy.mock.calls[1][0]).toMatchInlineSnapshot(`
|
|
348
|
+
"Please fix the issues in: /myHomeDir/.backport/repositories/elastic/kibana
|
|
349
|
+
|
|
350
|
+
Conflicting files:
|
|
351
|
+
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
Press ENTER when the conflicts are resolved and files are staged"
|
|
355
|
+
`);
|
|
356
|
+
expect(promptSpy.mock.calls[2][0]).toMatchInlineSnapshot(`
|
|
357
|
+
"Please fix the issues in: /myHomeDir/.backport/repositories/elastic/kibana
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
Unstaged files:
|
|
361
|
+
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
362
|
+
|
|
363
|
+
Press ENTER when the conflicts are resolved and files are staged"
|
|
364
|
+
`);
|
|
365
|
+
});
|
|
366
|
+
it('calls exec correctly', () => {
|
|
367
|
+
expect(execSpy.mock.calls).toMatchSnapshot();
|
|
368
|
+
});
|
|
369
|
+
it('calls ora correctly', () => {
|
|
370
|
+
expect(ora_1.default.mock.calls.map((call) => call[0]))
|
|
371
|
+
.toMatchInlineSnapshot(`
|
|
372
|
+
Array [
|
|
373
|
+
"Pulling latest changes",
|
|
374
|
+
"Cherry-picking: myCommitMessage (mySha)",
|
|
375
|
+
"Finalizing cherrypick",
|
|
376
|
+
"Pushing branch \\"sqren:backport/6.x/commit-mySha\\"",
|
|
377
|
+
undefined,
|
|
378
|
+
"Creating pull request",
|
|
379
|
+
"Adding labels: \\"backport\\" to #1338",
|
|
380
|
+
]
|
|
381
|
+
`);
|
|
382
|
+
});
|
|
383
|
+
it('logs correctly', async () => {
|
|
384
|
+
expect(consoleLogSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
|
|
385
|
+
"
|
|
386
|
+
Backporting to 6.x:"
|
|
387
|
+
`);
|
|
388
|
+
expect(consoleLogSpy.mock.calls[1][0]).toMatchInlineSnapshot(`
|
|
389
|
+
"
|
|
390
|
+
----------------------------------------
|
|
391
|
+
"
|
|
392
|
+
`);
|
|
393
|
+
expect(consoleLogSpy.mock.calls[2][0]).toMatchInlineSnapshot(`
|
|
394
|
+
"
|
|
395
|
+
----------------------------------------
|
|
396
|
+
"
|
|
397
|
+
`);
|
|
398
|
+
expect(consoleLogSpy.mock.calls[3][0]).toMatchInlineSnapshot(`"View pull request: myHtmlUrl"`);
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
function setupExecSpy() {
|
|
403
|
+
let conflictingFilesCheck = 0;
|
|
404
|
+
let unstagedFilesCheck = 0;
|
|
405
|
+
return jest
|
|
406
|
+
.spyOn(childProcess, 'exec')
|
|
407
|
+
.mockImplementation(async (cmd) => {
|
|
408
|
+
// createFeatureBranch
|
|
409
|
+
if (cmd.includes('git checkout -B')) {
|
|
410
|
+
return { stdout: 'create feature branch succeeded', stderr: '' };
|
|
411
|
+
}
|
|
412
|
+
// git fetch
|
|
413
|
+
if (cmd.startsWith('git fetch')) {
|
|
414
|
+
return { stderr: '', stdout: '' };
|
|
415
|
+
}
|
|
416
|
+
// cherrypick
|
|
417
|
+
if (cmd === 'git cherry-pick mySha') {
|
|
418
|
+
throw new ExecError_1.ExecError({ cmd });
|
|
419
|
+
}
|
|
420
|
+
// getConflictingFiles
|
|
421
|
+
if (cmd === 'git --no-pager diff --check') {
|
|
422
|
+
conflictingFilesCheck++;
|
|
423
|
+
if (conflictingFilesCheck >= 4) {
|
|
424
|
+
return { stderr: '', stdout: '' };
|
|
425
|
+
}
|
|
426
|
+
throw new ExecError_1.ExecError({
|
|
427
|
+
code: 2,
|
|
428
|
+
cmd,
|
|
429
|
+
stdout: `conflicting-file.txt:1: leftover conflict marker\nconflicting-file.txt:3: leftover conflict marker\nconflicting-file.txt:5: leftover conflict marker\n`,
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
// getUnstagedFiles
|
|
433
|
+
if (cmd === 'git --no-pager diff --name-only') {
|
|
434
|
+
unstagedFilesCheck++;
|
|
435
|
+
if (unstagedFilesCheck >= 5) {
|
|
436
|
+
return { stderr: '', stdout: '' };
|
|
437
|
+
}
|
|
438
|
+
return { stdout: `conflicting-file.txt\n`, stderr: '' };
|
|
439
|
+
}
|
|
440
|
+
// addUnstagedFiles
|
|
441
|
+
if (cmd === 'git add --update') {
|
|
442
|
+
return { stdout: ``, stderr: '' };
|
|
443
|
+
}
|
|
444
|
+
// finalizeCherrypick
|
|
445
|
+
if (cmd.includes('git commit --no-edit')) {
|
|
446
|
+
return { stdout: ``, stderr: '' };
|
|
447
|
+
}
|
|
448
|
+
// pushFeatureBranch
|
|
449
|
+
if (cmd.startsWith('git push ')) {
|
|
450
|
+
return { stdout: ``, stderr: '' };
|
|
451
|
+
}
|
|
452
|
+
// deleteFeatureBranch
|
|
453
|
+
if (cmd.includes('git branch -D ')) {
|
|
454
|
+
return { stdout: ``, stderr: '' };
|
|
455
|
+
}
|
|
456
|
+
throw new Error(`Missing mock for "${cmd}"`);
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
function mockCreatePullRequestCall() {
|
|
460
|
+
return nockHelpers_1.createNockListener(nock_1.default('https://api.github.com')
|
|
461
|
+
.post('/repos/elastic/kibana/pulls')
|
|
462
|
+
.reply(200, { html_url: 'myHtmlUrl', number: TARGET_PULL_NUMBER }));
|
|
463
|
+
}
|
|
464
|
+
function mockAddLabelCall(pullNumber) {
|
|
465
|
+
return nockHelpers_1.createNockListener(nock_1.default('https://api.github.com')
|
|
466
|
+
.post(`/repos/elastic/kibana/issues/${pullNumber}/labels`)
|
|
467
|
+
.reply(200));
|
|
468
|
+
}
|
package/dist/ui/getCommits.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../options/options';
|
|
2
|
-
export declare function getCommits(options: ValidConfigOptions): Promise<import("../
|
|
2
|
+
export declare function getCommits(options: ValidConfigOptions): Promise<import("../services/sourceCommit/parseSourceCommit").Commit[]>;
|
package/dist/ui/getCommits.js
CHANGED
|
@@ -1,38 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getCommits = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const ora_1 = __importDefault(require("ora"));
|
|
4
9
|
const HandledError_1 = require("../services/HandledError");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
10
|
+
const commitFormatters_1 = require("../services/github/commitFormatters");
|
|
11
|
+
const fetchCommitByPullNumber_1 = require("../services/github/v4/fetchCommits/fetchCommitByPullNumber");
|
|
12
|
+
const fetchCommitBySha_1 = require("../services/github/v4/fetchCommits/fetchCommitBySha");
|
|
13
|
+
const fetchCommitsByAuthor_1 = require("../services/github/v4/fetchCommits/fetchCommitsByAuthor");
|
|
14
|
+
const fetchPullRequestBySearchQuery_1 = require("../services/github/v4/fetchCommits/fetchPullRequestBySearchQuery");
|
|
9
15
|
const prompts_1 = require("../services/prompts");
|
|
16
|
+
function getOraPersistsOption(question, answer) {
|
|
17
|
+
return {
|
|
18
|
+
symbol: chalk_1.default.green('?'),
|
|
19
|
+
text: `${chalk_1.default.bold(question)} ${chalk_1.default.cyan(answer)}`,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
10
22
|
async function getCommits(options) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
const spinner = (0, ora_1.default)().start();
|
|
24
|
+
try {
|
|
25
|
+
if (options.sha) {
|
|
26
|
+
spinner.text = `Loading commit "${(0, commitFormatters_1.getShortSha)(options.sha)}"`;
|
|
27
|
+
const commit = await (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha: options.sha });
|
|
28
|
+
spinner.stopAndPersist(getOraPersistsOption('Select commit', commit.originalMessage));
|
|
29
|
+
return [commit];
|
|
30
|
+
}
|
|
31
|
+
if (options.pullNumber) {
|
|
32
|
+
spinner.text = `Loading pull request #${options.pullNumber}`;
|
|
33
|
+
const commit = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
|
|
17
34
|
...options,
|
|
18
|
-
pullNumber: options.pullNumber,
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
pullNumber: options.pullNumber, // must extract pullNumber to satisfy the ts gods
|
|
36
|
+
});
|
|
37
|
+
// add styles to make it look like a prompt question
|
|
38
|
+
spinner.stopAndPersist(getOraPersistsOption('Select pull request', commit.originalMessage));
|
|
39
|
+
return [commit];
|
|
40
|
+
}
|
|
41
|
+
if (options.ci) {
|
|
42
|
+
throw new HandledError_1.HandledError('When "--ci" flag is enabled either `--sha` or `--pr` must be specified');
|
|
43
|
+
}
|
|
44
|
+
if (options.prFilter) {
|
|
45
|
+
spinner.text = 'Loading pull requests...';
|
|
46
|
+
const commitChoices = await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options);
|
|
47
|
+
spinner.stop();
|
|
48
|
+
return (0, prompts_1.promptForCommits)({
|
|
49
|
+
commitChoices,
|
|
50
|
+
isMultipleChoice: options.multipleCommits,
|
|
51
|
+
showDetails: options.details,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
spinner.text = `Loading commits from branch "${options.sourceBranch}"...`;
|
|
55
|
+
const commitChoices = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(options);
|
|
56
|
+
spinner.stop();
|
|
57
|
+
return (0, prompts_1.promptForCommits)({
|
|
28
58
|
commitChoices,
|
|
29
59
|
isMultipleChoice: options.multipleCommits,
|
|
60
|
+
showDetails: options.details,
|
|
30
61
|
});
|
|
31
62
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
63
|
+
catch (e) {
|
|
64
|
+
spinner.fail();
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
37
67
|
}
|
|
38
68
|
exports.getCommits = getCommits;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../options/options';
|
|
2
|
-
import { Commit } from '../
|
|
2
|
+
import { Commit } from '../services/sourceCommit/parseSourceCommit';
|
|
3
3
|
export declare function getTargetBranches(options: ValidConfigOptions, commits: Commit[]): string[] | Promise<string[]>;
|
|
4
|
-
export declare function getTargetBranchChoices(options: ValidConfigOptions,
|
|
4
|
+
export declare function getTargetBranchChoices(options: ValidConfigOptions, missingTargetBranches: string[], sourceBranch: string): import("../options/ConfigOptions").TargetBranchChoice[];
|
|
@@ -1,51 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getTargetBranchChoices = exports.getTargetBranches = void 0;
|
|
7
|
-
const
|
|
8
|
-
const lodash_isempty_1 = __importDefault(require("lodash.isempty"));
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
9
5
|
const HandledError_1 = require("../services/HandledError");
|
|
10
6
|
const prompts_1 = require("../services/prompts");
|
|
11
|
-
const filterEmpty_1 = require("../utils/filterEmpty");
|
|
12
7
|
function getTargetBranches(options, commits) {
|
|
13
8
|
// target branches already specified (in contrast to letting the user choose from a list)
|
|
14
|
-
if (!
|
|
9
|
+
if (!(0, lodash_1.isEmpty)(options.targetBranches)) {
|
|
15
10
|
return options.targetBranches;
|
|
16
11
|
}
|
|
17
|
-
//
|
|
18
|
-
const
|
|
12
|
+
// target branches from the first commit
|
|
13
|
+
const missingTargetBranches = commits.length === 1
|
|
14
|
+
? commits[0].expectedTargetPullRequests
|
|
15
|
+
.filter((pr) => pr.state === 'MISSING')
|
|
16
|
+
.map((pr) => pr.branch)
|
|
17
|
+
: [];
|
|
19
18
|
// automatically backport to specified target branches
|
|
20
19
|
if (options.ci) {
|
|
21
|
-
if (
|
|
20
|
+
if ((0, lodash_1.isEmpty)(missingTargetBranches)) {
|
|
22
21
|
throw new HandledError_1.HandledError(`There are no branches to backport to. Aborting.`);
|
|
23
22
|
}
|
|
24
|
-
return
|
|
23
|
+
return missingTargetBranches;
|
|
25
24
|
}
|
|
26
25
|
// sourceBranch should be the same for all commits, so picking `sourceBranch` from the first commit should be fine 🤞
|
|
27
26
|
// this is specifically needed when backporting a PR like `backport --pr 123` and the source PR was merged to a non-default (aka non-master) branch.
|
|
28
27
|
const { sourceBranch } = commits[0];
|
|
29
|
-
const targetBranchChoices = getTargetBranchChoices(options,
|
|
28
|
+
const targetBranchChoices = getTargetBranchChoices(options, missingTargetBranches, sourceBranch);
|
|
30
29
|
// render interactive list of branches
|
|
31
|
-
return prompts_1.promptForTargetBranches({
|
|
30
|
+
return (0, prompts_1.promptForTargetBranches)({
|
|
32
31
|
targetBranchChoices,
|
|
33
32
|
isMultipleChoice: options.multipleBranches,
|
|
34
33
|
});
|
|
35
34
|
}
|
|
36
35
|
exports.getTargetBranches = getTargetBranches;
|
|
37
|
-
function getTargetBranchChoices(options,
|
|
36
|
+
function getTargetBranchChoices(options, missingTargetBranches, sourceBranch) {
|
|
38
37
|
// exclude sourceBranch from targetBranchChoices
|
|
39
38
|
const targetBranchesChoices = options.targetBranchChoices.filter((choice) => choice.name !== sourceBranch);
|
|
40
|
-
if (
|
|
39
|
+
if ((0, lodash_1.isEmpty)(targetBranchesChoices)) {
|
|
41
40
|
throw new HandledError_1.HandledError('Missing target branch choices');
|
|
42
41
|
}
|
|
43
42
|
if (!options.branchLabelMapping) {
|
|
44
43
|
return targetBranchesChoices;
|
|
45
44
|
}
|
|
46
|
-
// select target branches based on pull request labels
|
|
45
|
+
// select missing target branches (based on pull request labels)
|
|
47
46
|
return targetBranchesChoices.map((choice) => {
|
|
48
|
-
const isChecked =
|
|
47
|
+
const isChecked = missingTargetBranches.includes(choice.name);
|
|
49
48
|
return { ...choice, checked: isChecked };
|
|
50
49
|
});
|
|
51
50
|
}
|