backport 8.0.0 → 8.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 +4 -4
- package/dist/backportRun.d.ts +5 -4
- package/dist/backportRun.js +41 -42
- package/dist/entrypoint.cli.js +3 -7
- package/dist/entrypoint.module.d.ts +7 -5
- package/dist/entrypoint.module.js +11 -9
- package/dist/entrypoint.module.private.test.js +4 -4
- package/dist/errors/BackportError.d.ts +19 -0
- package/dist/errors/BackportError.js +29 -0
- package/dist/lib/BackportError.d.ts +19 -0
- package/dist/lib/BackportError.js +29 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +13 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +238 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +321 -0
- package/dist/lib/child-process-promisified.d.ts +25 -0
- package/dist/lib/child-process-promisified.js +58 -0
- package/dist/lib/env.d.ts +7 -0
- package/dist/lib/env.js +33 -0
- package/dist/lib/env.test.d.ts +1 -0
- package/dist/lib/env.test.js +26 -0
- package/dist/lib/getCommits.d.ts +2 -0
- package/dist/lib/getCommits.js +75 -0
- package/dist/lib/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/lib/getCommitsWithoutBackports.js +68 -0
- package/dist/lib/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/lib/getCommitsWithoutBackports.test.js +335 -0
- package/dist/lib/getGitConfigAuthor.d.ts +6 -0
- package/dist/lib/getGitConfigAuthor.js +15 -0
- package/dist/lib/getTargetBranches.d.ts +5 -0
- package/dist/lib/getTargetBranches.js +67 -0
- package/dist/lib/getTargetBranches.test.d.ts +1 -0
- package/dist/lib/getTargetBranches.test.js +206 -0
- package/dist/lib/git.d.ts +77 -0
- package/dist/lib/git.js +439 -0
- package/dist/lib/git.private.test.d.ts +1 -0
- package/dist/lib/git.private.test.js +618 -0
- package/dist/lib/git.test.d.ts +1 -0
- package/dist/lib/git.test.js +580 -0
- package/dist/lib/github/commitFormatters.d.ts +3 -0
- package/dist/lib/github/commitFormatters.js +17 -0
- package/dist/lib/github/commitFormatters.test.d.ts +1 -0
- package/dist/lib/github/commitFormatters.test.js +11 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.js +32 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
- package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +27 -0
- package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addLabelsToPullRequest.js +30 -0
- package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +2 -0
- package/dist/lib/github/v3/addReviewersToPullRequest.js +32 -0
- package/dist/lib/github/v3/createPullRequest.d.ts +29 -0
- package/dist/lib/github/v3/createPullRequest.js +91 -0
- package/dist/lib/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/lib/github/v3/createPullRequest.test.js +377 -0
- package/dist/lib/github/v3/createStatusComment.d.ts +11 -0
- package/dist/lib/github/v3/createStatusComment.js +136 -0
- package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/lib/github/v3/createStatusComment.test.js +461 -0
- package/dist/lib/github/v3/getGithubV3ErrorMessage.d.ts +14 -0
- package/dist/lib/github/v3/getGithubV3ErrorMessage.js +16 -0
- package/dist/lib/github/v4/FetchPullRequestId.d.ts +2 -0
- package/dist/lib/github/v4/FetchPullRequestId.js +36 -0
- package/dist/lib/github/v4/apiRequestV4.d.ts +31 -0
- package/dist/lib/github/v4/apiRequestV4.js +71 -0
- package/dist/lib/github/v4/apiRequestV4.test.d.ts +1 -0
- package/dist/lib/github/v4/apiRequestV4.test.js +109 -0
- package/dist/lib/github/v4/disablePullRequestAutoMerge.d.ts +2 -0
- package/dist/lib/github/v4/disablePullRequestAutoMerge.js +32 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.d.ts +2 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.js +50 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
- package/dist/lib/github/v4/fetchAuthorId.d.ts +10 -0
- package/dist/lib/github/v4/fetchAuthorId.js +28 -0
- package/dist/lib/github/v4/fetchAuthorId.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchAuthorId.private.test.js +25 -0
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +11 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +58 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +136 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.d.ts +11 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +48 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +118 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +29 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +110 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +196 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +107 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +12 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +69 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.d.ts +9 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.js +64 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchExistingPullRequest.private.test.js +44 -0
- package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.d.ts +2 -0
- package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.js +39 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.js +49 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
- package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.js +49 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +72 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +78 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +116 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +16 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.js +29 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.js +61 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
- package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +72 -0
- package/dist/lib/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
- package/dist/lib/github/v4/mocks/commitsByAuthorMock.js +176 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.d.ts +7 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.js +45 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
- package/dist/lib/github/v4/throwOnInvalidAccessToken.test.js +87 -0
- package/dist/lib/logger.d.ts +9 -0
- package/dist/lib/logger.js +74 -0
- package/dist/lib/ora.d.ts +2 -0
- package/dist/lib/ora.js +21 -0
- package/dist/lib/prompt.test.d.ts +1 -0
- package/dist/lib/prompt.test.js +139 -0
- package/dist/lib/prompts.d.ts +17 -0
- package/dist/lib/prompts.js +132 -0
- package/dist/lib/remoteConfig.d.ts +20 -0
- package/dist/lib/remoteConfig.js +52 -0
- package/dist/lib/sequentially.d.ts +1 -0
- package/dist/lib/sequentially.js +10 -0
- package/dist/lib/setupRepo.d.ts +2 -0
- package/dist/lib/setupRepo.js +56 -0
- package/dist/lib/setupRepo.test.d.ts +1 -0
- package/dist/lib/setupRepo.test.js +278 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
- package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
- package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
- package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
- package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
- package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
- package/dist/options/ConfigOptions.d.ts +4 -2
- package/dist/options/cliArgs.d.ts +15 -12
- package/dist/options/cliArgs.js +34 -19
- package/dist/options/cliArgs.test.js +125 -1
- package/dist/options/config/config.d.ts +5 -4
- package/dist/options/config/config.js +3 -5
- package/dist/options/config/config.test.js +0 -1
- package/dist/options/config/globalConfig.d.ts +3 -1
- package/dist/options/config/globalConfig.js +5 -5
- package/dist/options/config/readConfigFile.d.ts +9 -7
- package/dist/options/config/readConfigFile.js +2 -2
- package/dist/options/options.d.ts +43 -7
- package/dist/options/options.js +20 -24
- package/dist/options/options.test.js +112 -54
- package/dist/runSequentially.d.ts +10 -7
- package/dist/runSequentially.js +5 -5
- package/dist/scripts/postinstall.js +3 -3
- package/dist/scripts/postinstall.test.js +1 -1
- package/dist/services/BackportError.d.ts +19 -0
- package/dist/services/BackportError.js +29 -0
- package/dist/services/HandledBackportError.d.ts +19 -0
- package/dist/services/HandledBackportError.js +29 -0
- package/dist/services/HandledError.d.ts +1 -1
- package/dist/services/HandledError.js +5 -5
- package/dist/services/git.js +7 -7
- package/dist/services/github/v3/createPullRequest.js +2 -2
- package/dist/services/github/v3/createStatusComment.js +2 -2
- package/dist/services/github/v3/createStatusComment.test.js +5 -4
- package/dist/services/github/v4/apiRequestV4.js +2 -2
- package/dist/services/github/v4/apiRequestV4.test.js +2 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +3 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +3 -3
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +2 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
- package/dist/state.d.ts +0 -0
- package/dist/state.js +1 -0
- package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +26 -24
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +189 -140
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +12 -14
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -2
- package/dist/test/e2e/cli/runBackportViaCli.js +42 -29
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +2 -2
- package/dist/test/handleUnbackportedPullRequests.private.test.js +3 -2
- package/dist/test/setupFiles/automatic-mocks.js +1 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
- package/dist/ui/getCommits.js +2 -2
- package/dist/ui/getTargetBranches.js +3 -3
- package/dist/ui/setupRepo.js +2 -2
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +12 -12
- package/yarn.lock +112 -65
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
30
|
+
const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
|
|
31
|
+
const git = __importStar(require("./git"));
|
|
32
|
+
const fetchCommitsByAuthorModule = __importStar(require("./github/v4/fetchCommits/fetchCommitsByAuthor"));
|
|
33
|
+
describe('getCommitsWithoutBackports', () => {
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
jest.restoreAllMocks();
|
|
36
|
+
});
|
|
37
|
+
describe('expectedTargetPullRequests', () => {
|
|
38
|
+
function setupExpectedPullRequests({ expectedTargetPullRequests, }) {
|
|
39
|
+
// simulate 1 unbackported commit
|
|
40
|
+
jest
|
|
41
|
+
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
42
|
+
.mockResolvedValueOnce([
|
|
43
|
+
{
|
|
44
|
+
author: {
|
|
45
|
+
email: 'soren.louv@elastic.co',
|
|
46
|
+
name: 'Søren Louv-Jansen',
|
|
47
|
+
},
|
|
48
|
+
sourceCommit: {
|
|
49
|
+
committedDate: '10',
|
|
50
|
+
message: 'First commit (#1)',
|
|
51
|
+
sha: 'xyz',
|
|
52
|
+
},
|
|
53
|
+
sourcePullRequest: {
|
|
54
|
+
url: 'https://www.github.com/foo/bar/pull/123',
|
|
55
|
+
number: 123,
|
|
56
|
+
mergeCommit: {
|
|
57
|
+
message: 'First commit (#1)',
|
|
58
|
+
sha: 'xyz',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
expectedTargetPullRequests,
|
|
62
|
+
sourceBranch: 'main',
|
|
63
|
+
},
|
|
64
|
+
]);
|
|
65
|
+
// simulate commit is definitely not backported
|
|
66
|
+
jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
|
|
67
|
+
return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
|
|
68
|
+
options: {},
|
|
69
|
+
commit: {
|
|
70
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
71
|
+
sourceCommit: {
|
|
72
|
+
committedDate: '100',
|
|
73
|
+
message: 'Second commit (#2)',
|
|
74
|
+
sha: 'abc',
|
|
75
|
+
},
|
|
76
|
+
expectedTargetPullRequests: [],
|
|
77
|
+
sourceBranch: 'main',
|
|
78
|
+
},
|
|
79
|
+
targetBranch: '7.x',
|
|
80
|
+
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
it('should not unbackported commits if no backports were expected', async () => {
|
|
84
|
+
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
85
|
+
expectedTargetPullRequests: [],
|
|
86
|
+
});
|
|
87
|
+
expect(commitsWithoutBackports.length).toEqual(0);
|
|
88
|
+
});
|
|
89
|
+
it('should display as missing if a backport is CLOSED', async () => {
|
|
90
|
+
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
91
|
+
expectedTargetPullRequests: [
|
|
92
|
+
{
|
|
93
|
+
state: 'CLOSED',
|
|
94
|
+
branch: '7.x',
|
|
95
|
+
number: 456,
|
|
96
|
+
url: 'https://www.github.com/foo/bar/pull/456',
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
});
|
|
100
|
+
expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport missing)\n https://www.github.com/foo/bar/pull/123');
|
|
101
|
+
});
|
|
102
|
+
it('should display as missing if a backport is NOT_CREATED', async () => {
|
|
103
|
+
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
104
|
+
expectedTargetPullRequests: [{ state: 'NOT_CREATED', branch: '7.x' }],
|
|
105
|
+
});
|
|
106
|
+
expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport missing)\n https://www.github.com/foo/bar/pull/123');
|
|
107
|
+
});
|
|
108
|
+
it('should display as pending if a backport is OPEN', async () => {
|
|
109
|
+
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
110
|
+
expectedTargetPullRequests: [
|
|
111
|
+
{
|
|
112
|
+
state: 'OPEN',
|
|
113
|
+
branch: '7.x',
|
|
114
|
+
url: 'https://www.github.com/foo/bar/pull/456',
|
|
115
|
+
number: 456,
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
});
|
|
119
|
+
expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
|
|
120
|
+
});
|
|
121
|
+
it('should not display commit as unbackported if a backport was MERGED', async () => {
|
|
122
|
+
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
123
|
+
expectedTargetPullRequests: [
|
|
124
|
+
{
|
|
125
|
+
state: 'MERGED',
|
|
126
|
+
branch: '7.x',
|
|
127
|
+
number: 456,
|
|
128
|
+
url: 'https://www.github.com/foo/bar/pull/456',
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
});
|
|
132
|
+
expect(commitsWithoutBackports).toEqual([]);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
describe('commitDate', () => {
|
|
136
|
+
function setupCommitDateDiff({ offendingCommitDate, currentCommitDate, }) {
|
|
137
|
+
// simulate 1 commit with a pending backport
|
|
138
|
+
jest
|
|
139
|
+
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
140
|
+
.mockResolvedValueOnce([
|
|
141
|
+
{
|
|
142
|
+
author: {
|
|
143
|
+
email: 'soren.louv@elastic.co',
|
|
144
|
+
name: 'Søren Louv-Jansen',
|
|
145
|
+
},
|
|
146
|
+
sourceCommit: {
|
|
147
|
+
committedDate: offendingCommitDate,
|
|
148
|
+
message: 'First commit (#1)',
|
|
149
|
+
sha: 'xyz',
|
|
150
|
+
},
|
|
151
|
+
sourcePullRequest: {
|
|
152
|
+
number: 123,
|
|
153
|
+
url: 'https://www.github.com/foo/bar/pull/123',
|
|
154
|
+
mergeCommit: {
|
|
155
|
+
message: 'First commit (#1)',
|
|
156
|
+
sha: 'xyz',
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
sourceBranch: 'main',
|
|
160
|
+
expectedTargetPullRequests: [
|
|
161
|
+
{
|
|
162
|
+
state: 'OPEN',
|
|
163
|
+
branch: '7.x',
|
|
164
|
+
number: 456,
|
|
165
|
+
url: 'https://www.github.com/foo/bar/pull/456',
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
]);
|
|
170
|
+
// simulate commit is definitely not backported
|
|
171
|
+
jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
|
|
172
|
+
return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
|
|
173
|
+
options: {},
|
|
174
|
+
commit: {
|
|
175
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
176
|
+
sourceCommit: {
|
|
177
|
+
committedDate: currentCommitDate,
|
|
178
|
+
message: 'Second commit (#2)',
|
|
179
|
+
sha: 'abc',
|
|
180
|
+
},
|
|
181
|
+
sourcePullRequest: {
|
|
182
|
+
number: 123,
|
|
183
|
+
url: 'https://www.github.com/foo/bar/pull/123',
|
|
184
|
+
mergeCommit: {
|
|
185
|
+
message: 'Second commit (#2)',
|
|
186
|
+
sha: 'abc',
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
sourceBranch: 'main',
|
|
190
|
+
expectedTargetPullRequests: [],
|
|
191
|
+
},
|
|
192
|
+
targetBranch: '7.x',
|
|
193
|
+
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
it('should not display commit as unbackport if is newer than the commit currently being backported', async () => {
|
|
197
|
+
const commitsWithoutBackports = await setupCommitDateDiff({
|
|
198
|
+
offendingCommitDate: '100',
|
|
199
|
+
currentCommitDate: '10',
|
|
200
|
+
});
|
|
201
|
+
expect(commitsWithoutBackports).toEqual([]);
|
|
202
|
+
});
|
|
203
|
+
it('should display commit as unbackport if is older than the commit currently being backported', async () => {
|
|
204
|
+
const commitsWithoutBackports = await setupCommitDateDiff({
|
|
205
|
+
offendingCommitDate: '10',
|
|
206
|
+
currentCommitDate: '100',
|
|
207
|
+
});
|
|
208
|
+
expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
describe('targetBranch', () => {
|
|
212
|
+
function setupTargetBranchDiff({ offendingCommitTargetBranch, currentCommitTargetBranch, }) {
|
|
213
|
+
// return mock commits that also touched the conflicting files
|
|
214
|
+
jest
|
|
215
|
+
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
216
|
+
.mockResolvedValueOnce([
|
|
217
|
+
{
|
|
218
|
+
author: {
|
|
219
|
+
email: 'soren.louv@elastic.co',
|
|
220
|
+
name: 'Søren Louv-Jansen',
|
|
221
|
+
},
|
|
222
|
+
sourceCommit: {
|
|
223
|
+
committedDate: '10',
|
|
224
|
+
message: 'First commit (#1)',
|
|
225
|
+
sha: 'xyz',
|
|
226
|
+
},
|
|
227
|
+
sourcePullRequest: {
|
|
228
|
+
number: 123,
|
|
229
|
+
url: 'https://www.github.com/foo/bar/pull/123',
|
|
230
|
+
mergeCommit: {
|
|
231
|
+
message: 'First commit (#1)',
|
|
232
|
+
sha: 'xyz',
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
sourceBranch: 'main',
|
|
236
|
+
expectedTargetPullRequests: [
|
|
237
|
+
{
|
|
238
|
+
branch: offendingCommitTargetBranch,
|
|
239
|
+
state: 'OPEN',
|
|
240
|
+
url: 'https://www.github.com/foo/bar/pull/456',
|
|
241
|
+
number: 456,
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
]);
|
|
246
|
+
// simulate commit is definitely not backported
|
|
247
|
+
jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
|
|
248
|
+
return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
|
|
249
|
+
options: {},
|
|
250
|
+
// commit that is being backported
|
|
251
|
+
commit: {
|
|
252
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
253
|
+
sourceCommit: {
|
|
254
|
+
committedDate: '100',
|
|
255
|
+
message: 'Second commit (#2)',
|
|
256
|
+
sha: 'abc',
|
|
257
|
+
},
|
|
258
|
+
sourcePullRequest: {
|
|
259
|
+
url: 'https://www.github.com/foo/bar/pull/123',
|
|
260
|
+
number: 123,
|
|
261
|
+
mergeCommit: {
|
|
262
|
+
message: 'Second commit (#2)',
|
|
263
|
+
sha: 'abc',
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
expectedTargetPullRequests: [],
|
|
267
|
+
sourceBranch: 'main',
|
|
268
|
+
},
|
|
269
|
+
targetBranch: currentCommitTargetBranch,
|
|
270
|
+
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
it('should display backport as pending if target branches match', async () => {
|
|
274
|
+
const commitsWithoutBackports = await setupTargetBranchDiff({
|
|
275
|
+
offendingCommitTargetBranch: '7.x',
|
|
276
|
+
currentCommitTargetBranch: '7.x',
|
|
277
|
+
});
|
|
278
|
+
expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
|
|
279
|
+
});
|
|
280
|
+
it("should not display commit if target branches don't match", async () => {
|
|
281
|
+
const commitsWithoutBackports = await setupTargetBranchDiff({
|
|
282
|
+
offendingCommitTargetBranch: '7.x',
|
|
283
|
+
currentCommitTargetBranch: '8.x',
|
|
284
|
+
});
|
|
285
|
+
expect(commitsWithoutBackports.length).toBe(0);
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
describe("when conflicting commit doesn't have an associated pull request", () => {
|
|
289
|
+
it('should be ignored', async () => {
|
|
290
|
+
jest
|
|
291
|
+
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
292
|
+
.mockResolvedValueOnce([
|
|
293
|
+
{
|
|
294
|
+
author: {
|
|
295
|
+
email: 'soren.louv@elastic.co',
|
|
296
|
+
name: 'Søren Louv-Jansen',
|
|
297
|
+
},
|
|
298
|
+
sourceCommit: {
|
|
299
|
+
committedDate: '10',
|
|
300
|
+
sha: 'xyz',
|
|
301
|
+
message: 'First commit (#1)',
|
|
302
|
+
},
|
|
303
|
+
expectedTargetPullRequests: [],
|
|
304
|
+
sourceBranch: 'main',
|
|
305
|
+
},
|
|
306
|
+
]);
|
|
307
|
+
// simulate commit is definitely not backported
|
|
308
|
+
jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
|
|
309
|
+
const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
|
|
310
|
+
options: {},
|
|
311
|
+
commit: {
|
|
312
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
313
|
+
sourceCommit: {
|
|
314
|
+
committedDate: '100',
|
|
315
|
+
message: 'Second commit (#2)',
|
|
316
|
+
sha: 'abc',
|
|
317
|
+
},
|
|
318
|
+
sourcePullRequest: {
|
|
319
|
+
url: 'https://www.github.com/foo/bar/pull/123',
|
|
320
|
+
number: 123,
|
|
321
|
+
mergeCommit: {
|
|
322
|
+
message: 'Second commit (#2)',
|
|
323
|
+
sha: 'abc',
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
expectedTargetPullRequests: [],
|
|
327
|
+
sourceBranch: 'main',
|
|
328
|
+
},
|
|
329
|
+
targetBranch: '7.x',
|
|
330
|
+
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
331
|
+
});
|
|
332
|
+
expect(commitsWithoutBackports.length).toEqual(0);
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGitConfigAuthor = void 0;
|
|
4
|
+
const git_1 = require("./git");
|
|
5
|
+
async function getGitConfigAuthor(options) {
|
|
6
|
+
const localRepoPath = await (0, git_1.getLocalSourceRepoPath)(options);
|
|
7
|
+
if (!localRepoPath) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
name: await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.name' }),
|
|
12
|
+
email: await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.email' }),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.getGitConfigAuthor = getGitConfigAuthor;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TargetBranchChoice } from '../options/ConfigOptions';
|
|
2
|
+
import { ValidConfigOptions } from '../options/options';
|
|
3
|
+
import { Commit } from './sourceCommit/parseSourceCommit';
|
|
4
|
+
export declare function getTargetBranches(options: ValidConfigOptions, commits: Commit[]): string[] | Promise<string[]>;
|
|
5
|
+
export declare function getTargetBranchChoices(options: ValidConfigOptions, missingTargetBranches: string[], sourceBranch: string): TargetBranchChoice[];
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTargetBranchChoices = exports.getTargetBranches = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const BackportError_1 = require("./BackportError");
|
|
6
|
+
const prompts_1 = require("./prompts");
|
|
7
|
+
function getTargetBranches(options, commits) {
|
|
8
|
+
// target branches already specified (in contrast to letting the user choose from a list)
|
|
9
|
+
if (!(0, lodash_1.isEmpty)(options.targetBranches)) {
|
|
10
|
+
return options.targetBranches;
|
|
11
|
+
}
|
|
12
|
+
// target branches from the first commit
|
|
13
|
+
const missingTargetBranches = commits.length === 1
|
|
14
|
+
? commits[0].expectedTargetPullRequests
|
|
15
|
+
.filter((pr) => pr.state === 'NOT_CREATED' || pr.state === 'CLOSED')
|
|
16
|
+
.map((pr) => pr.branch)
|
|
17
|
+
: [];
|
|
18
|
+
// require target branches to be specified when when in non-interactive mode
|
|
19
|
+
if (!options.interactive) {
|
|
20
|
+
if ((0, lodash_1.isEmpty)(missingTargetBranches)) {
|
|
21
|
+
throw new BackportError_1.BackportError({ code: 'no-branches-exception' });
|
|
22
|
+
}
|
|
23
|
+
return missingTargetBranches;
|
|
24
|
+
}
|
|
25
|
+
// sourceBranch should be the same for all commits, so picking `sourceBranch` from the first commit should be fine 🤞
|
|
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.
|
|
27
|
+
const { sourceBranch } = commits[0];
|
|
28
|
+
const targetBranchChoices = getTargetBranchChoices(options, missingTargetBranches, sourceBranch);
|
|
29
|
+
// render prmompt for selecting target branches
|
|
30
|
+
return (0, prompts_1.promptForTargetBranches)({
|
|
31
|
+
targetBranchChoices,
|
|
32
|
+
isMultipleChoice: options.multipleBranches,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.getTargetBranches = getTargetBranches;
|
|
36
|
+
function getTargetBranchChoices(options, missingTargetBranches, sourceBranch) {
|
|
37
|
+
// exclude sourceBranch from targetBranchChoices
|
|
38
|
+
const targetBranchesChoices = getTargetBranchChoicesAsObject(options.targetBranchChoices).filter((choice) => choice.name !== sourceBranch);
|
|
39
|
+
if ((0, lodash_1.isEmpty)(targetBranchesChoices)) {
|
|
40
|
+
throw new BackportError_1.BackportError('Missing target branch choices');
|
|
41
|
+
}
|
|
42
|
+
if (!options.branchLabelMapping) {
|
|
43
|
+
return targetBranchesChoices;
|
|
44
|
+
}
|
|
45
|
+
// select missing target branches (based on pull request labels)
|
|
46
|
+
return targetBranchesChoices.map((choice) => {
|
|
47
|
+
const isChecked = missingTargetBranches.includes(choice.name);
|
|
48
|
+
return { ...choice, checked: isChecked };
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.getTargetBranchChoices = getTargetBranchChoices;
|
|
52
|
+
// `targetBranchChoices` can either be a string or an object.
|
|
53
|
+
// It must be transformed so it is always treated as an object troughout the application
|
|
54
|
+
function getTargetBranchChoicesAsObject(targetBranchChoices) {
|
|
55
|
+
if (!targetBranchChoices) {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
return targetBranchChoices.map((choice) => {
|
|
59
|
+
if ((0, lodash_1.isString)(choice)) {
|
|
60
|
+
return {
|
|
61
|
+
name: choice,
|
|
62
|
+
checked: false,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return choice;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const getTargetBranches_1 = require("./getTargetBranches");
|
|
27
|
+
const prompts = __importStar(require("./prompts"));
|
|
28
|
+
describe('getTargetBranches', () => {
|
|
29
|
+
let promptSpy;
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
jest.clearAllMocks();
|
|
32
|
+
promptSpy = jest
|
|
33
|
+
.spyOn(prompts, 'promptForTargetBranches')
|
|
34
|
+
.mockResolvedValueOnce(['branchA']);
|
|
35
|
+
});
|
|
36
|
+
describe('when `options.targetBranches` is empty', () => {
|
|
37
|
+
let branches;
|
|
38
|
+
beforeEach(async () => {
|
|
39
|
+
const options = {
|
|
40
|
+
targetBranches: [],
|
|
41
|
+
targetBranchChoices: [{ name: 'branchA' }, { name: 'branchB' }],
|
|
42
|
+
multipleBranches: false,
|
|
43
|
+
interactive: true,
|
|
44
|
+
};
|
|
45
|
+
const commits = [
|
|
46
|
+
{
|
|
47
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
48
|
+
sourceCommit: {
|
|
49
|
+
committedDate: 'aaa',
|
|
50
|
+
message: 'hey',
|
|
51
|
+
sha: 'abcd',
|
|
52
|
+
},
|
|
53
|
+
sourcePullRequest: {
|
|
54
|
+
url: 'foo',
|
|
55
|
+
number: 1337,
|
|
56
|
+
mergeCommit: {
|
|
57
|
+
message: 'hey',
|
|
58
|
+
sha: 'abcd',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
sourceBranch: '7.x',
|
|
62
|
+
expectedTargetPullRequests: [],
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
branches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
|
66
|
+
});
|
|
67
|
+
it('should return branches from prompt', () => {
|
|
68
|
+
expect(branches).toEqual(['branchA']);
|
|
69
|
+
});
|
|
70
|
+
it('should call prompt with correct args', () => {
|
|
71
|
+
expect(promptSpy).toHaveBeenLastCalledWith({
|
|
72
|
+
targetBranchChoices: [{ name: 'branchA' }, { name: 'branchB' }],
|
|
73
|
+
isMultipleChoice: false,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
describe('when `options.targetBranches` is not empty', () => {
|
|
78
|
+
let branches;
|
|
79
|
+
beforeEach(() => {
|
|
80
|
+
branches = (0, getTargetBranches_1.getTargetBranches)({
|
|
81
|
+
targetBranches: ['branchA', 'branchB'],
|
|
82
|
+
targetBranchChoices: [],
|
|
83
|
+
multipleBranches: false,
|
|
84
|
+
}, []);
|
|
85
|
+
});
|
|
86
|
+
it('should return branches from `options.branches`', () => {
|
|
87
|
+
expect(branches).toEqual(['branchA', 'branchB']);
|
|
88
|
+
});
|
|
89
|
+
it('should not call prompt', () => {
|
|
90
|
+
expect(promptSpy).not.toHaveBeenCalled();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe('when interactive=false', () => {
|
|
94
|
+
it('should throw when there are no missing backports', () => {
|
|
95
|
+
const commits = [];
|
|
96
|
+
expect(() => {
|
|
97
|
+
return (0, getTargetBranches_1.getTargetBranches)({
|
|
98
|
+
expectedTargetPullRequests: [],
|
|
99
|
+
interactive: false,
|
|
100
|
+
}, commits);
|
|
101
|
+
}).toThrow('There are no branches to backport to. Aborting.');
|
|
102
|
+
});
|
|
103
|
+
it('should return missing backports', () => {
|
|
104
|
+
const commits = [
|
|
105
|
+
{
|
|
106
|
+
expectedTargetPullRequests: [
|
|
107
|
+
{ branch: '7.2', state: 'MERGED' },
|
|
108
|
+
{ branch: '7.1', state: 'OPEN' },
|
|
109
|
+
{ branch: '7.x', state: 'NOT_CREATED' },
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
const targetBranches = (0, getTargetBranches_1.getTargetBranches)({ interactive: false }, commits);
|
|
114
|
+
expect(targetBranches).toEqual(['7.x']);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
describe('when `expectedTargetPullRequests` is missing a backport to 7.x', () => {
|
|
118
|
+
let targetBranchChoices;
|
|
119
|
+
beforeEach(async () => {
|
|
120
|
+
const options = {
|
|
121
|
+
interactive: true,
|
|
122
|
+
targetBranches: [],
|
|
123
|
+
multipleBranches: true,
|
|
124
|
+
targetBranchChoices: [
|
|
125
|
+
{ name: 'master' },
|
|
126
|
+
{ name: '7.x' },
|
|
127
|
+
{ name: '7.7' },
|
|
128
|
+
{ name: '7.6' },
|
|
129
|
+
{ name: '7.5' },
|
|
130
|
+
],
|
|
131
|
+
branchLabelMapping: {},
|
|
132
|
+
sourceBranch: 'master',
|
|
133
|
+
};
|
|
134
|
+
const commits = [
|
|
135
|
+
{
|
|
136
|
+
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
137
|
+
sourceCommit: {
|
|
138
|
+
committedDate: 'bbb',
|
|
139
|
+
message: '[backport] Bump to 5.1.3 (#62286)',
|
|
140
|
+
sha: 'my-sha',
|
|
141
|
+
},
|
|
142
|
+
sourcePullRequest: {
|
|
143
|
+
url: 'foo',
|
|
144
|
+
number: 62286,
|
|
145
|
+
mergeCommit: {
|
|
146
|
+
message: '[backport] Bump to 5.1.3 (#62286)',
|
|
147
|
+
sha: 'my-sha',
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
sourceBranch: 'master',
|
|
151
|
+
expectedTargetPullRequests: [{ branch: '7.x', state: 'NOT_CREATED' }],
|
|
152
|
+
},
|
|
153
|
+
];
|
|
154
|
+
await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
|
155
|
+
targetBranchChoices = promptSpy.mock.calls[0][0].targetBranchChoices;
|
|
156
|
+
});
|
|
157
|
+
it('should list the correct branches', async () => {
|
|
158
|
+
expect(targetBranchChoices).toEqual([
|
|
159
|
+
{ checked: true, name: '7.x' },
|
|
160
|
+
{ checked: false, name: '7.7' },
|
|
161
|
+
{ checked: false, name: '7.6' },
|
|
162
|
+
{ checked: false, name: '7.5' },
|
|
163
|
+
]);
|
|
164
|
+
});
|
|
165
|
+
it('should not list the sourceBranch (master)', async () => {
|
|
166
|
+
expect(targetBranchChoices).not.toContainEqual(expect.objectContaining({ name: 'master' }));
|
|
167
|
+
});
|
|
168
|
+
it('should select 7.x', async () => {
|
|
169
|
+
expect(targetBranchChoices).toContainEqual({
|
|
170
|
+
name: '7.x',
|
|
171
|
+
checked: true,
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
describe('getTargetBranchChoices', () => {
|
|
177
|
+
const options = {
|
|
178
|
+
interactive: true,
|
|
179
|
+
targetBranchChoices: [
|
|
180
|
+
{ name: 'master', checked: true },
|
|
181
|
+
{ name: '7.x', checked: true },
|
|
182
|
+
{ name: '7.8', checked: false },
|
|
183
|
+
{ name: '7.7', checked: false },
|
|
184
|
+
],
|
|
185
|
+
branchLabelMapping: {},
|
|
186
|
+
};
|
|
187
|
+
const sourceBranch = 'master';
|
|
188
|
+
it('should not check any branches if no labels match', () => {
|
|
189
|
+
const targetBranchesFromLabels = [];
|
|
190
|
+
const branches = (0, getTargetBranches_1.getTargetBranchChoices)(options, targetBranchesFromLabels, sourceBranch);
|
|
191
|
+
expect(branches).toEqual([
|
|
192
|
+
{ checked: false, name: '7.x' },
|
|
193
|
+
{ checked: false, name: '7.8' },
|
|
194
|
+
{ checked: false, name: '7.7' },
|
|
195
|
+
]);
|
|
196
|
+
});
|
|
197
|
+
it('should pre-select branches based on labels', () => {
|
|
198
|
+
const targetBranchesFromLabels = ['7.7'];
|
|
199
|
+
const branches = (0, getTargetBranches_1.getTargetBranchChoices)(options, targetBranchesFromLabels, sourceBranch);
|
|
200
|
+
expect(branches).toEqual([
|
|
201
|
+
{ checked: false, name: '7.x' },
|
|
202
|
+
{ checked: false, name: '7.8' },
|
|
203
|
+
{ checked: true, name: '7.7' },
|
|
204
|
+
]);
|
|
205
|
+
});
|
|
206
|
+
});
|