backport 5.6.5 → 6.1.1
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 +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 -12
- package/dist/options/cliArgs.d.ts +36 -35
- package/dist/options/cliArgs.js +91 -52
- package/dist/options/cliArgs.test.js +41 -42
- package/dist/options/config/config.d.ts +34 -57
- package/dist/options/config/config.js +5 -39
- package/dist/options/config/config.test.js +11 -25
- 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 -49
- 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 -49
- package/dist/options/config/projectConfig.js +2 -2
- package/dist/options/config/projectConfig.test.js +53 -16
- package/dist/options/config/readConfigFile.d.ts +43 -39
- package/dist/options/config/readConfigFile.js +30 -4
- package/dist/options/options.d.ts +57 -31
- package/dist/options/options.js +102 -10
- package/dist/options/options.test.js +263 -61
- 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 +140 -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 -29
- 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 +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 +8 -10
- package/dist/services/github/v4/apiRequestV4.test.js +7 -7
- package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +1 -8
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +6 -32
- package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +1 -8
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +31 -40
- 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 +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.d.ts +11 -0
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
- 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 +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 +19 -9
- package/dist/services/github/v4/getOptionsFromGithub/index.js +59 -19
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +119 -32
- 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.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 +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 +64 -49
- 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 +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 +2414 -2993
|
@@ -29,138 +29,123 @@ describe('getTargetBranches', () => {
|
|
|
29
29
|
.spyOn(prompts, 'promptForTargetBranches')
|
|
30
30
|
.mockResolvedValueOnce(['branchA']);
|
|
31
31
|
});
|
|
32
|
-
describe('when `
|
|
33
|
-
let
|
|
32
|
+
describe('when `options.targetBranches` is empty', () => {
|
|
33
|
+
let branches;
|
|
34
34
|
beforeEach(async () => {
|
|
35
35
|
const options = {
|
|
36
36
|
targetBranches: [],
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
{ name: 'master' },
|
|
40
|
-
{ name: '7.x' },
|
|
41
|
-
{ name: '7.7' },
|
|
42
|
-
{ name: '7.6' },
|
|
43
|
-
{ name: '7.5' },
|
|
44
|
-
],
|
|
45
|
-
branchLabelMapping: {},
|
|
46
|
-
sourceBranch: 'master',
|
|
37
|
+
targetBranchChoices: [{ name: 'branchA' }, { name: 'branchB' }],
|
|
38
|
+
multipleBranches: false,
|
|
47
39
|
};
|
|
48
40
|
const commits = [
|
|
49
41
|
{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
sha: '
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
existingTargetPullRequests: [],
|
|
42
|
+
committedDate: 'aaa',
|
|
43
|
+
originalMessage: 'hey',
|
|
44
|
+
sha: 'abcd',
|
|
45
|
+
sourceBranch: '7.x',
|
|
46
|
+
pullNumber: 1337,
|
|
47
|
+
expectedTargetPullRequests: [],
|
|
57
48
|
},
|
|
58
49
|
];
|
|
59
|
-
await getTargetBranches_1.getTargetBranches(options, commits);
|
|
60
|
-
targetBranchChoices = promptSpy.mock.calls[0][0].targetBranchChoices;
|
|
61
|
-
});
|
|
62
|
-
it('should list the correct branches', async () => {
|
|
63
|
-
expect(targetBranchChoices).toEqual([
|
|
64
|
-
{ checked: true, name: '7.x' },
|
|
65
|
-
{ checked: false, name: '7.7' },
|
|
66
|
-
{ checked: false, name: '7.6' },
|
|
67
|
-
{ checked: false, name: '7.5' },
|
|
68
|
-
]);
|
|
50
|
+
branches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
|
69
51
|
});
|
|
70
|
-
it('should
|
|
71
|
-
expect(
|
|
52
|
+
it('should return branches from prompt', () => {
|
|
53
|
+
expect(branches).toEqual(['branchA']);
|
|
72
54
|
});
|
|
73
|
-
it('should
|
|
74
|
-
expect(
|
|
75
|
-
name: '
|
|
76
|
-
|
|
55
|
+
it('should call prompt with correct args', () => {
|
|
56
|
+
expect(promptSpy).toHaveBeenLastCalledWith({
|
|
57
|
+
targetBranchChoices: [{ name: 'branchA' }, { name: 'branchB' }],
|
|
58
|
+
isMultipleChoice: false,
|
|
77
59
|
});
|
|
78
60
|
});
|
|
79
61
|
});
|
|
80
|
-
describe('when `
|
|
62
|
+
describe('when `options.targetBranches` is not empty', () => {
|
|
63
|
+
let branches;
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
branches = (0, getTargetBranches_1.getTargetBranches)({
|
|
66
|
+
targetBranches: ['branchA', 'branchB'],
|
|
67
|
+
targetBranchChoices: [],
|
|
68
|
+
multipleBranches: false,
|
|
69
|
+
}, []);
|
|
70
|
+
});
|
|
71
|
+
it('should return branches from `options.branches`', () => {
|
|
72
|
+
expect(branches).toEqual(['branchA', 'branchB']);
|
|
73
|
+
});
|
|
74
|
+
it('should not call prompt', () => {
|
|
75
|
+
expect(promptSpy).not.toHaveBeenCalled();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
describe('when ci=true', () => {
|
|
79
|
+
it('should throw when there are no missing backports', () => {
|
|
80
|
+
const commits = [];
|
|
81
|
+
expect(() => {
|
|
82
|
+
return (0, getTargetBranches_1.getTargetBranches)({
|
|
83
|
+
expectedTargetPullRequests: [],
|
|
84
|
+
ci: true,
|
|
85
|
+
}, commits);
|
|
86
|
+
}).toThrow('There are no branches to backport to. Aborting.');
|
|
87
|
+
});
|
|
88
|
+
it('should return missing backports', () => {
|
|
89
|
+
const commits = [
|
|
90
|
+
{
|
|
91
|
+
expectedTargetPullRequests: [
|
|
92
|
+
{ branch: '7.2', state: 'MERGED' },
|
|
93
|
+
{ branch: '7.1', state: 'OPEN' },
|
|
94
|
+
{ branch: '7.x', state: 'MISSING' },
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
const targetBranches = (0, getTargetBranches_1.getTargetBranches)({ ci: true }, commits);
|
|
99
|
+
expect(targetBranches).toEqual(['7.x']);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
describe('when `expectedTargetPullRequests` is missing a backport to 7.x', () => {
|
|
81
103
|
let targetBranchChoices;
|
|
82
104
|
beforeEach(async () => {
|
|
83
105
|
const options = {
|
|
84
106
|
targetBranches: [],
|
|
85
107
|
multipleBranches: true,
|
|
86
108
|
targetBranchChoices: [
|
|
109
|
+
{ name: 'master' },
|
|
87
110
|
{ name: '7.x' },
|
|
88
111
|
{ name: '7.7' },
|
|
89
112
|
{ name: '7.6' },
|
|
90
113
|
{ name: '7.5' },
|
|
91
114
|
],
|
|
115
|
+
branchLabelMapping: {},
|
|
92
116
|
sourceBranch: 'master',
|
|
93
117
|
};
|
|
94
118
|
const commits = [
|
|
95
119
|
{
|
|
120
|
+
committedDate: 'bbb',
|
|
96
121
|
sourceBranch: 'master',
|
|
97
|
-
targetBranchesFromLabels: ['8.0.0'],
|
|
98
122
|
sha: 'my-sha',
|
|
99
|
-
formattedMessage: '[backport] Bump to 5.1.3 (#62286)',
|
|
100
123
|
originalMessage: '[backport] Bump to 5.1.3 (#62286)',
|
|
101
124
|
pullNumber: 62286,
|
|
102
|
-
|
|
125
|
+
expectedTargetPullRequests: [{ branch: '7.x', state: 'MISSING' }],
|
|
103
126
|
},
|
|
104
127
|
];
|
|
105
|
-
await getTargetBranches_1.getTargetBranches(options, commits);
|
|
128
|
+
await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
|
106
129
|
targetBranchChoices = promptSpy.mock.calls[0][0].targetBranchChoices;
|
|
107
130
|
});
|
|
108
131
|
it('should list the correct branches', async () => {
|
|
109
132
|
expect(targetBranchChoices).toEqual([
|
|
110
|
-
{ name: '7.x' },
|
|
111
|
-
{ name: '7.7' },
|
|
112
|
-
{ name: '7.6' },
|
|
113
|
-
{ name: '7.5' },
|
|
133
|
+
{ checked: true, name: '7.x' },
|
|
134
|
+
{ checked: false, name: '7.7' },
|
|
135
|
+
{ checked: false, name: '7.6' },
|
|
136
|
+
{ checked: false, name: '7.5' },
|
|
114
137
|
]);
|
|
115
138
|
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
let branches;
|
|
119
|
-
beforeEach(async () => {
|
|
120
|
-
const options = {
|
|
121
|
-
targetBranches: [],
|
|
122
|
-
targetBranchChoices: [{ name: 'branchA' }, { name: 'branchB' }],
|
|
123
|
-
multipleBranches: false,
|
|
124
|
-
};
|
|
125
|
-
const commits = [
|
|
126
|
-
{
|
|
127
|
-
formattedMessage: 'hey',
|
|
128
|
-
originalMessage: 'hey',
|
|
129
|
-
targetBranchesFromLabels: [],
|
|
130
|
-
sha: 'abcd',
|
|
131
|
-
sourceBranch: '7.x',
|
|
132
|
-
pullNumber: 1337,
|
|
133
|
-
existingTargetPullRequests: [],
|
|
134
|
-
},
|
|
135
|
-
];
|
|
136
|
-
branches = await getTargetBranches_1.getTargetBranches(options, commits);
|
|
137
|
-
});
|
|
138
|
-
it('should return branches from prompt', () => {
|
|
139
|
-
expect(branches).toEqual(['branchA']);
|
|
139
|
+
it('should not list the sourceBranch (master)', async () => {
|
|
140
|
+
expect(targetBranchChoices).not.toContainEqual(expect.objectContaining({ name: 'master' }));
|
|
140
141
|
});
|
|
141
|
-
it('should
|
|
142
|
-
expect(
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
it('should select 7.x', async () => {
|
|
143
|
+
expect(targetBranchChoices).toContainEqual({
|
|
144
|
+
name: '7.x',
|
|
145
|
+
checked: true,
|
|
145
146
|
});
|
|
146
147
|
});
|
|
147
148
|
});
|
|
148
|
-
describe('when `options.targetBranches` is not empty', () => {
|
|
149
|
-
let branches;
|
|
150
|
-
beforeEach(() => {
|
|
151
|
-
branches = getTargetBranches_1.getTargetBranches({
|
|
152
|
-
targetBranches: ['branchA', 'branchB'],
|
|
153
|
-
targetBranchChoices: [],
|
|
154
|
-
multipleBranches: false,
|
|
155
|
-
}, []);
|
|
156
|
-
});
|
|
157
|
-
it('should return branches from `options.branches`', () => {
|
|
158
|
-
expect(branches).toEqual(['branchA', 'branchB']);
|
|
159
|
-
});
|
|
160
|
-
it('should not call prompt', () => {
|
|
161
|
-
expect(promptSpy).not.toHaveBeenCalled();
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
149
|
});
|
|
165
150
|
describe('getTargetBranchChoices', () => {
|
|
166
151
|
const options = {
|
|
@@ -176,16 +161,7 @@ describe('getTargetBranchChoices', () => {
|
|
|
176
161
|
const sourceBranch = 'master';
|
|
177
162
|
it('should not check any branches if no labels match', () => {
|
|
178
163
|
const targetBranchesFromLabels = [];
|
|
179
|
-
const branches = getTargetBranches_1.getTargetBranchChoices(options, targetBranchesFromLabels, sourceBranch);
|
|
180
|
-
expect(branches).toEqual([
|
|
181
|
-
{ checked: false, name: '7.x' },
|
|
182
|
-
{ checked: false, name: '7.8' },
|
|
183
|
-
{ checked: false, name: '7.7' },
|
|
184
|
-
]);
|
|
185
|
-
});
|
|
186
|
-
it('should not return default branches when running in "--ci" mode', () => {
|
|
187
|
-
const targetBranchesFromLabels = [];
|
|
188
|
-
const branches = getTargetBranches_1.getTargetBranchChoices({ ...options, ci: true }, targetBranchesFromLabels, sourceBranch);
|
|
164
|
+
const branches = (0, getTargetBranches_1.getTargetBranchChoices)(options, targetBranchesFromLabels, sourceBranch);
|
|
189
165
|
expect(branches).toEqual([
|
|
190
166
|
{ checked: false, name: '7.x' },
|
|
191
167
|
{ checked: false, name: '7.8' },
|
|
@@ -194,7 +170,7 @@ describe('getTargetBranchChoices', () => {
|
|
|
194
170
|
});
|
|
195
171
|
it('should pre-select branches based on labels', () => {
|
|
196
172
|
const targetBranchesFromLabels = ['7.7'];
|
|
197
|
-
const branches = getTargetBranches_1.getTargetBranchChoices(options, targetBranchesFromLabels, sourceBranch);
|
|
173
|
+
const branches = (0, getTargetBranches_1.getTargetBranchChoices)(options, targetBranchesFromLabels, sourceBranch);
|
|
198
174
|
expect(branches).toEqual([
|
|
199
175
|
{ checked: false, name: '7.x' },
|
|
200
176
|
{ checked: false, name: '7.8' },
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getTargetBranchesFromLabels = void 0;
|
|
7
|
+
const lodash_isempty_1 = __importDefault(require("lodash.isempty"));
|
|
8
|
+
const matcher_1 = __importDefault(require("matcher"));
|
|
9
|
+
function getTargetBranchesFromLabels({ options, commits, }) {
|
|
10
|
+
// don't infer target branches if multiple commits are selected
|
|
11
|
+
if (commits.length != 1) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
// use first (and only) commit
|
|
15
|
+
const commit = commits[0];
|
|
16
|
+
// commit must be related to a PR that contain labels
|
|
17
|
+
if (!commit.sourcePRLabels) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
const existingPRs = commit.existingTargetPullRequests.map((pr) => pr.branch);
|
|
21
|
+
return (options.targetBranchChoices
|
|
22
|
+
.filter((targetBranchChoice) => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
// if there's no sourcePRLabels, it should match by the branch name
|
|
25
|
+
if (targetBranchChoice.checked !== false &&
|
|
26
|
+
lodash_isempty_1.default(targetBranchChoice.sourcePRLabels)) {
|
|
27
|
+
return (_a = commit.sourcePRLabels) === null || _a === void 0 ? void 0 : _a.includes(targetBranchChoice.name);
|
|
28
|
+
}
|
|
29
|
+
// match by sourcePRLabels
|
|
30
|
+
return (_b = targetBranchChoice.sourcePRLabels) === null || _b === void 0 ? void 0 : _b.every((label) =>
|
|
31
|
+
//@ts-expect-error
|
|
32
|
+
matcher_1.default.isMatch(commit.sourcePRLabels, label));
|
|
33
|
+
})
|
|
34
|
+
// remove target branch if a pr already exists for the given branch
|
|
35
|
+
.filter((targetBranch) => !existingPRs.includes(targetBranch.name))
|
|
36
|
+
// remove target branch if source branch is identical
|
|
37
|
+
.filter((targetBranch) => commit.sourceBranch !== targetBranch.name)
|
|
38
|
+
.map((targetBranch) => targetBranch.name));
|
|
39
|
+
}
|
|
40
|
+
exports.getTargetBranchesFromLabels = getTargetBranchesFromLabels;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getTargetBranchesFromLabels_1 = require("./getTargetBranchesFromLabels");
|
|
4
|
+
describe('getTargetBranchesFromLabels', () => {
|
|
5
|
+
it(`should support Kibana's label format`, () => {
|
|
6
|
+
const targetBranchChoices = [
|
|
7
|
+
{ name: 'master', sourcePRLabels: ['v8.0.0'] },
|
|
8
|
+
{ name: '7.x', sourcePRLabels: ['v7.8.0'] },
|
|
9
|
+
{ name: '7.7', sourcePRLabels: ['v7.7.0'] },
|
|
10
|
+
{ name: '7.6', sourcePRLabels: ['v7.6.0'] },
|
|
11
|
+
{ name: '7.5', sourcePRLabels: ['v7.5.0'] },
|
|
12
|
+
{ name: '7.4', sourcePRLabels: ['v7.4.1'] },
|
|
13
|
+
{ name: '7.3', sourcePRLabels: ['v7.3.3'] },
|
|
14
|
+
{ name: '7.2', sourcePRLabels: ['v7.2.2'] },
|
|
15
|
+
{ name: '7.1', sourcePRLabels: ['v7.1.2'] },
|
|
16
|
+
{ name: '7.0', sourcePRLabels: ['v7.0.2'] },
|
|
17
|
+
{ name: '6.8', sourcePRLabels: ['v6.8.4'] },
|
|
18
|
+
{ name: '6.7', sourcePRLabels: ['v6.7.2'] },
|
|
19
|
+
{ name: '6.6', sourcePRLabels: ['v6.6.3'] },
|
|
20
|
+
{ name: '6.5', sourcePRLabels: ['v6.5.5'] },
|
|
21
|
+
{ name: '6.4', sourcePRLabels: ['v6.4.4'] },
|
|
22
|
+
{ name: '6.3', sourcePRLabels: ['v6.3.3'] },
|
|
23
|
+
{ name: '6.2', sourcePRLabels: ['v6.2.5'] },
|
|
24
|
+
{ name: '6.1', sourcePRLabels: ['v6.1.4'] },
|
|
25
|
+
{ name: '6.0', sourcePRLabels: ['v6.0.1'] },
|
|
26
|
+
{ name: '5.6', sourcePRLabels: ['v5.6.16'] },
|
|
27
|
+
];
|
|
28
|
+
const sourceBranch = 'master';
|
|
29
|
+
const existingTargetPullRequests = [];
|
|
30
|
+
const sourcePRLabels = [
|
|
31
|
+
'release_note:fix',
|
|
32
|
+
'v5.4.3',
|
|
33
|
+
'v5.5.3',
|
|
34
|
+
'v5.6.16',
|
|
35
|
+
'v6.0.1',
|
|
36
|
+
'v6.1.4',
|
|
37
|
+
'v6.2.5',
|
|
38
|
+
'v6.3.3',
|
|
39
|
+
'v6.4.4',
|
|
40
|
+
'v6.5.5',
|
|
41
|
+
'v6.6.3',
|
|
42
|
+
'v6.7.2',
|
|
43
|
+
'v6.8.4',
|
|
44
|
+
'v7.0.2',
|
|
45
|
+
'v7.1.2',
|
|
46
|
+
'v7.2.2',
|
|
47
|
+
'v7.3.3',
|
|
48
|
+
'v7.4.1',
|
|
49
|
+
'v7.5.0',
|
|
50
|
+
'v7.6.0',
|
|
51
|
+
'v7.7.0',
|
|
52
|
+
'v7.8.0',
|
|
53
|
+
'v8.0.0', // master
|
|
54
|
+
];
|
|
55
|
+
const targetBranches = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
56
|
+
commits: [
|
|
57
|
+
{ sourceBranch, existingTargetPullRequests, sourcePRLabels },
|
|
58
|
+
],
|
|
59
|
+
options: {
|
|
60
|
+
targetBranchChoices,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
expect(targetBranches).toEqual([
|
|
64
|
+
'7.x',
|
|
65
|
+
'7.7',
|
|
66
|
+
'7.6',
|
|
67
|
+
'7.5',
|
|
68
|
+
'7.4',
|
|
69
|
+
'7.3',
|
|
70
|
+
'7.2',
|
|
71
|
+
'7.1',
|
|
72
|
+
'7.0',
|
|
73
|
+
'6.8',
|
|
74
|
+
'6.7',
|
|
75
|
+
'6.6',
|
|
76
|
+
'6.5',
|
|
77
|
+
'6.4',
|
|
78
|
+
'6.3',
|
|
79
|
+
'6.2',
|
|
80
|
+
'6.1',
|
|
81
|
+
'6.0',
|
|
82
|
+
'5.6',
|
|
83
|
+
]);
|
|
84
|
+
});
|
|
85
|
+
it('returns target branch if all labels in sourcePRLabels matches', () => {
|
|
86
|
+
const sourceBranch = 'master';
|
|
87
|
+
const existingTargetPullRequests = [];
|
|
88
|
+
const sourcePRLabels = ['label-foo', 'label-bar'];
|
|
89
|
+
const targetBranchChoices = [
|
|
90
|
+
{ name: 'branch-1', sourcePRLabels: ['label-foo', 'label-bar'] },
|
|
91
|
+
{ name: 'branch-2', sourcePRLabels: [] },
|
|
92
|
+
{ name: 'branch-3', sourcePRLabels: [] },
|
|
93
|
+
];
|
|
94
|
+
const targetBranches = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
95
|
+
commits: [
|
|
96
|
+
{ sourceBranch, existingTargetPullRequests, sourcePRLabels },
|
|
97
|
+
],
|
|
98
|
+
options: {
|
|
99
|
+
targetBranchChoices,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
expect(targetBranches).toEqual(['branch-1']);
|
|
103
|
+
});
|
|
104
|
+
it('does not return target branch if only some items in sourcePRLabels matches', () => {
|
|
105
|
+
const sourceBranch = 'master';
|
|
106
|
+
const existingTargetPullRequests = [];
|
|
107
|
+
const sourcePRLabels = ['label-foo'];
|
|
108
|
+
const targetBranchChoices = [
|
|
109
|
+
{ name: 'branch-1', sourcePRLabels: ['label-foo', 'label-bar'] },
|
|
110
|
+
{ name: 'branch-2', sourcePRLabels: [] },
|
|
111
|
+
{ name: 'branch-3', sourcePRLabels: [] },
|
|
112
|
+
];
|
|
113
|
+
const targetBranches = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
114
|
+
commits: [
|
|
115
|
+
{ sourceBranch, existingTargetPullRequests, sourcePRLabels },
|
|
116
|
+
],
|
|
117
|
+
options: {
|
|
118
|
+
targetBranchChoices,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
expect(targetBranches).toEqual([]);
|
|
122
|
+
});
|
|
123
|
+
it('does not return branch if a related PR is already open', () => {
|
|
124
|
+
const sourceBranch = 'master';
|
|
125
|
+
const existingTargetPullRequests = [
|
|
126
|
+
{ branch: 'branch-1', state: 'OPEN' },
|
|
127
|
+
];
|
|
128
|
+
const sourcePRLabels = ['label-foo', 'label-bar', 'label-baz'];
|
|
129
|
+
const targetBranchChoices = [
|
|
130
|
+
{ name: 'branch-1', sourcePRLabels: ['label-foo', 'label-bar'] },
|
|
131
|
+
{ name: 'branch-2', sourcePRLabels: ['label-baz'] },
|
|
132
|
+
{ name: 'branch-3', sourcePRLabels: [] },
|
|
133
|
+
];
|
|
134
|
+
const targetBranches = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
135
|
+
commits: [
|
|
136
|
+
{ sourceBranch, existingTargetPullRequests, sourcePRLabels },
|
|
137
|
+
],
|
|
138
|
+
options: {
|
|
139
|
+
targetBranchChoices,
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
expect(targetBranches).toEqual(['branch-2']);
|
|
143
|
+
});
|
|
144
|
+
it('does not return branch if a related PR is already merged', () => {
|
|
145
|
+
const sourceBranch = 'master';
|
|
146
|
+
const existingTargetPullRequests = [
|
|
147
|
+
{ branch: 'branch-2', state: 'MERGED' },
|
|
148
|
+
];
|
|
149
|
+
const sourcePRLabels = ['label-foo', 'label-bar', 'label-baz'];
|
|
150
|
+
const targetBranchChoices = [
|
|
151
|
+
{ name: 'branch-1', sourcePRLabels: ['label-foo', 'label-bar'] },
|
|
152
|
+
{ name: 'branch-2', sourcePRLabels: ['label-baz'] },
|
|
153
|
+
{ name: 'branch-3', sourcePRLabels: [] },
|
|
154
|
+
];
|
|
155
|
+
const targetBranches = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
156
|
+
commits: [
|
|
157
|
+
{ sourceBranch, existingTargetPullRequests, sourcePRLabels },
|
|
158
|
+
],
|
|
159
|
+
options: {
|
|
160
|
+
targetBranchChoices,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
expect(targetBranches).toEqual(['branch-1']);
|
|
164
|
+
});
|
|
165
|
+
it('does not return branch if sourceBranch is identical', () => {
|
|
166
|
+
const sourceBranch = 'branch-2';
|
|
167
|
+
const existingTargetPullRequests = [];
|
|
168
|
+
const sourcePRLabels = ['label-foo', 'label-bar', 'label-baz'];
|
|
169
|
+
const targetBranchChoices = [
|
|
170
|
+
{ name: 'branch-1', sourcePRLabels: ['label-foo', 'label-bar'] },
|
|
171
|
+
{ name: 'branch-2', sourcePRLabels: ['label-baz'] },
|
|
172
|
+
{ name: 'branch-3', sourcePRLabels: [] },
|
|
173
|
+
];
|
|
174
|
+
const targetBranches = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
175
|
+
commits: [
|
|
176
|
+
{ sourceBranch, existingTargetPullRequests, sourcePRLabels },
|
|
177
|
+
],
|
|
178
|
+
options: {
|
|
179
|
+
targetBranchChoices,
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
expect(targetBranches).toEqual(['branch-1']);
|
|
183
|
+
});
|
|
184
|
+
it('ignores non-matching labels', () => {
|
|
185
|
+
const sourceBranch = 'master';
|
|
186
|
+
const existingTargetPullRequests = [];
|
|
187
|
+
const sourcePRLabels = [
|
|
188
|
+
'label-foo',
|
|
189
|
+
'label-bar',
|
|
190
|
+
'label-baz',
|
|
191
|
+
'label-unknown',
|
|
192
|
+
];
|
|
193
|
+
const targetBranchChoices = [
|
|
194
|
+
{ name: 'branch-1', sourcePRLabels: ['label-foo', 'label-bar'] },
|
|
195
|
+
{ name: 'branch-2', sourcePRLabels: ['label-baz'] },
|
|
196
|
+
{ name: 'branch-3', sourcePRLabels: [] },
|
|
197
|
+
];
|
|
198
|
+
const targetBranches = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
199
|
+
commits: [
|
|
200
|
+
{ sourceBranch, existingTargetPullRequests, sourcePRLabels },
|
|
201
|
+
],
|
|
202
|
+
options: {
|
|
203
|
+
targetBranchChoices,
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
expect(targetBranches).toEqual(['branch-1', 'branch-2']);
|
|
207
|
+
});
|
|
208
|
+
it('supports wildcard matching', () => {
|
|
209
|
+
const sourceBranch = 'master';
|
|
210
|
+
const existingTargetPullRequests = [];
|
|
211
|
+
const sourcePRLabels = ['label-c-foo'];
|
|
212
|
+
const targetBranchChoices = [
|
|
213
|
+
{ name: 'branch-1', sourcePRLabels: ['label-a'] },
|
|
214
|
+
{ name: 'branch-2', sourcePRLabels: ['label-b'] },
|
|
215
|
+
{ name: 'branch-3', sourcePRLabels: ['label-c-*'] },
|
|
216
|
+
{ name: 'branch-4', sourcePRLabels: ['label-d'] },
|
|
217
|
+
];
|
|
218
|
+
const targetBranches = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
219
|
+
commits: [
|
|
220
|
+
{ sourceBranch, existingTargetPullRequests, sourcePRLabels },
|
|
221
|
+
],
|
|
222
|
+
options: {
|
|
223
|
+
targetBranchChoices,
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
expect(targetBranches).toEqual(['branch-3']);
|
|
227
|
+
});
|
|
228
|
+
it('supports literal wildcards', () => {
|
|
229
|
+
const sourceBranch = 'master';
|
|
230
|
+
const existingTargetPullRequests = [];
|
|
231
|
+
const sourcePRLabels = ['label-wildcard-*'];
|
|
232
|
+
const targetBranchChoices = [
|
|
233
|
+
{ name: 'branch-1', sourcePRLabels: ['label-a'] },
|
|
234
|
+
{ name: 'branch-2', sourcePRLabels: ['label-b'] },
|
|
235
|
+
{ name: 'branch-3', sourcePRLabels: ['label-wildcard-*'] },
|
|
236
|
+
{ name: 'branch-4', sourcePRLabels: ['label-d'] },
|
|
237
|
+
];
|
|
238
|
+
const targetBranches = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
239
|
+
commits: [
|
|
240
|
+
{ sourceBranch, existingTargetPullRequests, sourcePRLabels },
|
|
241
|
+
],
|
|
242
|
+
options: {
|
|
243
|
+
targetBranchChoices,
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
expect(targetBranches).toEqual(['branch-3']);
|
|
247
|
+
});
|
|
248
|
+
it('returns empty if no commits are selected', () => {
|
|
249
|
+
const targetBranchChoices = [
|
|
250
|
+
{ name: 'branch-1', sourcePRLabels: ['label-a'] },
|
|
251
|
+
{ name: 'branch-2', sourcePRLabels: ['label-b'] },
|
|
252
|
+
];
|
|
253
|
+
const targetBranches = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
254
|
+
commits: [],
|
|
255
|
+
options: {
|
|
256
|
+
targetBranchChoices,
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
expect(targetBranches).toEqual([]);
|
|
260
|
+
});
|
|
261
|
+
it('returns empty if multiple commits are selected', () => {
|
|
262
|
+
const sourceBranch = 'master';
|
|
263
|
+
const existingTargetPullRequests = [];
|
|
264
|
+
const targetBranchChoices = [
|
|
265
|
+
{ name: 'branch-1', sourcePRLabels: ['label-foo'] },
|
|
266
|
+
{ name: 'branch-2', sourcePRLabels: ['label-baz'] },
|
|
267
|
+
{ name: 'branch-3', sourcePRLabels: [] },
|
|
268
|
+
];
|
|
269
|
+
const targetBranches = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
|
|
270
|
+
commits: [
|
|
271
|
+
{
|
|
272
|
+
sourceBranch,
|
|
273
|
+
existingTargetPullRequests,
|
|
274
|
+
sourcePRLabels: ['label-foo'],
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
sourceBranch,
|
|
278
|
+
existingTargetPullRequests,
|
|
279
|
+
sourcePRLabels: ['label-bar'],
|
|
280
|
+
},
|
|
281
|
+
],
|
|
282
|
+
options: {
|
|
283
|
+
targetBranchChoices,
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
expect(targetBranches).toEqual([]);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
@@ -9,33 +9,34 @@ const ora = require("ora");
|
|
|
9
9
|
const env_1 = require("../services/env");
|
|
10
10
|
const git_1 = require("../services/git");
|
|
11
11
|
async function maybeSetupRepo(options) {
|
|
12
|
-
const isAlreadyCloned = await git_1.repoExists(options);
|
|
12
|
+
const isAlreadyCloned = await (0, git_1.repoExists)(options);
|
|
13
13
|
// clone repo if folder does not already exists
|
|
14
14
|
if (!isAlreadyCloned) {
|
|
15
15
|
const spinner = ora().start();
|
|
16
16
|
try {
|
|
17
17
|
const spinnerCloneText = 'Cloning repository (one-time operation)';
|
|
18
18
|
spinner.text = `0% ${spinnerCloneText}`;
|
|
19
|
-
await make_dir_1.default(env_1.getRepoOwnerPath(options));
|
|
20
|
-
await git_1.cloneRepo(options, (progress) => {
|
|
19
|
+
await (0, make_dir_1.default)((0, env_1.getRepoOwnerPath)(options));
|
|
20
|
+
await (0, git_1.cloneRepo)(options, (progress) => {
|
|
21
21
|
spinner.text = `${progress}% ${spinnerCloneText}`;
|
|
22
22
|
});
|
|
23
23
|
spinner.succeed(`100% ${spinnerCloneText}`);
|
|
24
24
|
}
|
|
25
25
|
catch (e) {
|
|
26
26
|
spinner.fail();
|
|
27
|
-
await git_1.deleteRepo(options);
|
|
27
|
+
await (0, git_1.deleteRepo)(options);
|
|
28
28
|
throw e;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
// delete default "origin" remote to avoid confusion
|
|
32
|
-
await git_1.deleteRemote(options, 'origin');
|
|
32
|
+
await (0, git_1.deleteRemote)(options, 'origin');
|
|
33
33
|
// ensure remote are setup with latest accessToken
|
|
34
|
-
await git_1.deleteRemote(options, options.
|
|
35
|
-
await git_1.addRemote(options, options.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
await git_1.
|
|
34
|
+
await (0, git_1.deleteRemote)(options, options.authenticatedUsername);
|
|
35
|
+
await (0, git_1.addRemote)(options, options.authenticatedUsername);
|
|
36
|
+
// update remote for origin (if the above is a fork)
|
|
37
|
+
if (options.authenticatedUsername !== options.repoOwner) {
|
|
38
|
+
await (0, git_1.deleteRemote)(options, options.repoOwner);
|
|
39
|
+
await (0, git_1.addRemote)(options, options.repoOwner);
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
exports.maybeSetupRepo = maybeSetupRepo;
|