backport 8.6.2 → 8.7.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/dist/entrypoint.module.private.test.js +78 -52
- package/dist/lib/{cherrypickAndCreateTargetPullRequest.d.ts → cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.d.ts} +2 -2
- package/dist/lib/cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.js +98 -0
- package/dist/lib/{cherrypickAndCreateTargetPullRequest.test.d.ts → cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.test.d.ts} +0 -0
- package/dist/lib/{cherrypickAndCreateTargetPullRequest.test.js → cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.test.js} +12 -10
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getBackportBranchName.d.ts +2 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getBackportBranchName.js +22 -0
- package/dist/lib/{getCommitsWithoutBackports.d.ts → cherrypickAndCreateTargetPullRequest/getCommitsWithoutBackports.d.ts} +2 -2
- package/dist/lib/{getCommitsWithoutBackports.js → cherrypickAndCreateTargetPullRequest/getCommitsWithoutBackports.js} +6 -6
- package/dist/lib/{getCommitsWithoutBackports.test.d.ts → cherrypickAndCreateTargetPullRequest/getCommitsWithoutBackports.test.d.ts} +0 -0
- package/dist/lib/{getCommitsWithoutBackports.test.js → cherrypickAndCreateTargetPullRequest/getCommitsWithoutBackports.test.js} +24 -17
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getMergeCommit.d.ts +3 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getMergeCommit.js +17 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getTargetPRLabels.d.ts +7 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getTargetPRLabels.js +33 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getTargetPRLabels.test.d.ts +1 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/getTargetPRLabels.test.js +166 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/waitForCherrypick.d.ts +3 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest/waitForCherrypick.js +154 -0
- package/dist/lib/getSourceBranchFromCommits.d.ts +2 -0
- package/dist/lib/getSourceBranchFromCommits.js +10 -0
- package/dist/lib/getTargetBranches.js +2 -3
- package/dist/lib/getTargetBranches.test.js +6 -4
- package/dist/lib/git.test.js +1 -1
- package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +11 -2
- package/dist/lib/github/v3/addAssigneesToPullRequest.js +9 -1
- package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +5 -2
- package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +10 -2
- package/dist/lib/github/v3/addLabelsToPullRequest.js +5 -1
- package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +1 -1
- package/dist/lib/github/v3/addReviewersToPullRequest.js +5 -1
- package/dist/lib/github/v3/createPullRequest.js +7 -1
- package/dist/lib/github/v3/createPullRequest.test.js +22 -13
- package/dist/lib/github/v3/createStatusComment.test.js +4 -2
- package/dist/lib/github/v4/enablePullRequestAutoMerge.js +4 -0
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +10 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +5 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +10 -4
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +7 -5
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -2
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +6 -5
- package/dist/lib/prompt.test.js +14 -6
- package/dist/lib/prompts.js +2 -2
- package/dist/lib/sourceCommit/getPullRequestStates.d.ts +3 -2
- package/dist/lib/sourceCommit/getPullRequestStates.js +13 -20
- package/dist/lib/sourceCommit/getPullRequestStates.test.js +69 -28
- package/dist/lib/sourceCommit/parseSourceCommit.d.ts +2 -1
- package/dist/lib/sourceCommit/parseSourceCommit.js +15 -7
- package/dist/lib/sourceCommit/parseSourceCommit.test.js +15 -4
- package/dist/runSequentially.js +5 -5
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +6 -2
- package/dist/test/e2e/cli/gracefully-handles-corrupt-repo.private.test.js +5 -1
- package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.js +2 -2
- package/dist/test/e2e/cli/repo-with-programatically-added-commits.mutation.test.js +1 -1
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +6 -2
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +4 -4
- package/dist/test/handleUnbackportedPullRequests.private.test.js +3 -1
- package/dist/utils/filterUnmergedCommits.js +1 -1
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +7 -7
- package/yarn.lock +75 -75
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +0 -255
|
@@ -27,15 +27,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
30
|
+
const git = __importStar(require("../git"));
|
|
31
|
+
const fetchCommitsByAuthorModule = __importStar(require("../github/v4/fetchCommits/fetchCommitsByAuthor"));
|
|
30
32
|
const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
|
|
31
|
-
const git = __importStar(require("./git"));
|
|
32
|
-
const fetchCommitsByAuthorModule = __importStar(require("./github/v4/fetchCommits/fetchCommitsByAuthor"));
|
|
33
33
|
describe('getCommitsWithoutBackports', () => {
|
|
34
34
|
afterEach(() => {
|
|
35
35
|
jest.restoreAllMocks();
|
|
36
36
|
});
|
|
37
|
-
describe('
|
|
38
|
-
function setupExpectedPullRequests({
|
|
37
|
+
describe('targetPullRequestStates', () => {
|
|
38
|
+
function setupExpectedPullRequests({ targetPullRequestStates, }) {
|
|
39
39
|
// simulate 1 unbackported commit
|
|
40
40
|
jest
|
|
41
41
|
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
@@ -53,6 +53,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
53
53
|
sha: 'xyz',
|
|
54
54
|
},
|
|
55
55
|
sourcePullRequest: {
|
|
56
|
+
labels: [],
|
|
56
57
|
url: 'https://www.github.com/foo/bar/pull/123',
|
|
57
58
|
number: 123,
|
|
58
59
|
mergeCommit: {
|
|
@@ -60,7 +61,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
60
61
|
sha: 'xyz',
|
|
61
62
|
},
|
|
62
63
|
},
|
|
63
|
-
|
|
64
|
+
targetPullRequestStates: targetPullRequestStates,
|
|
64
65
|
sourceBranch: 'main',
|
|
65
66
|
},
|
|
66
67
|
]);
|
|
@@ -77,7 +78,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
77
78
|
message: 'Second commit (#2)',
|
|
78
79
|
sha: 'abc',
|
|
79
80
|
},
|
|
80
|
-
|
|
81
|
+
targetPullRequestStates: [],
|
|
81
82
|
sourceBranch: 'main',
|
|
82
83
|
},
|
|
83
84
|
targetBranch: '7.x',
|
|
@@ -86,13 +87,13 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
86
87
|
}
|
|
87
88
|
it('should not unbackported commits if no backports were expected', async () => {
|
|
88
89
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
89
|
-
|
|
90
|
+
targetPullRequestStates: [],
|
|
90
91
|
});
|
|
91
92
|
expect(commitsWithoutBackports.length).toEqual(0);
|
|
92
93
|
});
|
|
93
94
|
it('should display as missing if a backport is CLOSED', async () => {
|
|
94
95
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
95
|
-
|
|
96
|
+
targetPullRequestStates: [
|
|
96
97
|
{
|
|
97
98
|
state: 'CLOSED',
|
|
98
99
|
branch: '7.x',
|
|
@@ -105,8 +106,9 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
105
106
|
});
|
|
106
107
|
it('should display as missing if a backport is NOT_CREATED', async () => {
|
|
107
108
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
108
|
-
|
|
109
|
+
targetPullRequestStates: [
|
|
109
110
|
{
|
|
111
|
+
labelRegex: 'foo tbd',
|
|
110
112
|
state: 'NOT_CREATED',
|
|
111
113
|
branch: '7.x',
|
|
112
114
|
label: 'v7.0.0',
|
|
@@ -118,7 +120,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
118
120
|
});
|
|
119
121
|
it('should display as pending if a backport is OPEN', async () => {
|
|
120
122
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
121
|
-
|
|
123
|
+
targetPullRequestStates: [
|
|
122
124
|
{
|
|
123
125
|
state: 'OPEN',
|
|
124
126
|
branch: '7.x',
|
|
@@ -131,7 +133,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
131
133
|
});
|
|
132
134
|
it('should not display commit as unbackported if a backport was MERGED', async () => {
|
|
133
135
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
134
|
-
|
|
136
|
+
targetPullRequestStates: [
|
|
135
137
|
{
|
|
136
138
|
state: 'MERGED',
|
|
137
139
|
branch: '7.x',
|
|
@@ -162,6 +164,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
162
164
|
sha: 'xyz',
|
|
163
165
|
},
|
|
164
166
|
sourcePullRequest: {
|
|
167
|
+
labels: [],
|
|
165
168
|
number: 123,
|
|
166
169
|
url: 'https://www.github.com/foo/bar/pull/123',
|
|
167
170
|
mergeCommit: {
|
|
@@ -170,7 +173,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
170
173
|
},
|
|
171
174
|
},
|
|
172
175
|
sourceBranch: 'main',
|
|
173
|
-
|
|
176
|
+
targetPullRequestStates: [
|
|
174
177
|
{
|
|
175
178
|
state: 'OPEN',
|
|
176
179
|
branch: '7.x',
|
|
@@ -194,6 +197,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
194
197
|
sha: 'abc',
|
|
195
198
|
},
|
|
196
199
|
sourcePullRequest: {
|
|
200
|
+
labels: [],
|
|
197
201
|
number: 123,
|
|
198
202
|
url: 'https://www.github.com/foo/bar/pull/123',
|
|
199
203
|
mergeCommit: {
|
|
@@ -202,7 +206,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
202
206
|
},
|
|
203
207
|
},
|
|
204
208
|
sourceBranch: 'main',
|
|
205
|
-
|
|
209
|
+
targetPullRequestStates: [],
|
|
206
210
|
},
|
|
207
211
|
targetBranch: '7.x',
|
|
208
212
|
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
@@ -242,6 +246,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
242
246
|
sha: 'xyz',
|
|
243
247
|
},
|
|
244
248
|
sourcePullRequest: {
|
|
249
|
+
labels: [],
|
|
245
250
|
number: 123,
|
|
246
251
|
url: 'https://www.github.com/foo/bar/pull/123',
|
|
247
252
|
mergeCommit: {
|
|
@@ -250,7 +255,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
250
255
|
},
|
|
251
256
|
},
|
|
252
257
|
sourceBranch: 'main',
|
|
253
|
-
|
|
258
|
+
targetPullRequestStates: [
|
|
254
259
|
{
|
|
255
260
|
branch: offendingCommitTargetBranch,
|
|
256
261
|
state: 'OPEN',
|
|
@@ -275,6 +280,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
275
280
|
sha: 'abc',
|
|
276
281
|
},
|
|
277
282
|
sourcePullRequest: {
|
|
283
|
+
labels: [],
|
|
278
284
|
url: 'https://www.github.com/foo/bar/pull/123',
|
|
279
285
|
number: 123,
|
|
280
286
|
mergeCommit: {
|
|
@@ -282,7 +288,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
282
288
|
sha: 'abc',
|
|
283
289
|
},
|
|
284
290
|
},
|
|
285
|
-
|
|
291
|
+
targetPullRequestStates: [],
|
|
286
292
|
sourceBranch: 'main',
|
|
287
293
|
},
|
|
288
294
|
targetBranch: currentCommitTargetBranch,
|
|
@@ -321,7 +327,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
321
327
|
sha: 'xyz',
|
|
322
328
|
message: 'First commit (#1)',
|
|
323
329
|
},
|
|
324
|
-
|
|
330
|
+
targetPullRequestStates: [],
|
|
325
331
|
sourceBranch: 'main',
|
|
326
332
|
},
|
|
327
333
|
]);
|
|
@@ -339,6 +345,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
339
345
|
sha: 'abc',
|
|
340
346
|
},
|
|
341
347
|
sourcePullRequest: {
|
|
348
|
+
labels: [],
|
|
342
349
|
url: 'https://www.github.com/foo/bar/pull/123',
|
|
343
350
|
number: 123,
|
|
344
351
|
mergeCommit: {
|
|
@@ -346,7 +353,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
346
353
|
sha: 'abc',
|
|
347
354
|
},
|
|
348
355
|
},
|
|
349
|
-
|
|
356
|
+
targetPullRequestStates: [],
|
|
350
357
|
sourceBranch: 'main',
|
|
351
358
|
},
|
|
352
359
|
targetBranch: '7.x',
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMergeCommits = void 0;
|
|
4
|
+
const git_1 = require("../git");
|
|
5
|
+
const fetchCommitBySha_1 = require("../github/v4/fetchCommits/fetchCommitBySha");
|
|
6
|
+
async function getMergeCommits(options, commit) {
|
|
7
|
+
const { sha } = commit.sourceCommit;
|
|
8
|
+
if (!options.mainline) {
|
|
9
|
+
const isMergeCommit = await (0, git_1.getIsMergeCommit)(options, sha);
|
|
10
|
+
if (isMergeCommit) {
|
|
11
|
+
const shas = await (0, git_1.getShasInMergeCommit)(options, sha);
|
|
12
|
+
return Promise.all(shas.reverse().map((sha) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha })));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return [commit];
|
|
16
|
+
}
|
|
17
|
+
exports.getMergeCommits = getMergeCommits;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTargetPRLabels = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const filterEmpty_1 = require("../../utils/filterEmpty");
|
|
6
|
+
const getSourceBranchFromCommits_1 = require("../getSourceBranchFromCommits");
|
|
7
|
+
const logger_1 = require("../logger");
|
|
8
|
+
function getTargetPRLabels({ interactive, targetPRLabels, commits, targetBranch, }) {
|
|
9
|
+
const sourceBranch = (0, getSourceBranchFromCommits_1.getSourceBranchFromCommits)(commits);
|
|
10
|
+
const labels = commits
|
|
11
|
+
.flatMap((c) => {
|
|
12
|
+
const targetPullRequest = c.targetPullRequestStates.find((pr) => pr.branch === targetBranch);
|
|
13
|
+
if (!targetPullRequest?.labelRegex) {
|
|
14
|
+
logger_1.logger.info('Missing labelRegex for target pull request');
|
|
15
|
+
// remove dynamic labels like `$1` in interactive mode
|
|
16
|
+
return targetPRLabels.filter((l) => {
|
|
17
|
+
return l.match(/\$\d/) === null || !interactive;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const regex = new RegExp(targetPullRequest.labelRegex);
|
|
21
|
+
return targetPRLabels.map((targetPRLabel) => {
|
|
22
|
+
return targetPullRequest.label?.replace(regex, targetPRLabel);
|
|
23
|
+
});
|
|
24
|
+
})
|
|
25
|
+
.filter(filterEmpty_1.filterNil)
|
|
26
|
+
.map((label) => {
|
|
27
|
+
return label
|
|
28
|
+
.replaceAll('{targetBranch}', targetBranch)
|
|
29
|
+
.replaceAll('{sourceBranch}', sourceBranch);
|
|
30
|
+
});
|
|
31
|
+
return (0, lodash_1.uniq)(labels);
|
|
32
|
+
}
|
|
33
|
+
exports.getTargetPRLabels = getTargetPRLabels;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getTargetPRLabels_1 = require("./getTargetPRLabels");
|
|
4
|
+
const commits = [
|
|
5
|
+
{
|
|
6
|
+
author: { name: 'Søren Louv-Jansen', email: 'sorenlouv@gmail.com' },
|
|
7
|
+
suggestedTargetBranches: [],
|
|
8
|
+
sourceCommit: {
|
|
9
|
+
branchLabelMapping: {
|
|
10
|
+
'^backport-to-(.+)$': '$1',
|
|
11
|
+
},
|
|
12
|
+
committedDate: '2021-01-13T20:01:44Z',
|
|
13
|
+
message: 'Fix major bug (#88188)',
|
|
14
|
+
sha: 'd1b348e6213c5ad48653dfaad6eaf4928b2c688b',
|
|
15
|
+
},
|
|
16
|
+
sourcePullRequest: {
|
|
17
|
+
labels: ['backport-to-7.11'],
|
|
18
|
+
number: 88188,
|
|
19
|
+
url: 'https://github.com/elastic/kibana/pull/88188',
|
|
20
|
+
mergeCommit: {
|
|
21
|
+
message: 'Fix major bug (#88188)',
|
|
22
|
+
sha: 'd1b348e6213c5ad48653dfaad6eaf4928b2c688b',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
sourceBranch: 'master',
|
|
26
|
+
targetPullRequestStates: [
|
|
27
|
+
// PR to 7.11 branch was created automatically using the label `backport-to-7.11`
|
|
28
|
+
{
|
|
29
|
+
url: 'https://github.com/elastic/kibana/pull/88289',
|
|
30
|
+
number: 88289,
|
|
31
|
+
branch: '7.11',
|
|
32
|
+
label: 'backport-to-7.11',
|
|
33
|
+
labelRegex: '^backport-to-(.+)$',
|
|
34
|
+
isSourceBranch: false,
|
|
35
|
+
state: 'OPEN',
|
|
36
|
+
mergeCommit: {
|
|
37
|
+
sha: 'b8194e9ec27d69f485d8b194d1cb5e4f6d8fef6d',
|
|
38
|
+
message: 'Fix major bug (#88188) (#88289)',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
// PR to 7.x branch was created manually (not via labels) and does not contain labelRegex
|
|
42
|
+
{
|
|
43
|
+
url: 'https://github.com/elastic/kibana/pull/88288',
|
|
44
|
+
number: 88288,
|
|
45
|
+
branch: '7.x',
|
|
46
|
+
state: 'OPEN',
|
|
47
|
+
mergeCommit: {
|
|
48
|
+
sha: '52710be7add6811ec4783c7d383d4159c0aa76f5',
|
|
49
|
+
message: '[7.x] Fix major bug (#88188) (#88288)',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
describe('getTargetPRLabels', () => {
|
|
56
|
+
describe('replaces template values', () => {
|
|
57
|
+
it('replaces {targetBranch}', () => {
|
|
58
|
+
const labels = (0, getTargetPRLabels_1.getTargetPRLabels)({
|
|
59
|
+
interactive: false,
|
|
60
|
+
commits,
|
|
61
|
+
targetPRLabels: ['backported-to-{targetBranch}'],
|
|
62
|
+
targetBranch: '7.x',
|
|
63
|
+
});
|
|
64
|
+
expect(labels).toEqual(['backported-to-7.x']);
|
|
65
|
+
});
|
|
66
|
+
it('replaces {sourceBranch}', () => {
|
|
67
|
+
const labels = (0, getTargetPRLabels_1.getTargetPRLabels)({
|
|
68
|
+
interactive: false,
|
|
69
|
+
commits,
|
|
70
|
+
targetPRLabels: ['backported-from-{sourceBranch}'],
|
|
71
|
+
targetBranch: '7.x',
|
|
72
|
+
});
|
|
73
|
+
expect(labels).toEqual(['backported-from-master']);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe('when label is static', () => {
|
|
77
|
+
describe('and when interactive=false', () => {
|
|
78
|
+
it('adds static label for 7.11', () => {
|
|
79
|
+
const labels = (0, getTargetPRLabels_1.getTargetPRLabels)({
|
|
80
|
+
interactive: false,
|
|
81
|
+
commits,
|
|
82
|
+
targetPRLabels: ['some-static-label'],
|
|
83
|
+
targetBranch: '7.11',
|
|
84
|
+
});
|
|
85
|
+
expect(labels).toEqual(['some-static-label']);
|
|
86
|
+
});
|
|
87
|
+
it('adds static label for 7.x', () => {
|
|
88
|
+
const labels = (0, getTargetPRLabels_1.getTargetPRLabels)({
|
|
89
|
+
interactive: false,
|
|
90
|
+
commits,
|
|
91
|
+
targetPRLabels: ['some-static-label'],
|
|
92
|
+
targetBranch: '7.x',
|
|
93
|
+
});
|
|
94
|
+
expect(labels).toEqual(['some-static-label']);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
describe('and when interactive=true', () => {
|
|
98
|
+
it('adds static label for 7.x', () => {
|
|
99
|
+
const labels = (0, getTargetPRLabels_1.getTargetPRLabels)({
|
|
100
|
+
interactive: true,
|
|
101
|
+
commits,
|
|
102
|
+
targetPRLabels: ['backport'],
|
|
103
|
+
targetBranch: '7.x',
|
|
104
|
+
});
|
|
105
|
+
expect(labels).toEqual(['backport']);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
describe('when label is dynamic', () => {
|
|
110
|
+
describe('and when interactive=false', () => {
|
|
111
|
+
it('adds dynamic label for 7.11', () => {
|
|
112
|
+
const labels = (0, getTargetPRLabels_1.getTargetPRLabels)({
|
|
113
|
+
interactive: false,
|
|
114
|
+
commits,
|
|
115
|
+
targetPRLabels: ['backport-$1'],
|
|
116
|
+
targetBranch: '7.11',
|
|
117
|
+
});
|
|
118
|
+
expect(labels).toEqual(['backport-7.11']);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
describe('when interactive=true', () => {
|
|
122
|
+
it('adds dynamic label for 7.11', () => {
|
|
123
|
+
const labels = (0, getTargetPRLabels_1.getTargetPRLabels)({
|
|
124
|
+
interactive: false,
|
|
125
|
+
commits,
|
|
126
|
+
targetPRLabels: ['backport-$1'],
|
|
127
|
+
targetBranch: '7.11',
|
|
128
|
+
});
|
|
129
|
+
expect(labels).toEqual(['backport-7.11']);
|
|
130
|
+
});
|
|
131
|
+
it('does not add dynamic label for 7.x', () => {
|
|
132
|
+
const labels = (0, getTargetPRLabels_1.getTargetPRLabels)({
|
|
133
|
+
interactive: true,
|
|
134
|
+
commits,
|
|
135
|
+
targetPRLabels: ['backport-$1'],
|
|
136
|
+
targetBranch: '7.x',
|
|
137
|
+
});
|
|
138
|
+
expect(labels).toEqual([]);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
describe('multiple dynamic labels', () => {
|
|
143
|
+
describe('interactive=false', () => {
|
|
144
|
+
it('adds dynamic and static labels for 7.11', () => {
|
|
145
|
+
const labels = (0, getTargetPRLabels_1.getTargetPRLabels)({
|
|
146
|
+
interactive: false,
|
|
147
|
+
commits,
|
|
148
|
+
targetPRLabels: ['backport-$1', '$1', 'my-static-label'],
|
|
149
|
+
targetBranch: '7.11',
|
|
150
|
+
});
|
|
151
|
+
expect(labels).toEqual(['backport-7.11', '7.11', 'my-static-label']);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
describe('interactive=true', () => {
|
|
155
|
+
it('only add the static labels for 7.x', () => {
|
|
156
|
+
const labels = (0, getTargetPRLabels_1.getTargetPRLabels)({
|
|
157
|
+
interactive: true,
|
|
158
|
+
commits,
|
|
159
|
+
targetPRLabels: ['backport-$1', '$1', 'my-static-label'],
|
|
160
|
+
targetBranch: '7.x',
|
|
161
|
+
});
|
|
162
|
+
expect(labels).toEqual(['my-static-label']);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
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.waitForCherrypick = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const entrypoint_module_1 = require("../../entrypoint.module");
|
|
10
|
+
const ora_1 = require("../../lib/ora");
|
|
11
|
+
const author_1 = require("../author");
|
|
12
|
+
const child_process_promisified_1 = require("../child-process-promisified");
|
|
13
|
+
const env_1 = require("../env");
|
|
14
|
+
const git_1 = require("../git");
|
|
15
|
+
const commitFormatters_1 = require("../github/commitFormatters");
|
|
16
|
+
const logger_1 = require("../logger");
|
|
17
|
+
const prompts_1 = require("../prompts");
|
|
18
|
+
const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
|
|
19
|
+
async function waitForCherrypick(options, commit, targetBranch) {
|
|
20
|
+
const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))}`;
|
|
21
|
+
const cherrypickSpinner = (0, ora_1.ora)(options.interactive, spinnerText).start();
|
|
22
|
+
const commitAuthor = (0, author_1.getCommitAuthor)({ options, commit });
|
|
23
|
+
await cherrypickAndHandleConflicts({
|
|
24
|
+
options,
|
|
25
|
+
commit,
|
|
26
|
+
commitAuthor,
|
|
27
|
+
targetBranch,
|
|
28
|
+
cherrypickSpinner,
|
|
29
|
+
});
|
|
30
|
+
// Conflicts should be resolved and files staged at this point
|
|
31
|
+
try {
|
|
32
|
+
// Run `git commit` in case conflicts were not manually committed
|
|
33
|
+
await (0, git_1.commitChanges)({ options, commit, commitAuthor });
|
|
34
|
+
cherrypickSpinner.succeed();
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
cherrypickSpinner.fail();
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.waitForCherrypick = waitForCherrypick;
|
|
42
|
+
async function cherrypickAndHandleConflicts({ options, commit, commitAuthor, targetBranch, cherrypickSpinner, }) {
|
|
43
|
+
const mergedTargetPullRequest = commit.targetPullRequestStates.find((pr) => pr.state === 'MERGED' && pr.branch === targetBranch);
|
|
44
|
+
let conflictingFiles;
|
|
45
|
+
let unstagedFiles;
|
|
46
|
+
let needsResolving;
|
|
47
|
+
try {
|
|
48
|
+
({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)({
|
|
49
|
+
options,
|
|
50
|
+
sha: commit.sourceCommit.sha,
|
|
51
|
+
mergedTargetPullRequest,
|
|
52
|
+
commitAuthor,
|
|
53
|
+
}));
|
|
54
|
+
// no conflicts encountered
|
|
55
|
+
if (!needsResolving) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// cherrypick failed due to conflicts
|
|
59
|
+
cherrypickSpinner.fail();
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
cherrypickSpinner.fail();
|
|
63
|
+
throw e;
|
|
64
|
+
}
|
|
65
|
+
const repoPath = (0, env_1.getRepoPath)(options);
|
|
66
|
+
// resolve conflicts automatically
|
|
67
|
+
if (options.autoFixConflicts) {
|
|
68
|
+
const autoResolveSpinner = (0, ora_1.ora)(options.interactive, 'Attempting to resolve conflicts automatically').start();
|
|
69
|
+
const didAutoFix = await options.autoFixConflicts({
|
|
70
|
+
files: conflictingFiles.map((f) => f.absolute),
|
|
71
|
+
directory: repoPath,
|
|
72
|
+
logger: logger_1.logger,
|
|
73
|
+
targetBranch,
|
|
74
|
+
});
|
|
75
|
+
// conflicts were automatically resolved
|
|
76
|
+
if (didAutoFix) {
|
|
77
|
+
autoResolveSpinner.succeed();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
autoResolveSpinner.fail();
|
|
81
|
+
}
|
|
82
|
+
const conflictingFilesRelative = conflictingFiles
|
|
83
|
+
.map((f) => f.relative)
|
|
84
|
+
.slice(0, 50);
|
|
85
|
+
const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
|
|
86
|
+
options,
|
|
87
|
+
commit,
|
|
88
|
+
targetBranch,
|
|
89
|
+
conflictingFiles: conflictingFilesRelative,
|
|
90
|
+
});
|
|
91
|
+
if (!options.interactive) {
|
|
92
|
+
throw new entrypoint_module_1.BackportError({
|
|
93
|
+
code: 'merge-conflict-exception',
|
|
94
|
+
commitsWithoutBackports,
|
|
95
|
+
conflictingFiles: conflictingFilesRelative,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
(0, logger_1.consoleLog)(chalk_1.default.bold('\nThe commit could not be backported due to conflicts\n'));
|
|
99
|
+
(0, logger_1.consoleLog)(`Please fix the conflicts in ${repoPath}`);
|
|
100
|
+
if (commitsWithoutBackports.length > 0) {
|
|
101
|
+
(0, logger_1.consoleLog)(chalk_1.default.italic(`Hint: Before fixing the conflicts manually you should consider backporting the following pull requests to "${targetBranch}":`));
|
|
102
|
+
(0, logger_1.consoleLog)(`${commitsWithoutBackports.map((c) => c.formatted).join('\n')}\n\n`);
|
|
103
|
+
}
|
|
104
|
+
/*
|
|
105
|
+
* Commit could not be cleanly cherrypicked: Initiating conflict resolution
|
|
106
|
+
*/
|
|
107
|
+
if (options.editor) {
|
|
108
|
+
await (0, child_process_promisified_1.spawnPromise)(options.editor, [repoPath], options.cwd);
|
|
109
|
+
}
|
|
110
|
+
// list files with conflict markers + unstaged files and require user to resolve them
|
|
111
|
+
await listConflictingAndUnstagedFiles({
|
|
112
|
+
retries: 0,
|
|
113
|
+
options,
|
|
114
|
+
conflictingFiles: conflictingFiles.map((f) => f.absolute),
|
|
115
|
+
unstagedFiles,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
async function listConflictingAndUnstagedFiles({ retries, options, conflictingFiles, unstagedFiles, }) {
|
|
119
|
+
const hasUnstagedFiles = !(0, lodash_1.isEmpty)((0, lodash_1.difference)(unstagedFiles, conflictingFiles));
|
|
120
|
+
const hasConflictingFiles = !(0, lodash_1.isEmpty)(conflictingFiles);
|
|
121
|
+
if (!hasConflictingFiles && !hasUnstagedFiles) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
// add divider between prompts
|
|
125
|
+
if (retries > 0) {
|
|
126
|
+
(0, logger_1.consoleLog)('\n----------------------------------------\n');
|
|
127
|
+
}
|
|
128
|
+
const header = chalk_1.default.reset(`Fix the following conflicts manually:`);
|
|
129
|
+
// show conflict section if there are conflicting files
|
|
130
|
+
const conflictSection = hasConflictingFiles
|
|
131
|
+
? `Conflicting files:\n${chalk_1.default.reset(conflictingFiles.map((file) => ` - ${file}`).join('\n'))}`
|
|
132
|
+
: '';
|
|
133
|
+
const unstagedSection = hasUnstagedFiles
|
|
134
|
+
? `Unstaged files:\n${chalk_1.default.reset(unstagedFiles.map((file) => ` - ${file}`).join('\n'))}`
|
|
135
|
+
: '';
|
|
136
|
+
const didConfirm = await (0, prompts_1.confirmPrompt)(`${header}\n\n${conflictSection}\n${unstagedSection}\n\nPress ENTER when the conflicts are resolved and files are staged`);
|
|
137
|
+
if (!didConfirm) {
|
|
138
|
+
throw new entrypoint_module_1.BackportError({ code: 'abort-conflict-resolution-exception' });
|
|
139
|
+
}
|
|
140
|
+
const MAX_RETRIES = 100;
|
|
141
|
+
if (retries++ > MAX_RETRIES) {
|
|
142
|
+
throw new Error(`Maximum number of retries (${MAX_RETRIES}) exceeded`);
|
|
143
|
+
}
|
|
144
|
+
const [_conflictingFiles, _unstagedFiles] = await Promise.all([
|
|
145
|
+
(0, git_1.getConflictingFiles)(options),
|
|
146
|
+
(0, git_1.getUnstagedFiles)(options),
|
|
147
|
+
]);
|
|
148
|
+
await listConflictingAndUnstagedFiles({
|
|
149
|
+
retries,
|
|
150
|
+
options,
|
|
151
|
+
conflictingFiles: _conflictingFiles.map((file) => file.absolute),
|
|
152
|
+
unstagedFiles: _unstagedFiles,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSourceBranchFromCommits = void 0;
|
|
4
|
+
function getSourceBranchFromCommits(commits) {
|
|
5
|
+
// sourceBranch should be the same for all commits, so picking `sourceBranch` from the first commit should be fine 🤞
|
|
6
|
+
// 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.
|
|
7
|
+
const { sourceBranch } = commits[0];
|
|
8
|
+
return sourceBranch;
|
|
9
|
+
}
|
|
10
|
+
exports.getSourceBranchFromCommits = getSourceBranchFromCommits;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getTargetBranchChoices = exports.getTargetBranches = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
const BackportError_1 = require("./BackportError");
|
|
6
|
+
const getSourceBranchFromCommits_1 = require("./getSourceBranchFromCommits");
|
|
6
7
|
const prompts_1 = require("./prompts");
|
|
7
8
|
async function getTargetBranches(options, commits) {
|
|
8
9
|
// target branches already specified (in contrast to letting the user choose from a list)
|
|
@@ -18,9 +19,7 @@ async function getTargetBranches(options, commits) {
|
|
|
18
19
|
}
|
|
19
20
|
return suggestedTargetBranches;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
// 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.
|
|
23
|
-
const { sourceBranch } = commits[0];
|
|
22
|
+
const sourceBranch = (0, getSourceBranchFromCommits_1.getSourceBranchFromCommits)(commits);
|
|
24
23
|
const targetBranchChoices = getTargetBranchChoices(options, suggestedTargetBranches, sourceBranch);
|
|
25
24
|
// render prmompt for selecting target branches
|
|
26
25
|
return (0, prompts_1.promptForTargetBranches)({
|
|
@@ -52,6 +52,7 @@ describe('getTargetBranches', () => {
|
|
|
52
52
|
sha: 'abcd',
|
|
53
53
|
},
|
|
54
54
|
sourcePullRequest: {
|
|
55
|
+
labels: [],
|
|
55
56
|
url: 'foo',
|
|
56
57
|
number: 1337,
|
|
57
58
|
mergeCommit: {
|
|
@@ -61,7 +62,7 @@ describe('getTargetBranches', () => {
|
|
|
61
62
|
},
|
|
62
63
|
sourceBranch: '7.x',
|
|
63
64
|
suggestedTargetBranches: [],
|
|
64
|
-
|
|
65
|
+
targetPullRequestStates: [],
|
|
65
66
|
},
|
|
66
67
|
];
|
|
67
68
|
branches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
|
@@ -105,7 +106,7 @@ describe('getTargetBranches', () => {
|
|
|
105
106
|
const commits = [
|
|
106
107
|
{
|
|
107
108
|
suggestedTargetBranches: ['7.x'],
|
|
108
|
-
|
|
109
|
+
targetPullRequestStates: [
|
|
109
110
|
{ branch: '7.2', state: 'MERGED' },
|
|
110
111
|
{ branch: '7.1', state: 'OPEN' },
|
|
111
112
|
{ branch: '7.x', state: 'NOT_CREATED' },
|
|
@@ -116,7 +117,7 @@ describe('getTargetBranches', () => {
|
|
|
116
117
|
expect(targetBranches).toEqual(['7.x']);
|
|
117
118
|
});
|
|
118
119
|
});
|
|
119
|
-
describe('when `
|
|
120
|
+
describe('when `targetPullRequestStates` is missing a backport to 7.x', () => {
|
|
120
121
|
let targetBranchChoices;
|
|
121
122
|
beforeEach(async () => {
|
|
122
123
|
const options = {
|
|
@@ -143,6 +144,7 @@ describe('getTargetBranches', () => {
|
|
|
143
144
|
sha: 'my-sha',
|
|
144
145
|
},
|
|
145
146
|
sourcePullRequest: {
|
|
147
|
+
labels: [],
|
|
146
148
|
url: 'foo',
|
|
147
149
|
number: 62286,
|
|
148
150
|
mergeCommit: {
|
|
@@ -152,7 +154,7 @@ describe('getTargetBranches', () => {
|
|
|
152
154
|
},
|
|
153
155
|
sourceBranch: 'master',
|
|
154
156
|
suggestedTargetBranches: ['7.x'],
|
|
155
|
-
|
|
157
|
+
targetPullRequestStates: [],
|
|
156
158
|
},
|
|
157
159
|
];
|
|
158
160
|
await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
package/dist/lib/git.test.js
CHANGED