backport 5.6.4 → 6.1.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 +166 -41
- 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 +33 -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 +56 -39
- package/dist/options/cliArgs.d.ts +38 -45
- package/dist/options/cliArgs.js +123 -104
- package/dist/options/cliArgs.test.js +106 -119
- package/dist/options/config/config.d.ts +56 -2
- package/dist/options/config/config.js +12 -6
- package/dist/options/config/config.test.js +11 -6
- package/dist/options/config/getOptionsFromGit.d.ts +4 -0
- package/dist/options/config/getOptionsFromGit.js +8 -0
- package/dist/options/config/globalConfig.d.ts +2 -1
- 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 -1
- package/dist/options/config/projectConfig.js +3 -3
- package/dist/options/config/projectConfig.test.js +54 -17
- package/dist/options/config/readConfigFile.d.ts +53 -2
- package/dist/options/config/readConfigFile.js +31 -5
- package/dist/options/options.d.ts +67 -35
- package/dist/options/options.js +99 -16
- package/dist/options/options.test.js +214 -67
- package/dist/options/parseRequiredOptions.d.ts +71 -0
- package/dist/options/parseRequiredOptions.js +68 -0
- package/dist/options/parseRequiredOptions.test.d.ts +1 -0
- package/dist/options/parseRequiredOptions.test.js +122 -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 +192 -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 +23 -5
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +168 -0
- package/dist/services/git.js +133 -60
- package/dist/services/git.test.js +160 -53
- 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 +32 -26
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +78 -0
- 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 +2 -2
- package/dist/services/github/v4/apiRequestV4.js +9 -11
- 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 +112 -0
- package/dist/services/github/v4/fetchAuthorId.d.ts +10 -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 +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 +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 +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 -5
- 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/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.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/getOptionsFromGithub.d.ts +66 -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 +63 -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 +147 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +37 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.js +47 -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 +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 +105 -61
- 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 +317 -0
- package/dist/test/integration/integration.test.js +30 -31
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +37 -0
- package/dist/test/nockHelpers.d.ts +3 -3
- 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 +333 -76
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +138 -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 +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 +2416 -2987
|
@@ -22,25 +22,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const os_1 = __importDefault(require("os"));
|
|
25
26
|
const nock_1 = __importDefault(require("nock"));
|
|
26
27
|
const ora_1 = __importDefault(require("ora"));
|
|
28
|
+
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
27
29
|
const childProcess = __importStar(require("../services/child-process-promisified"));
|
|
30
|
+
const git = __importStar(require("../services/git"));
|
|
31
|
+
const fetchCommitsByAuthorModule = __importStar(require("../services/github/v4/fetchCommits/fetchCommitsByAuthor"));
|
|
32
|
+
const commitsByAuthorMock_1 = require("../services/github/v4/mocks/commitsByAuthorMock");
|
|
28
33
|
const logger = __importStar(require("../services/logger"));
|
|
29
34
|
const prompts = __importStar(require("../services/prompts"));
|
|
30
35
|
const ExecError_1 = require("../test/ExecError");
|
|
36
|
+
const nockHelpers_1 = require("../test/nockHelpers");
|
|
31
37
|
const cherrypickAndCreateTargetPullRequest_1 = require("./cherrypickAndCreateTargetPullRequest");
|
|
32
38
|
describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
33
39
|
let execSpy;
|
|
34
40
|
let addLabelsScope;
|
|
35
41
|
let consoleLogSpy;
|
|
36
42
|
beforeEach(() => {
|
|
43
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
37
44
|
execSpy = jest
|
|
38
45
|
.spyOn(childProcess, 'exec')
|
|
39
46
|
// mock all exec commands to respond without errors
|
|
40
47
|
.mockResolvedValue({ stdout: '', stderr: '' });
|
|
41
48
|
consoleLogSpy = jest.spyOn(logger, 'consoleLog');
|
|
42
49
|
// ensure labels are added
|
|
43
|
-
addLabelsScope = nock_1.default('https://api.github.com')
|
|
50
|
+
addLabelsScope = (0, nock_1.default)('https://api.github.com')
|
|
44
51
|
.post('/repos/elastic/kibana/issues/1337/labels', {
|
|
45
52
|
labels: ['backport'],
|
|
46
53
|
})
|
|
@@ -53,49 +60,45 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
53
60
|
});
|
|
54
61
|
describe('when commit has a pull request reference', () => {
|
|
55
62
|
let res;
|
|
63
|
+
let createPullRequestCalls;
|
|
56
64
|
beforeEach(async () => {
|
|
57
65
|
const options = {
|
|
58
66
|
assignees: [],
|
|
59
|
-
|
|
67
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
60
68
|
fork: true,
|
|
61
|
-
targetPRLabels: ['backport'],
|
|
62
69
|
prDescription: 'myPrSuffix',
|
|
63
70
|
prTitle: '[{targetBranch}] {commitMessages}',
|
|
64
71
|
repoName: 'kibana',
|
|
65
72
|
repoOwner: 'elastic',
|
|
66
|
-
|
|
73
|
+
reviewers: [],
|
|
67
74
|
sourceBranch: 'myDefaultSourceBranch',
|
|
68
75
|
sourcePRLabels: [],
|
|
76
|
+
targetPRLabels: ['backport'],
|
|
77
|
+
author: 'sqren',
|
|
69
78
|
};
|
|
70
79
|
const commits = [
|
|
71
80
|
{
|
|
81
|
+
committedDate: 'fff',
|
|
72
82
|
sourceBranch: '7.x',
|
|
73
83
|
sha: 'mySha',
|
|
74
|
-
|
|
75
|
-
originalMessage: 'My original commit message',
|
|
84
|
+
originalMessage: 'My original commit message (#1000)',
|
|
76
85
|
pullNumber: 1000,
|
|
77
|
-
|
|
78
|
-
existingTargetPullRequests: [],
|
|
86
|
+
expectedTargetPullRequests: [],
|
|
79
87
|
},
|
|
80
88
|
{
|
|
89
|
+
committedDate: 'ggg',
|
|
81
90
|
sourceBranch: '7.x',
|
|
82
91
|
sha: 'mySha2',
|
|
83
|
-
|
|
84
|
-
originalMessage: 'My original commit message',
|
|
92
|
+
originalMessage: 'My other commit message (#2000)',
|
|
85
93
|
pullNumber: 2000,
|
|
86
|
-
|
|
87
|
-
existingTargetPullRequests: [],
|
|
94
|
+
expectedTargetPullRequests: [],
|
|
88
95
|
},
|
|
89
96
|
];
|
|
90
|
-
const scope = nock_1.default('https://api.github.com')
|
|
91
|
-
.post('/repos/elastic/kibana/pulls'
|
|
92
|
-
title: '[6.x] myCommitMessage (#1000) | myOtherCommitMessage (#2000)',
|
|
93
|
-
head: 'sqren:backport/6.x/pr-1000_pr-2000',
|
|
94
|
-
base: '6.x',
|
|
95
|
-
body: 'Backports the following commits to 6.x:\n - myCommitMessage (#1000)\n - myOtherCommitMessage (#2000)\n\nmyPrSuffix',
|
|
96
|
-
})
|
|
97
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
98
|
+
.post('/repos/elastic/kibana/pulls')
|
|
97
99
|
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
|
98
|
-
|
|
100
|
+
createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
|
|
101
|
+
res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
|
|
99
102
|
options,
|
|
100
103
|
commits,
|
|
101
104
|
targetBranch: '6.x',
|
|
@@ -103,8 +106,26 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
103
106
|
scope.done();
|
|
104
107
|
nock_1.default.cleanAll();
|
|
105
108
|
});
|
|
109
|
+
it('creates the pull request with multiple PR references', () => {
|
|
110
|
+
expect(createPullRequestCalls).toMatchInlineSnapshot(`
|
|
111
|
+
Array [
|
|
112
|
+
Object {
|
|
113
|
+
"base": "6.x",
|
|
114
|
+
"body": "This is an automatic backport of the following commits to 6.x:
|
|
115
|
+
- #1000
|
|
116
|
+
- #2000
|
|
117
|
+
|
|
118
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport) for additional information
|
|
119
|
+
|
|
120
|
+
myPrSuffix",
|
|
121
|
+
"head": "sqren_authenticated:backport/6.x/pr-1000_pr-2000",
|
|
122
|
+
"title": "[6.x] My original commit message (#1000) | My other commit message (#2000)",
|
|
123
|
+
},
|
|
124
|
+
]
|
|
125
|
+
`);
|
|
126
|
+
});
|
|
106
127
|
it('returns the expected response', () => {
|
|
107
|
-
expect(res).toEqual({ url: 'myHtmlUrl', number: 1337 });
|
|
128
|
+
expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
|
|
108
129
|
});
|
|
109
130
|
it('should make correct git commands', () => {
|
|
110
131
|
expect(execSpy.mock.calls).toMatchSnapshot();
|
|
@@ -122,9 +143,9 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
122
143
|
.toMatchInlineSnapshot(`
|
|
123
144
|
Array [
|
|
124
145
|
"Pulling latest changes",
|
|
125
|
-
"Cherry-picking:
|
|
126
|
-
"Cherry-picking:
|
|
127
|
-
"Pushing branch \\"
|
|
146
|
+
"Cherry-picking: My original commit message (#1000)",
|
|
147
|
+
"Cherry-picking: My other commit message (#2000)",
|
|
148
|
+
"Pushing branch \\"sqren_authenticated:backport/6.x/pr-1000_pr-2000\\"",
|
|
128
149
|
undefined,
|
|
129
150
|
"Creating pull request",
|
|
130
151
|
"Adding labels: backport",
|
|
@@ -134,84 +155,102 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
134
155
|
});
|
|
135
156
|
describe('when commit does not have a pull request reference', () => {
|
|
136
157
|
let res;
|
|
158
|
+
let createPullRequestCalls;
|
|
137
159
|
beforeEach(async () => {
|
|
138
160
|
const options = {
|
|
139
161
|
assignees: [],
|
|
140
|
-
|
|
162
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
141
163
|
fork: true,
|
|
142
|
-
targetPRLabels: ['backport'],
|
|
143
164
|
prTitle: '[{targetBranch}] {commitMessages}',
|
|
144
165
|
repoName: 'kibana',
|
|
145
166
|
repoOwner: 'elastic',
|
|
146
|
-
|
|
167
|
+
reviewers: [],
|
|
147
168
|
sourcePRLabels: [],
|
|
169
|
+
targetPRLabels: ['backport'],
|
|
170
|
+
author: 'sqren',
|
|
148
171
|
};
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
172
|
+
const commits = [
|
|
173
|
+
{
|
|
174
|
+
committedDate: 'hhh',
|
|
175
|
+
sourceBranch: '7.x',
|
|
176
|
+
sha: 'mySha',
|
|
177
|
+
originalMessage: 'My original commit message',
|
|
178
|
+
expectedTargetPullRequests: [],
|
|
179
|
+
},
|
|
180
|
+
];
|
|
181
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
182
|
+
.post('/repos/elastic/kibana/pulls')
|
|
156
183
|
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
|
157
|
-
|
|
184
|
+
createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
|
|
185
|
+
res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
|
|
158
186
|
options,
|
|
159
|
-
commits
|
|
160
|
-
{
|
|
161
|
-
sourceBranch: '7.x',
|
|
162
|
-
sha: 'mySha',
|
|
163
|
-
formattedMessage: 'myCommitMessage (mySha)',
|
|
164
|
-
originalMessage: 'My original commit message',
|
|
165
|
-
targetBranchesFromLabels: [],
|
|
166
|
-
existingTargetPullRequests: [],
|
|
167
|
-
},
|
|
168
|
-
],
|
|
187
|
+
commits,
|
|
169
188
|
targetBranch: '6.x',
|
|
170
189
|
});
|
|
171
190
|
scope.done();
|
|
172
191
|
nock_1.default.cleanAll();
|
|
173
192
|
});
|
|
193
|
+
it('creates the pull request with commit reference', () => {
|
|
194
|
+
expect(createPullRequestCalls).toMatchInlineSnapshot(`
|
|
195
|
+
Array [
|
|
196
|
+
Object {
|
|
197
|
+
"base": "6.x",
|
|
198
|
+
"body": "This is an automatic backport of commit mySha to 6.x.
|
|
199
|
+
|
|
200
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport) for additional information",
|
|
201
|
+
"head": "sqren_authenticated:backport/6.x/commit-mySha",
|
|
202
|
+
"title": "[6.x] My original commit message",
|
|
203
|
+
},
|
|
204
|
+
]
|
|
205
|
+
`);
|
|
206
|
+
});
|
|
174
207
|
it('returns the expected response', () => {
|
|
175
|
-
expect(res).toEqual({ url: 'myHtmlUrl', number: 1337 });
|
|
208
|
+
expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
|
|
176
209
|
});
|
|
177
210
|
});
|
|
178
211
|
describe('when cherry-picking fails', () => {
|
|
179
212
|
let res;
|
|
180
213
|
let promptSpy;
|
|
181
214
|
let execSpy;
|
|
215
|
+
let commitsByAuthorCalls;
|
|
216
|
+
let createPullRequestCalls;
|
|
182
217
|
beforeEach(async () => {
|
|
183
218
|
// spies
|
|
184
219
|
promptSpy = jest.spyOn(prompts, 'confirmPrompt').mockResolvedValue(true);
|
|
185
|
-
execSpy =
|
|
220
|
+
execSpy = setupExecSpyForCherryPick();
|
|
186
221
|
const options = {
|
|
187
222
|
assignees: [],
|
|
223
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
188
224
|
fork: true,
|
|
189
|
-
|
|
225
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
190
226
|
prTitle: '[{targetBranch}] {commitMessages}',
|
|
191
227
|
repoName: 'kibana',
|
|
192
228
|
repoOwner: 'elastic',
|
|
193
|
-
|
|
229
|
+
reviewers: [],
|
|
194
230
|
sourceBranch: 'myDefaultSourceBranch',
|
|
195
231
|
sourcePRLabels: [],
|
|
232
|
+
targetPRLabels: ['backport'],
|
|
233
|
+
author: 'sqren',
|
|
196
234
|
};
|
|
197
|
-
const scope = nock_1.default('https://api.github.com')
|
|
198
|
-
.post('/repos/elastic/kibana/pulls'
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
235
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
236
|
+
.post('/repos/elastic/kibana/pulls')
|
|
237
|
+
.reply(200, { number: 1337, html_url: 'myHtmlUrl' });
|
|
238
|
+
createPullRequestCalls = (0, nockHelpers_1.listenForCallsToNockScope)(scope);
|
|
239
|
+
commitsByAuthorCalls =
|
|
240
|
+
(0, nockHelpers_1.mockGqlRequest)({
|
|
241
|
+
name: 'CommitsByAuthor',
|
|
242
|
+
statusCode: 200,
|
|
243
|
+
body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
|
|
244
|
+
});
|
|
245
|
+
res = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
|
|
206
246
|
options,
|
|
207
247
|
commits: [
|
|
208
248
|
{
|
|
249
|
+
committedDate: 'eee',
|
|
209
250
|
sourceBranch: '7.x',
|
|
210
251
|
sha: 'mySha',
|
|
211
|
-
formattedMessage: 'myCommitMessage',
|
|
212
252
|
originalMessage: 'My original commit message',
|
|
213
|
-
|
|
214
|
-
existingTargetPullRequests: [],
|
|
253
|
+
expectedTargetPullRequests: [],
|
|
215
254
|
},
|
|
216
255
|
],
|
|
217
256
|
targetBranch: '6.x',
|
|
@@ -219,13 +258,27 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
219
258
|
scope.done();
|
|
220
259
|
nock_1.default.cleanAll();
|
|
221
260
|
});
|
|
222
|
-
it('creates pull request', () => {
|
|
223
|
-
expect(
|
|
261
|
+
it('creates the pull request with commit reference', () => {
|
|
262
|
+
expect(createPullRequestCalls).toMatchInlineSnapshot(`
|
|
263
|
+
Array [
|
|
264
|
+
Object {
|
|
265
|
+
"base": "6.x",
|
|
266
|
+
"body": "This is an automatic backport of commit mySha to 6.x.
|
|
267
|
+
|
|
268
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport) for additional information",
|
|
269
|
+
"head": "sqren_authenticated:backport/6.x/commit-mySha",
|
|
270
|
+
"title": "[6.x] My original commit message",
|
|
271
|
+
},
|
|
272
|
+
]
|
|
273
|
+
`);
|
|
274
|
+
});
|
|
275
|
+
it('returns the expected response', () => {
|
|
276
|
+
expect(res).toEqual({ didUpdate: false, url: 'myHtmlUrl', number: 1337 });
|
|
224
277
|
});
|
|
225
278
|
it('shows the right prompts', () => {
|
|
226
|
-
expect(promptSpy.mock.calls.length).toBe(
|
|
279
|
+
expect(promptSpy.mock.calls.length).toBe(4);
|
|
227
280
|
expect(promptSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
|
|
228
|
-
"
|
|
281
|
+
"Fix the following conflicts manually:
|
|
229
282
|
|
|
230
283
|
Conflicting files:
|
|
231
284
|
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
@@ -234,7 +287,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
234
287
|
Press ENTER when the conflicts are resolved and files are staged"
|
|
235
288
|
`);
|
|
236
289
|
expect(promptSpy.mock.calls[1][0]).toMatchInlineSnapshot(`
|
|
237
|
-
"
|
|
290
|
+
"Fix the following conflicts manually:
|
|
238
291
|
|
|
239
292
|
Conflicting files:
|
|
240
293
|
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
@@ -243,13 +296,25 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
243
296
|
Press ENTER when the conflicts are resolved and files are staged"
|
|
244
297
|
`);
|
|
245
298
|
expect(promptSpy.mock.calls[2][0]).toMatchInlineSnapshot(`
|
|
246
|
-
"
|
|
247
|
-
|
|
299
|
+
"Fix the following conflicts manually:
|
|
248
300
|
|
|
249
|
-
|
|
301
|
+
Conflicting files:
|
|
250
302
|
- /myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt
|
|
251
303
|
|
|
304
|
+
|
|
252
305
|
Press ENTER when the conflicts are resolved and files are staged"
|
|
306
|
+
`);
|
|
307
|
+
});
|
|
308
|
+
it('commitsByAuthor is called with correct arguments', () => {
|
|
309
|
+
expect(commitsByAuthorCalls[0].variables).toMatchInlineSnapshot(`
|
|
310
|
+
Object {
|
|
311
|
+
"authorId": null,
|
|
312
|
+
"commitPath": "conflicting-file.txt",
|
|
313
|
+
"maxNumber": 10,
|
|
314
|
+
"repoName": "kibana",
|
|
315
|
+
"repoOwner": "elastic",
|
|
316
|
+
"sourceBranch": "myDefaultSourceBranch",
|
|
317
|
+
}
|
|
253
318
|
`);
|
|
254
319
|
});
|
|
255
320
|
it('calls exec correctly', () => {
|
|
@@ -260,9 +325,9 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
260
325
|
.toMatchInlineSnapshot(`
|
|
261
326
|
Array [
|
|
262
327
|
"Pulling latest changes",
|
|
263
|
-
"Cherry-picking:
|
|
328
|
+
"Cherry-picking: My original commit message",
|
|
264
329
|
"Finalizing cherrypick",
|
|
265
|
-
"Pushing branch \\"
|
|
330
|
+
"Pushing branch \\"sqren_authenticated:backport/6.x/commit-mySha\\"",
|
|
266
331
|
undefined,
|
|
267
332
|
"Creating pull request",
|
|
268
333
|
"Adding labels: backport",
|
|
@@ -276,7 +341,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
276
341
|
`);
|
|
277
342
|
expect(consoleLogSpy.mock.calls[1][0]).toMatchInlineSnapshot(`
|
|
278
343
|
"
|
|
279
|
-
|
|
344
|
+
The commit could not be backported due to conflicts
|
|
280
345
|
"
|
|
281
346
|
`);
|
|
282
347
|
expect(consoleLogSpy.mock.calls[2][0]).toMatchInlineSnapshot(`
|
|
@@ -284,11 +349,199 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
284
349
|
----------------------------------------
|
|
285
350
|
"
|
|
286
351
|
`);
|
|
287
|
-
expect(consoleLogSpy.mock.calls[3][0]).toMatchInlineSnapshot(`
|
|
352
|
+
expect(consoleLogSpy.mock.calls[3][0]).toMatchInlineSnapshot(`
|
|
353
|
+
"
|
|
354
|
+
----------------------------------------
|
|
355
|
+
"
|
|
356
|
+
`);
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
describe('getCommitsWithoutBackports', () => {
|
|
361
|
+
afterEach(() => {
|
|
362
|
+
jest.restoreAllMocks();
|
|
363
|
+
});
|
|
364
|
+
describe('expectedTargetPullRequests', () => {
|
|
365
|
+
function setup({ expectedTargetPullRequests, }) {
|
|
366
|
+
// simulate 1 unbackported commit
|
|
367
|
+
jest
|
|
368
|
+
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
369
|
+
.mockResolvedValueOnce([
|
|
370
|
+
{
|
|
371
|
+
committedDate: '10',
|
|
372
|
+
expectedTargetPullRequests,
|
|
373
|
+
originalMessage: 'First commit (#1)',
|
|
374
|
+
sha: 'xyz',
|
|
375
|
+
sourceBranch: 'main',
|
|
376
|
+
pullUrl: 'https://www.github.com/foo',
|
|
377
|
+
},
|
|
378
|
+
]);
|
|
379
|
+
// simulate commit is definitely not backported
|
|
380
|
+
jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
|
|
381
|
+
return (0, cherrypickAndCreateTargetPullRequest_1.getCommitsWithoutBackports)({
|
|
382
|
+
options: {},
|
|
383
|
+
commit: {
|
|
384
|
+
committedDate: '100',
|
|
385
|
+
expectedTargetPullRequests: [],
|
|
386
|
+
originalMessage: 'Second commit (#2)',
|
|
387
|
+
sha: 'abc',
|
|
388
|
+
sourceBranch: 'main',
|
|
389
|
+
},
|
|
390
|
+
targetBranch: '7.x',
|
|
391
|
+
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
it('should display unbackported commits if no backports were created', async () => {
|
|
395
|
+
const commitsWithoutBackports = await setup({
|
|
396
|
+
expectedTargetPullRequests: [],
|
|
397
|
+
});
|
|
398
|
+
expect(commitsWithoutBackports[0].formatted).toEqual(' - First commit (#1)\n https://www.github.com/foo');
|
|
399
|
+
});
|
|
400
|
+
it('should display as pending backport if a backport is OPEN', async () => {
|
|
401
|
+
const commitsWithoutBackports = await setup({
|
|
402
|
+
expectedTargetPullRequests: [{ state: 'OPEN', branch: '7.x' }],
|
|
403
|
+
});
|
|
404
|
+
expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo');
|
|
405
|
+
});
|
|
406
|
+
it('should not display commit as unbackported if a backport was MERGED', async () => {
|
|
407
|
+
const commitsWithoutBackports = await setup({
|
|
408
|
+
expectedTargetPullRequests: [{ state: 'MERGED', branch: '7.x' }],
|
|
409
|
+
});
|
|
410
|
+
expect(commitsWithoutBackports).toEqual([]);
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
describe('commitDate', () => {
|
|
414
|
+
function setup({ offendingCommitDate, currentCommitDate, }) {
|
|
415
|
+
// simulate 1 commit with a pending backport
|
|
416
|
+
jest
|
|
417
|
+
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
418
|
+
.mockResolvedValueOnce([
|
|
419
|
+
{
|
|
420
|
+
committedDate: offendingCommitDate,
|
|
421
|
+
expectedTargetPullRequests: [],
|
|
422
|
+
originalMessage: 'First commit (#1)',
|
|
423
|
+
sha: 'xyz',
|
|
424
|
+
sourceBranch: 'main',
|
|
425
|
+
},
|
|
426
|
+
]);
|
|
427
|
+
// simulate commit is definitely not backported
|
|
428
|
+
jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
|
|
429
|
+
return (0, cherrypickAndCreateTargetPullRequest_1.getCommitsWithoutBackports)({
|
|
430
|
+
options: {},
|
|
431
|
+
commit: {
|
|
432
|
+
committedDate: currentCommitDate,
|
|
433
|
+
expectedTargetPullRequests: [],
|
|
434
|
+
originalMessage: 'Second commit (#2)',
|
|
435
|
+
sha: 'abc',
|
|
436
|
+
sourceBranch: 'main',
|
|
437
|
+
},
|
|
438
|
+
targetBranch: '7.x',
|
|
439
|
+
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
it('should not display commit as unbackport if is newer than the commit currently being backported', async () => {
|
|
443
|
+
const commitsWithoutBackports = await setup({
|
|
444
|
+
offendingCommitDate: '100',
|
|
445
|
+
currentCommitDate: '10',
|
|
446
|
+
});
|
|
447
|
+
expect(commitsWithoutBackports).toEqual([]);
|
|
448
|
+
});
|
|
449
|
+
it('should display commit as unbackport if is older than the commit currently being backported', async () => {
|
|
450
|
+
const commitsWithoutBackports = await setup({
|
|
451
|
+
offendingCommitDate: '10',
|
|
452
|
+
currentCommitDate: '100',
|
|
453
|
+
});
|
|
454
|
+
expect(commitsWithoutBackports[0].formatted).toEqual(' - First commit (#1)');
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
describe('isCommitInBranch', () => {
|
|
458
|
+
function setup({ isCommitInBranch }) {
|
|
459
|
+
// simulate 1 unbackported commit
|
|
460
|
+
jest
|
|
461
|
+
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
462
|
+
.mockResolvedValueOnce([
|
|
463
|
+
{
|
|
464
|
+
committedDate: '10',
|
|
465
|
+
expectedTargetPullRequests: [],
|
|
466
|
+
originalMessage: 'First commit (#1)',
|
|
467
|
+
sha: 'xyz',
|
|
468
|
+
sourceBranch: 'main',
|
|
469
|
+
},
|
|
470
|
+
]);
|
|
471
|
+
// simulate commit is definitely not backported
|
|
472
|
+
jest
|
|
473
|
+
.spyOn(git, 'getIsCommitInBranch')
|
|
474
|
+
.mockResolvedValueOnce(isCommitInBranch);
|
|
475
|
+
return (0, cherrypickAndCreateTargetPullRequest_1.getCommitsWithoutBackports)({
|
|
476
|
+
options: {},
|
|
477
|
+
commit: {
|
|
478
|
+
committedDate: '100',
|
|
479
|
+
expectedTargetPullRequests: [],
|
|
480
|
+
originalMessage: 'Second commit (#2)',
|
|
481
|
+
sha: 'abc',
|
|
482
|
+
sourceBranch: 'main',
|
|
483
|
+
},
|
|
484
|
+
targetBranch: '7.x',
|
|
485
|
+
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
it('should not display commit as unbackport if `isCommitInBranch=true`', async () => {
|
|
489
|
+
const commitsWithoutBackports = await setup({ isCommitInBranch: true });
|
|
490
|
+
expect(commitsWithoutBackports).toEqual([]);
|
|
491
|
+
});
|
|
492
|
+
it('should display commit as unbackport if `isCommitInBranch=false`', async () => {
|
|
493
|
+
const commitsWithoutBackports = await setup({ isCommitInBranch: false });
|
|
494
|
+
expect(commitsWithoutBackports[0].formatted).toEqual(' - First commit (#1)');
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
describe('targetBranch', () => {
|
|
498
|
+
function setup({ offendingCommitTargetBranch, currentCommitTargetBranch, }) {
|
|
499
|
+
// simulate 1 commit with a pending backport
|
|
500
|
+
jest
|
|
501
|
+
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
502
|
+
.mockResolvedValueOnce([
|
|
503
|
+
{
|
|
504
|
+
committedDate: '10',
|
|
505
|
+
expectedTargetPullRequests: [
|
|
506
|
+
{ branch: offendingCommitTargetBranch, state: 'OPEN' },
|
|
507
|
+
],
|
|
508
|
+
originalMessage: 'First commit (#1)',
|
|
509
|
+
sha: 'xyz',
|
|
510
|
+
sourceBranch: 'main',
|
|
511
|
+
},
|
|
512
|
+
]);
|
|
513
|
+
// simulate commit is definitely not backported
|
|
514
|
+
jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
|
|
515
|
+
return (0, cherrypickAndCreateTargetPullRequest_1.getCommitsWithoutBackports)({
|
|
516
|
+
options: {},
|
|
517
|
+
commit: {
|
|
518
|
+
committedDate: '100',
|
|
519
|
+
expectedTargetPullRequests: [],
|
|
520
|
+
originalMessage: 'Second commit (#2)',
|
|
521
|
+
sha: 'abc',
|
|
522
|
+
sourceBranch: 'main',
|
|
523
|
+
},
|
|
524
|
+
targetBranch: currentCommitTargetBranch,
|
|
525
|
+
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
it('should display backport as pending if target branches match', async () => {
|
|
529
|
+
const commitsWithoutBackports = await setup({
|
|
530
|
+
offendingCommitTargetBranch: '7.x',
|
|
531
|
+
currentCommitTargetBranch: '7.x',
|
|
532
|
+
});
|
|
533
|
+
expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)');
|
|
534
|
+
});
|
|
535
|
+
it("should not display backport as pending if target branches don't match", async () => {
|
|
536
|
+
const commitsWithoutBackports = await setup({
|
|
537
|
+
offendingCommitTargetBranch: '7.x',
|
|
538
|
+
currentCommitTargetBranch: '8.x',
|
|
539
|
+
});
|
|
540
|
+
expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1)');
|
|
288
541
|
});
|
|
289
542
|
});
|
|
290
543
|
});
|
|
291
|
-
function
|
|
544
|
+
function setupExecSpyForCherryPick() {
|
|
292
545
|
let conflictingFilesCheck = 0;
|
|
293
546
|
let unstagedFilesCheck = 0;
|
|
294
547
|
return jest
|
|
@@ -303,9 +556,13 @@ function setupExecSpy() {
|
|
|
303
556
|
return { stderr: '', stdout: '' };
|
|
304
557
|
}
|
|
305
558
|
// cherrypick
|
|
306
|
-
if (cmd === 'git cherry-pick mySha') {
|
|
559
|
+
if (cmd === 'git cherry-pick -x mySha') {
|
|
307
560
|
throw new ExecError_1.ExecError({ cmd });
|
|
308
561
|
}
|
|
562
|
+
// getIsCommitInBranch
|
|
563
|
+
if (cmd.startsWith('git merge-base --is-ancestor')) {
|
|
564
|
+
return { stderr: '', stdout: '' };
|
|
565
|
+
}
|
|
309
566
|
// getConflictingFiles
|
|
310
567
|
if (cmd === 'git --no-pager diff --check') {
|
|
311
568
|
conflictingFilesCheck++;
|
|
@@ -342,6 +599,6 @@ function setupExecSpy() {
|
|
|
342
599
|
if (cmd.includes('git branch -D ')) {
|
|
343
600
|
return { stdout: ``, stderr: '' };
|
|
344
601
|
}
|
|
345
|
-
throw new Error(`Missing mock for "${cmd}"`);
|
|
602
|
+
throw new Error(`Missing exec mock for "${cmd}"`);
|
|
346
603
|
});
|
|
347
604
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../options/options';
|
|
2
|
-
import { Commit } from '../
|
|
2
|
+
import { Commit } from '../services/sourceCommit/parseSourceCommit';
|
|
3
3
|
export declare function cherrypickAndCreateTargetPullRequest({ options, commits, targetBranch, }: {
|
|
4
4
|
options: ValidConfigOptions;
|
|
5
5
|
commits: Commit[];
|
|
@@ -7,5 +7,15 @@ export declare function cherrypickAndCreateTargetPullRequest({ options, commits,
|
|
|
7
7
|
}): Promise<{
|
|
8
8
|
url: string;
|
|
9
9
|
number: number;
|
|
10
|
+
didUpdate: boolean;
|
|
10
11
|
}>;
|
|
12
|
+
export declare function getCommitsWithoutBackports({ options, commit, targetBranch, conflictingFiles, }: {
|
|
13
|
+
options: ValidConfigOptions;
|
|
14
|
+
commit: Commit;
|
|
15
|
+
targetBranch: string;
|
|
16
|
+
conflictingFiles: string[];
|
|
17
|
+
}): Promise<{
|
|
18
|
+
formatted: string;
|
|
19
|
+
commit: Commit;
|
|
20
|
+
}[]>;
|
|
11
21
|
export declare function getBackportBranchName(targetBranch: string, commits: Commit[]): string;
|