backport 8.4.4 → 8.5.2
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/backportRun.js +1 -5
- package/dist/entrypoint.module.d.ts +2 -2
- package/dist/entrypoint.module.js +9 -8
- package/dist/entrypoint.module.private.test.js +86 -32
- package/dist/lib/BackportError.d.ts +3 -0
- package/dist/lib/BackportError.js +2 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +4 -3
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +30 -4
- package/dist/lib/getCommits.js +14 -9
- package/dist/lib/getCommitsWithoutBackports.js +3 -3
- package/dist/lib/getCommitsWithoutBackports.test.js +38 -15
- package/dist/lib/getTargetBranches.d.ts +1 -1
- package/dist/lib/getTargetBranches.js +6 -10
- package/dist/lib/getTargetBranches.test.js +9 -9
- package/dist/lib/git.d.ts +2 -2
- package/dist/lib/git.js +9 -2
- package/dist/lib/git.test.js +3 -1
- package/dist/lib/github/v3/createPullRequest.test.js +39 -13
- package/dist/lib/github/v3/createStatusComment.js +5 -2
- package/dist/lib/github/v3/createStatusComment.test.js +7 -3
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +20 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +32 -10
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +9 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +49 -14
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +15 -5
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +41 -11
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -1
- package/dist/lib/github/v4/validateTargetBranch.d.ts +15 -0
- package/dist/lib/github/v4/{validateTargetBranches.js → validateTargetBranch.js} +13 -17
- package/dist/lib/github/v4/{validateTargetBranches.private.test.d.ts → validateTargetBranch.private.test.d.ts} +0 -0
- package/dist/lib/github/v4/validateTargetBranch.private.test.js +23 -0
- package/dist/lib/prompt.test.js +37 -9
- package/dist/lib/prompts.js +5 -2
- package/dist/lib/setupRepo.js +3 -3
- package/dist/lib/sourceCommit/getPullRequestStates.d.ts +27 -0
- package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.js → getPullRequestStates.js} +62 -27
- package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.test.d.ts → getPullRequestStates.test.d.ts} +0 -0
- package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.test.js → getPullRequestStates.test.js} +283 -87
- package/dist/lib/sourceCommit/parseSourceCommit.d.ts +4 -2
- package/dist/lib/sourceCommit/parseSourceCommit.js +20 -5
- package/dist/lib/sourceCommit/parseSourceCommit.test.js +78 -25
- package/dist/options/ConfigOptions.d.ts +1 -1
- package/dist/options/config/config.d.ts +1 -1
- package/dist/options/config/readConfigFile.d.ts +1 -1
- package/dist/options/options.d.ts +1 -1
- package/dist/runSequentially.js +9 -3
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -2
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +2 -2
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +10 -8
- package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.js +95 -0
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +11 -4
- package/dist/test/handleUnbackportedPullRequests.private.test.js +10 -1
- package/dist/test/nockHelpers.js +1 -0
- 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 +13 -13
- package/yarn.lock +512 -425
- package/dist/lib/github/v4/validateTargetBranches.d.ts +0 -9
- package/dist/lib/github/v4/validateTargetBranches.private.test.js +0 -51
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
|
@@ -34,8 +34,8 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
34
34
|
afterEach(() => {
|
|
35
35
|
jest.restoreAllMocks();
|
|
36
36
|
});
|
|
37
|
-
describe('
|
|
38
|
-
function setupExpectedPullRequests({
|
|
37
|
+
describe('pullRequestStates', () => {
|
|
38
|
+
function setupExpectedPullRequests({ pullRequestStates, }) {
|
|
39
39
|
// simulate 1 unbackported commit
|
|
40
40
|
jest
|
|
41
41
|
.spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
|
|
@@ -45,7 +45,9 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
45
45
|
email: 'soren.louv@elastic.co',
|
|
46
46
|
name: 'Søren Louv-Jansen',
|
|
47
47
|
},
|
|
48
|
+
suggestedTargetBranches: [],
|
|
48
49
|
sourceCommit: {
|
|
50
|
+
branchLabelMapping: {},
|
|
49
51
|
committedDate: '10',
|
|
50
52
|
message: 'First commit (#1)',
|
|
51
53
|
sha: 'xyz',
|
|
@@ -58,7 +60,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
58
60
|
sha: 'xyz',
|
|
59
61
|
},
|
|
60
62
|
},
|
|
61
|
-
|
|
63
|
+
pullRequestStates,
|
|
62
64
|
sourceBranch: 'main',
|
|
63
65
|
},
|
|
64
66
|
]);
|
|
@@ -68,12 +70,14 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
68
70
|
options: {},
|
|
69
71
|
commit: {
|
|
70
72
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
73
|
+
suggestedTargetBranches: [],
|
|
71
74
|
sourceCommit: {
|
|
75
|
+
branchLabelMapping: {},
|
|
72
76
|
committedDate: '100',
|
|
73
77
|
message: 'Second commit (#2)',
|
|
74
78
|
sha: 'abc',
|
|
75
79
|
},
|
|
76
|
-
|
|
80
|
+
pullRequestStates: [],
|
|
77
81
|
sourceBranch: 'main',
|
|
78
82
|
},
|
|
79
83
|
targetBranch: '7.x',
|
|
@@ -82,13 +86,13 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
82
86
|
}
|
|
83
87
|
it('should not unbackported commits if no backports were expected', async () => {
|
|
84
88
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
85
|
-
|
|
89
|
+
pullRequestStates: [],
|
|
86
90
|
});
|
|
87
91
|
expect(commitsWithoutBackports.length).toEqual(0);
|
|
88
92
|
});
|
|
89
93
|
it('should display as missing if a backport is CLOSED', async () => {
|
|
90
94
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
91
|
-
|
|
95
|
+
pullRequestStates: [
|
|
92
96
|
{
|
|
93
97
|
state: 'CLOSED',
|
|
94
98
|
branch: '7.x',
|
|
@@ -101,13 +105,20 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
101
105
|
});
|
|
102
106
|
it('should display as missing if a backport is NOT_CREATED', async () => {
|
|
103
107
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
104
|
-
|
|
108
|
+
pullRequestStates: [
|
|
109
|
+
{
|
|
110
|
+
state: 'NOT_CREATED',
|
|
111
|
+
branch: '7.x',
|
|
112
|
+
label: 'v7.0.0',
|
|
113
|
+
isSourceBranch: false,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
105
116
|
});
|
|
106
117
|
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
118
|
});
|
|
108
119
|
it('should display as pending if a backport is OPEN', async () => {
|
|
109
120
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
110
|
-
|
|
121
|
+
pullRequestStates: [
|
|
111
122
|
{
|
|
112
123
|
state: 'OPEN',
|
|
113
124
|
branch: '7.x',
|
|
@@ -120,7 +131,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
120
131
|
});
|
|
121
132
|
it('should not display commit as unbackported if a backport was MERGED', async () => {
|
|
122
133
|
const commitsWithoutBackports = await setupExpectedPullRequests({
|
|
123
|
-
|
|
134
|
+
pullRequestStates: [
|
|
124
135
|
{
|
|
125
136
|
state: 'MERGED',
|
|
126
137
|
branch: '7.x',
|
|
@@ -143,7 +154,9 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
143
154
|
email: 'soren.louv@elastic.co',
|
|
144
155
|
name: 'Søren Louv-Jansen',
|
|
145
156
|
},
|
|
157
|
+
suggestedTargetBranches: [],
|
|
146
158
|
sourceCommit: {
|
|
159
|
+
branchLabelMapping: {},
|
|
147
160
|
committedDate: offendingCommitDate,
|
|
148
161
|
message: 'First commit (#1)',
|
|
149
162
|
sha: 'xyz',
|
|
@@ -157,7 +170,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
157
170
|
},
|
|
158
171
|
},
|
|
159
172
|
sourceBranch: 'main',
|
|
160
|
-
|
|
173
|
+
pullRequestStates: [
|
|
161
174
|
{
|
|
162
175
|
state: 'OPEN',
|
|
163
176
|
branch: '7.x',
|
|
@@ -173,7 +186,9 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
173
186
|
options: {},
|
|
174
187
|
commit: {
|
|
175
188
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
189
|
+
suggestedTargetBranches: [],
|
|
176
190
|
sourceCommit: {
|
|
191
|
+
branchLabelMapping: {},
|
|
177
192
|
committedDate: currentCommitDate,
|
|
178
193
|
message: 'Second commit (#2)',
|
|
179
194
|
sha: 'abc',
|
|
@@ -187,7 +202,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
187
202
|
},
|
|
188
203
|
},
|
|
189
204
|
sourceBranch: 'main',
|
|
190
|
-
|
|
205
|
+
pullRequestStates: [],
|
|
191
206
|
},
|
|
192
207
|
targetBranch: '7.x',
|
|
193
208
|
conflictingFiles: ['/foo/bar/baz.ts'],
|
|
@@ -219,7 +234,9 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
219
234
|
email: 'soren.louv@elastic.co',
|
|
220
235
|
name: 'Søren Louv-Jansen',
|
|
221
236
|
},
|
|
237
|
+
suggestedTargetBranches: [],
|
|
222
238
|
sourceCommit: {
|
|
239
|
+
branchLabelMapping: {},
|
|
223
240
|
committedDate: '10',
|
|
224
241
|
message: 'First commit (#1)',
|
|
225
242
|
sha: 'xyz',
|
|
@@ -233,7 +250,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
233
250
|
},
|
|
234
251
|
},
|
|
235
252
|
sourceBranch: 'main',
|
|
236
|
-
|
|
253
|
+
pullRequestStates: [
|
|
237
254
|
{
|
|
238
255
|
branch: offendingCommitTargetBranch,
|
|
239
256
|
state: 'OPEN',
|
|
@@ -250,7 +267,9 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
250
267
|
// commit that is being backported
|
|
251
268
|
commit: {
|
|
252
269
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
270
|
+
suggestedTargetBranches: [],
|
|
253
271
|
sourceCommit: {
|
|
272
|
+
branchLabelMapping: {},
|
|
254
273
|
committedDate: '100',
|
|
255
274
|
message: 'Second commit (#2)',
|
|
256
275
|
sha: 'abc',
|
|
@@ -263,7 +282,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
263
282
|
sha: 'abc',
|
|
264
283
|
},
|
|
265
284
|
},
|
|
266
|
-
|
|
285
|
+
pullRequestStates: [],
|
|
267
286
|
sourceBranch: 'main',
|
|
268
287
|
},
|
|
269
288
|
targetBranch: currentCommitTargetBranch,
|
|
@@ -295,12 +314,14 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
295
314
|
email: 'soren.louv@elastic.co',
|
|
296
315
|
name: 'Søren Louv-Jansen',
|
|
297
316
|
},
|
|
317
|
+
suggestedTargetBranches: [],
|
|
298
318
|
sourceCommit: {
|
|
319
|
+
branchLabelMapping: {},
|
|
299
320
|
committedDate: '10',
|
|
300
321
|
sha: 'xyz',
|
|
301
322
|
message: 'First commit (#1)',
|
|
302
323
|
},
|
|
303
|
-
|
|
324
|
+
pullRequestStates: [],
|
|
304
325
|
sourceBranch: 'main',
|
|
305
326
|
},
|
|
306
327
|
]);
|
|
@@ -310,7 +331,9 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
310
331
|
options: {},
|
|
311
332
|
commit: {
|
|
312
333
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
334
|
+
suggestedTargetBranches: [],
|
|
313
335
|
sourceCommit: {
|
|
336
|
+
branchLabelMapping: {},
|
|
314
337
|
committedDate: '100',
|
|
315
338
|
message: 'Second commit (#2)',
|
|
316
339
|
sha: 'abc',
|
|
@@ -323,7 +346,7 @@ describe('getCommitsWithoutBackports', () => {
|
|
|
323
346
|
sha: 'abc',
|
|
324
347
|
},
|
|
325
348
|
},
|
|
326
|
-
|
|
349
|
+
pullRequestStates: [],
|
|
327
350
|
sourceBranch: 'main',
|
|
328
351
|
},
|
|
329
352
|
targetBranch: '7.x',
|
|
@@ -2,4 +2,4 @@ import { TargetBranchChoice } from '../options/ConfigOptions';
|
|
|
2
2
|
import { ValidConfigOptions } from '../options/options';
|
|
3
3
|
import { Commit } from './sourceCommit/parseSourceCommit';
|
|
4
4
|
export declare function getTargetBranches(options: ValidConfigOptions, commits: Commit[]): Promise<string[]>;
|
|
5
|
-
export declare function getTargetBranchChoices(options: ValidConfigOptions,
|
|
5
|
+
export declare function getTargetBranchChoices(options: ValidConfigOptions, suggestedTargetBranches: string[], sourceBranch: string): TargetBranchChoice[];
|
|
@@ -10,22 +10,18 @@ async function getTargetBranches(options, commits) {
|
|
|
10
10
|
return options.targetBranches;
|
|
11
11
|
}
|
|
12
12
|
// target branches from the first commit
|
|
13
|
-
const
|
|
14
|
-
? commits[0].expectedTargetPullRequests
|
|
15
|
-
.filter((pr) => pr.state === 'NOT_CREATED' || pr.state === 'CLOSED')
|
|
16
|
-
.map((pr) => pr.branch)
|
|
17
|
-
: [];
|
|
13
|
+
const suggestedTargetBranches = commits.length === 1 ? commits[0].suggestedTargetBranches : [];
|
|
18
14
|
// require target branches to be specified when when in non-interactive mode
|
|
19
15
|
if (!options.interactive) {
|
|
20
|
-
if ((0, lodash_1.isEmpty)(
|
|
16
|
+
if ((0, lodash_1.isEmpty)(suggestedTargetBranches)) {
|
|
21
17
|
throw new BackportError_1.BackportError({ code: 'no-branches-exception' });
|
|
22
18
|
}
|
|
23
|
-
return
|
|
19
|
+
return suggestedTargetBranches;
|
|
24
20
|
}
|
|
25
21
|
// sourceBranch should be the same for all commits, so picking `sourceBranch` from the first commit should be fine 🤞
|
|
26
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.
|
|
27
23
|
const { sourceBranch } = commits[0];
|
|
28
|
-
const targetBranchChoices = getTargetBranchChoices(options,
|
|
24
|
+
const targetBranchChoices = getTargetBranchChoices(options, suggestedTargetBranches, sourceBranch);
|
|
29
25
|
// render prmompt for selecting target branches
|
|
30
26
|
return (0, prompts_1.promptForTargetBranches)({
|
|
31
27
|
targetBranchChoices,
|
|
@@ -33,7 +29,7 @@ async function getTargetBranches(options, commits) {
|
|
|
33
29
|
});
|
|
34
30
|
}
|
|
35
31
|
exports.getTargetBranches = getTargetBranches;
|
|
36
|
-
function getTargetBranchChoices(options,
|
|
32
|
+
function getTargetBranchChoices(options, suggestedTargetBranches, sourceBranch) {
|
|
37
33
|
// exclude sourceBranch from targetBranchChoices
|
|
38
34
|
const targetBranchesChoices = getTargetBranchChoicesAsObject(options.targetBranchChoices).filter((choice) => choice.name !== sourceBranch);
|
|
39
35
|
if ((0, lodash_1.isEmpty)(targetBranchesChoices)) {
|
|
@@ -44,7 +40,7 @@ function getTargetBranchChoices(options, missingTargetBranches, sourceBranch) {
|
|
|
44
40
|
}
|
|
45
41
|
// select missing target branches (based on pull request labels)
|
|
46
42
|
return targetBranchesChoices.map((choice) => {
|
|
47
|
-
const isChecked =
|
|
43
|
+
const isChecked = suggestedTargetBranches.includes(choice.name);
|
|
48
44
|
return { ...choice, checked: isChecked };
|
|
49
45
|
});
|
|
50
46
|
}
|
|
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const getTargetBranches_1 = require("./getTargetBranches");
|
|
27
|
-
const validateTargetBranches = __importStar(require("./github/v4/validateTargetBranches"));
|
|
28
27
|
const prompts = __importStar(require("./prompts"));
|
|
29
28
|
describe('getTargetBranches', () => {
|
|
30
29
|
let promptSpy;
|
|
@@ -47,6 +46,7 @@ describe('getTargetBranches', () => {
|
|
|
47
46
|
{
|
|
48
47
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
49
48
|
sourceCommit: {
|
|
49
|
+
branchLabelMapping: {},
|
|
50
50
|
committedDate: 'aaa',
|
|
51
51
|
message: 'hey',
|
|
52
52
|
sha: 'abcd',
|
|
@@ -60,7 +60,8 @@ describe('getTargetBranches', () => {
|
|
|
60
60
|
},
|
|
61
61
|
},
|
|
62
62
|
sourceBranch: '7.x',
|
|
63
|
-
|
|
63
|
+
suggestedTargetBranches: [],
|
|
64
|
+
pullRequestStates: [],
|
|
64
65
|
},
|
|
65
66
|
];
|
|
66
67
|
branches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
|
@@ -78,9 +79,6 @@ describe('getTargetBranches', () => {
|
|
|
78
79
|
describe('when `options.targetBranches` is not empty', () => {
|
|
79
80
|
let branches;
|
|
80
81
|
beforeEach(async () => {
|
|
81
|
-
jest
|
|
82
|
-
.spyOn(validateTargetBranches, 'validateTargetBranches')
|
|
83
|
-
.mockResolvedValueOnce();
|
|
84
82
|
branches = await (0, getTargetBranches_1.getTargetBranches)({
|
|
85
83
|
targetBranches: ['branchA', 'branchB'],
|
|
86
84
|
targetBranchChoices: [],
|
|
@@ -99,7 +97,6 @@ describe('getTargetBranches', () => {
|
|
|
99
97
|
const commits = [];
|
|
100
98
|
await expect(() => {
|
|
101
99
|
return (0, getTargetBranches_1.getTargetBranches)({
|
|
102
|
-
expectedTargetPullRequests: [],
|
|
103
100
|
interactive: false,
|
|
104
101
|
}, commits);
|
|
105
102
|
}).rejects.toThrowError('There are no branches to backport to. Aborting.');
|
|
@@ -107,7 +104,8 @@ describe('getTargetBranches', () => {
|
|
|
107
104
|
it('should return missing backports', async () => {
|
|
108
105
|
const commits = [
|
|
109
106
|
{
|
|
110
|
-
|
|
107
|
+
suggestedTargetBranches: ['7.x'],
|
|
108
|
+
pullRequestStates: [
|
|
111
109
|
{ branch: '7.2', state: 'MERGED' },
|
|
112
110
|
{ branch: '7.1', state: 'OPEN' },
|
|
113
111
|
{ branch: '7.x', state: 'NOT_CREATED' },
|
|
@@ -118,7 +116,7 @@ describe('getTargetBranches', () => {
|
|
|
118
116
|
expect(targetBranches).toEqual(['7.x']);
|
|
119
117
|
});
|
|
120
118
|
});
|
|
121
|
-
describe('when `
|
|
119
|
+
describe('when `pullRequestStates` is missing a backport to 7.x', () => {
|
|
122
120
|
let targetBranchChoices;
|
|
123
121
|
beforeEach(async () => {
|
|
124
122
|
const options = {
|
|
@@ -139,6 +137,7 @@ describe('getTargetBranches', () => {
|
|
|
139
137
|
{
|
|
140
138
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
141
139
|
sourceCommit: {
|
|
140
|
+
branchLabelMapping: {},
|
|
142
141
|
committedDate: 'bbb',
|
|
143
142
|
message: '[backport] Bump to 5.1.3 (#62286)',
|
|
144
143
|
sha: 'my-sha',
|
|
@@ -152,7 +151,8 @@ describe('getTargetBranches', () => {
|
|
|
152
151
|
},
|
|
153
152
|
},
|
|
154
153
|
sourceBranch: 'master',
|
|
155
|
-
|
|
154
|
+
suggestedTargetBranches: ['7.x'],
|
|
155
|
+
pullRequestStates: [],
|
|
156
156
|
},
|
|
157
157
|
];
|
|
158
158
|
await (0, getTargetBranches_1.getTargetBranches)(options, commits);
|
package/dist/lib/git.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../options/options';
|
|
2
2
|
import { CommitAuthor } from './author';
|
|
3
|
-
import {
|
|
3
|
+
import { TargetPullRequest } from './sourceCommit/getPullRequestStates';
|
|
4
4
|
import { Commit } from './sourceCommit/parseSourceCommit';
|
|
5
5
|
export declare function getRemoteUrl({ repoName, accessToken, gitHostname }: ValidConfigOptions, repoOwner: string): string;
|
|
6
6
|
export declare function cloneRepo({ sourcePath, targetPath }: {
|
|
@@ -32,7 +32,7 @@ export declare function getShasInMergeCommit(options: ValidConfigOptions, sha: s
|
|
|
32
32
|
export declare function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor, }: {
|
|
33
33
|
options: ValidConfigOptions;
|
|
34
34
|
sha: string;
|
|
35
|
-
mergedTargetPullRequest?:
|
|
35
|
+
mergedTargetPullRequest?: TargetPullRequest;
|
|
36
36
|
commitAuthor: CommitAuthor;
|
|
37
37
|
}): Promise<{
|
|
38
38
|
conflictingFiles: {
|
package/dist/lib/git.js
CHANGED
|
@@ -176,8 +176,15 @@ async function fetchBranch(options, branch) {
|
|
|
176
176
|
exports.fetchBranch = fetchBranch;
|
|
177
177
|
async function getIsMergeCommit(options, sha) {
|
|
178
178
|
const cwd = (0, env_1.getRepoPath)(options);
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
try {
|
|
180
|
+
const res = await (0, child_process_promisified_1.spawnPromise)('git', ['rev-list', '-1', '--merges', `${sha}~1..${sha}`], cwd);
|
|
181
|
+
return res.stdout !== '';
|
|
182
|
+
}
|
|
183
|
+
catch (e) {
|
|
184
|
+
const shortSha = (0, commitFormatters_1.getShortSha)(sha);
|
|
185
|
+
logger_1.logger.info(`Could not determine if ${shortSha} is a merge commit. Will assume it is not`, e);
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
181
188
|
}
|
|
182
189
|
exports.getIsMergeCommit = getIsMergeCommit;
|
|
183
190
|
async function getShasInMergeCommit(options, sha) {
|
package/dist/lib/git.test.js
CHANGED
|
@@ -477,13 +477,15 @@ describe('commitChanges', () => {
|
|
|
477
477
|
};
|
|
478
478
|
const commit = {
|
|
479
479
|
author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
|
|
480
|
+
suggestedTargetBranches: [],
|
|
480
481
|
sourceCommit: {
|
|
482
|
+
branchLabelMapping: {},
|
|
481
483
|
message: 'The original commit message',
|
|
482
484
|
committedDate: '2020',
|
|
483
485
|
sha: 'abc',
|
|
484
486
|
},
|
|
485
487
|
sourceBranch: 'master',
|
|
486
|
-
|
|
488
|
+
pullRequestStates: [],
|
|
487
489
|
};
|
|
488
490
|
it('should return when changes committed successfully', async () => {
|
|
489
491
|
jest
|
|
@@ -19,12 +19,14 @@ describe('getPullRequestBody', () => {
|
|
|
19
19
|
message: 'My commit message (#55)',
|
|
20
20
|
},
|
|
21
21
|
},
|
|
22
|
+
suggestedTargetBranches: [],
|
|
22
23
|
sourceCommit: {
|
|
24
|
+
branchLabelMapping: {},
|
|
23
25
|
committedDate: '2020',
|
|
24
26
|
sha: 'abcdefghi',
|
|
25
27
|
message: 'My commit message (#55)',
|
|
26
28
|
},
|
|
27
|
-
|
|
29
|
+
pullRequestStates: [],
|
|
28
30
|
sourceBranch: 'master',
|
|
29
31
|
},
|
|
30
32
|
],
|
|
@@ -50,13 +52,15 @@ describe('getPullRequestBody', () => {
|
|
|
50
52
|
email: 'soren.louv@elastic.co',
|
|
51
53
|
name: 'Søren Louv-Jansen',
|
|
52
54
|
},
|
|
55
|
+
suggestedTargetBranches: [],
|
|
53
56
|
sourceCommit: {
|
|
57
|
+
branchLabelMapping: {},
|
|
54
58
|
committedDate: '',
|
|
55
59
|
sha: 'abcdefghijklmw',
|
|
56
60
|
message: 'My commit message',
|
|
57
61
|
},
|
|
58
62
|
sourceBranch: 'main',
|
|
59
|
-
|
|
63
|
+
pullRequestStates: [],
|
|
60
64
|
},
|
|
61
65
|
],
|
|
62
66
|
targetBranch: '7.x',
|
|
@@ -89,26 +93,30 @@ describe('getPullRequestBody', () => {
|
|
|
89
93
|
message: 'My commit message (#55)',
|
|
90
94
|
},
|
|
91
95
|
},
|
|
96
|
+
suggestedTargetBranches: [],
|
|
92
97
|
sourceCommit: {
|
|
98
|
+
branchLabelMapping: {},
|
|
93
99
|
committedDate: '',
|
|
94
100
|
sha: 'abcdefghijklm',
|
|
95
101
|
message: 'My commit message (#55)',
|
|
96
102
|
},
|
|
97
103
|
sourceBranch: 'main',
|
|
98
|
-
|
|
104
|
+
pullRequestStates: [],
|
|
99
105
|
},
|
|
100
106
|
{
|
|
101
107
|
author: {
|
|
102
108
|
email: 'soren.louv@elastic.co',
|
|
103
109
|
name: 'Søren Louv-Jansen',
|
|
104
110
|
},
|
|
111
|
+
suggestedTargetBranches: [],
|
|
105
112
|
sourceCommit: {
|
|
113
|
+
branchLabelMapping: {},
|
|
106
114
|
committedDate: '',
|
|
107
115
|
sha: 'qwertyuiop',
|
|
108
116
|
message: 'Another commit message',
|
|
109
117
|
},
|
|
110
118
|
sourceBranch: 'main',
|
|
111
|
-
|
|
119
|
+
pullRequestStates: [],
|
|
112
120
|
},
|
|
113
121
|
],
|
|
114
122
|
targetBranch: '7.x',
|
|
@@ -130,7 +138,9 @@ describe('getPullRequestBody', () => {
|
|
|
130
138
|
options: {},
|
|
131
139
|
commits: [
|
|
132
140
|
{
|
|
141
|
+
suggestedTargetBranches: [],
|
|
133
142
|
sourceCommit: {
|
|
143
|
+
branchLabelMapping: {},
|
|
134
144
|
committedDate: '2022-02-07T23:53:14Z',
|
|
135
145
|
message: 'Merge strategy: Second commit',
|
|
136
146
|
sha: 'e8df5eaa4db7b94474b48e2320b02d33a830d9fb',
|
|
@@ -148,10 +158,12 @@ describe('getPullRequestBody', () => {
|
|
|
148
158
|
},
|
|
149
159
|
},
|
|
150
160
|
sourceBranch: 'main',
|
|
151
|
-
|
|
161
|
+
pullRequestStates: [],
|
|
152
162
|
},
|
|
153
163
|
{
|
|
164
|
+
suggestedTargetBranches: [],
|
|
154
165
|
sourceCommit: {
|
|
166
|
+
branchLabelMapping: {},
|
|
155
167
|
committedDate: '2022-02-07T23:51:59Z',
|
|
156
168
|
message: 'Merge strategy: First commit',
|
|
157
169
|
sha: '5411b1c1144093e422220008f23f2c2b909ed113',
|
|
@@ -169,7 +181,7 @@ describe('getPullRequestBody', () => {
|
|
|
169
181
|
},
|
|
170
182
|
},
|
|
171
183
|
sourceBranch: 'main',
|
|
172
|
-
|
|
184
|
+
pullRequestStates: [],
|
|
173
185
|
},
|
|
174
186
|
],
|
|
175
187
|
targetBranch: '7.x',
|
|
@@ -205,26 +217,30 @@ describe('getPullRequestBody', () => {
|
|
|
205
217
|
message: 'My commit message (#55)',
|
|
206
218
|
},
|
|
207
219
|
},
|
|
220
|
+
suggestedTargetBranches: [],
|
|
208
221
|
sourceCommit: {
|
|
222
|
+
branchLabelMapping: {},
|
|
209
223
|
committedDate: '',
|
|
210
224
|
sha: 'abcdefghijklm',
|
|
211
225
|
message: 'My commit message (#55)',
|
|
212
226
|
},
|
|
213
227
|
sourceBranch: 'main',
|
|
214
|
-
|
|
228
|
+
pullRequestStates: [],
|
|
215
229
|
},
|
|
216
230
|
{
|
|
217
231
|
author: {
|
|
218
232
|
email: 'soren.louv@elastic.co',
|
|
219
233
|
name: 'Søren Louv-Jansen',
|
|
220
234
|
},
|
|
235
|
+
suggestedTargetBranches: [],
|
|
221
236
|
sourceCommit: {
|
|
237
|
+
branchLabelMapping: {},
|
|
222
238
|
committedDate: '',
|
|
223
239
|
sha: 'qwertyuiop',
|
|
224
240
|
message: 'Another commit message',
|
|
225
241
|
},
|
|
226
242
|
sourceBranch: 'main',
|
|
227
|
-
|
|
243
|
+
pullRequestStates: [],
|
|
228
244
|
},
|
|
229
245
|
],
|
|
230
246
|
targetBranch: '7.x',
|
|
@@ -253,26 +269,30 @@ describe('getPullRequestBody', () => {
|
|
|
253
269
|
message: 'My commit message (#55)',
|
|
254
270
|
},
|
|
255
271
|
},
|
|
272
|
+
suggestedTargetBranches: [],
|
|
256
273
|
sourceCommit: {
|
|
274
|
+
branchLabelMapping: {},
|
|
257
275
|
committedDate: '',
|
|
258
276
|
sha: 'abcdefghijklm',
|
|
259
277
|
message: 'My commit message (#55)',
|
|
260
278
|
},
|
|
261
279
|
sourceBranch: 'main',
|
|
262
|
-
|
|
280
|
+
pullRequestStates: [],
|
|
263
281
|
},
|
|
264
282
|
{
|
|
265
283
|
author: {
|
|
266
284
|
email: 'soren.louv@elastic.co',
|
|
267
285
|
name: 'Søren Louv-Jansen',
|
|
268
286
|
},
|
|
287
|
+
suggestedTargetBranches: [],
|
|
269
288
|
sourceCommit: {
|
|
289
|
+
branchLabelMapping: {},
|
|
270
290
|
committedDate: '',
|
|
271
291
|
sha: 'qwertyuiop',
|
|
272
292
|
message: 'Another commit message',
|
|
273
293
|
},
|
|
274
294
|
sourceBranch: 'main',
|
|
275
|
-
|
|
295
|
+
pullRequestStates: [],
|
|
276
296
|
},
|
|
277
297
|
],
|
|
278
298
|
targetBranch: '7.x',
|
|
@@ -311,12 +331,14 @@ describe('getTitle', () => {
|
|
|
311
331
|
message: 'My commit message (#55)',
|
|
312
332
|
},
|
|
313
333
|
},
|
|
334
|
+
suggestedTargetBranches: [],
|
|
314
335
|
sourceCommit: {
|
|
336
|
+
branchLabelMapping: {},
|
|
315
337
|
committedDate: '2020',
|
|
316
338
|
sha: 'abcdefghi',
|
|
317
339
|
message: 'My commit message (#55)',
|
|
318
340
|
},
|
|
319
|
-
|
|
341
|
+
pullRequestStates: [],
|
|
320
342
|
},
|
|
321
343
|
{
|
|
322
344
|
author: {
|
|
@@ -331,13 +353,15 @@ describe('getTitle', () => {
|
|
|
331
353
|
message: 'Another commit message (#56)',
|
|
332
354
|
},
|
|
333
355
|
},
|
|
356
|
+
suggestedTargetBranches: [],
|
|
334
357
|
sourceCommit: {
|
|
358
|
+
branchLabelMapping: {},
|
|
335
359
|
committedDate: '2020',
|
|
336
360
|
sha: 'jklmnopqr',
|
|
337
361
|
message: 'Another commit message (#56)',
|
|
338
362
|
},
|
|
339
363
|
sourceBranch: 'main',
|
|
340
|
-
|
|
364
|
+
pullRequestStates: [],
|
|
341
365
|
},
|
|
342
366
|
],
|
|
343
367
|
targetBranch: '7.x',
|
|
@@ -362,13 +386,15 @@ describe('getTitle', () => {
|
|
|
362
386
|
message: 'My commit message (#55)',
|
|
363
387
|
},
|
|
364
388
|
},
|
|
389
|
+
suggestedTargetBranches: [],
|
|
365
390
|
sourceCommit: {
|
|
391
|
+
branchLabelMapping: {},
|
|
366
392
|
committedDate: '',
|
|
367
393
|
sha: 'abcdefghi',
|
|
368
394
|
message: 'My commit message (#55)',
|
|
369
395
|
},
|
|
370
396
|
sourceBranch: 'main',
|
|
371
|
-
|
|
397
|
+
pullRequestStates: [],
|
|
372
398
|
},
|
|
373
399
|
],
|
|
374
400
|
targetBranch: '7.x',
|
|
@@ -100,11 +100,14 @@ ${manualBackportCommand}${questionsAndLinkToBackport}${packageVersionSection}`;
|
|
|
100
100
|
});
|
|
101
101
|
const unmergedBackportsSection = unmergedBackports.length > 0
|
|
102
102
|
? `<br><br>You might need to backport the following PRs to ${result.targetBranch}:<br>${unmergedBackports.join('<br>')}`
|
|
103
|
-
:
|
|
103
|
+
: undefined;
|
|
104
|
+
const backportFailedLabel = 'Backport failed because of merge conflicts';
|
|
104
105
|
return [
|
|
105
106
|
'❌',
|
|
106
107
|
result.targetBranch,
|
|
107
|
-
|
|
108
|
+
unmergedBackportsSection
|
|
109
|
+
? `**${backportFailedLabel}**${unmergedBackportsSection}`
|
|
110
|
+
: backportFailedLabel,
|
|
108
111
|
];
|
|
109
112
|
}
|
|
110
113
|
const message = result.status === 'handled-error'
|
|
@@ -279,12 +279,14 @@ describe('getCommentBody', () => {
|
|
|
279
279
|
message: 'New Zealand commit message',
|
|
280
280
|
},
|
|
281
281
|
},
|
|
282
|
+
suggestedTargetBranches: [],
|
|
282
283
|
sourceCommit: {
|
|
284
|
+
branchLabelMapping: {},
|
|
283
285
|
committedDate: '',
|
|
284
286
|
sha: '',
|
|
285
287
|
message: 'New Zealand commit message',
|
|
286
288
|
},
|
|
287
|
-
|
|
289
|
+
pullRequestStates: [],
|
|
288
290
|
},
|
|
289
291
|
},
|
|
290
292
|
{
|
|
@@ -303,12 +305,14 @@ describe('getCommentBody', () => {
|
|
|
303
305
|
message: 'Australia commit',
|
|
304
306
|
},
|
|
305
307
|
},
|
|
308
|
+
suggestedTargetBranches: [],
|
|
306
309
|
sourceCommit: {
|
|
310
|
+
branchLabelMapping: {},
|
|
307
311
|
committedDate: '',
|
|
308
312
|
sha: '',
|
|
309
313
|
message: 'Australia commit',
|
|
310
314
|
},
|
|
311
|
-
|
|
315
|
+
pullRequestStates: [],
|
|
312
316
|
},
|
|
313
317
|
},
|
|
314
318
|
],
|
|
@@ -335,7 +339,7 @@ describe('getCommentBody', () => {
|
|
|
335
339
|
|:------:|:------:|:------|
|
|
336
340
|
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
337
341
|
|❌|7.1|**Backport failed because of merge conflicts**<br><br>You might need to backport the following PRs to 7.1:<br> - [New Zealand commit message](url-to-pr-5)<br> - [Australia commit](url-to-pr-44)|
|
|
338
|
-
|❌|7.2
|
|
342
|
+
|❌|7.2|Backport failed because of merge conflicts|
|
|
339
343
|
|
|
340
344
|
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
341
345
|
|