backport 8.4.4 → 8.5.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.d.ts +1 -1
- package/dist/entrypoint.module.js +8 -7
- package/dist/entrypoint.module.private.test.js +79 -29
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +1 -1
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +12 -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 -5
- package/dist/lib/git.d.ts +2 -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/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/test/e2e/cli/entrypoint.cli.private.test.js +2 -2
- 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/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/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
|
@@ -26,7 +26,7 @@ export declare function getCommits(options: {
|
|
|
26
26
|
maxNumber?: number;
|
|
27
27
|
onlyMissing?: boolean;
|
|
28
28
|
prFilter?: string;
|
|
29
|
-
pullNumber?: number;
|
|
29
|
+
pullNumber?: number | number[];
|
|
30
30
|
sha?: string | string[];
|
|
31
31
|
skipRemoteConfig?: boolean;
|
|
32
32
|
sourceBranch?: string;
|
|
@@ -27,13 +27,14 @@ async function getCommits(options) {
|
|
|
27
27
|
(0, logger_1.initLogger)({ interactive: false, accessToken: options.accessToken });
|
|
28
28
|
const optionsFromGithub = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(options);
|
|
29
29
|
if (options.pullNumber) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
const pullNumbers = Array.isArray(options.pullNumber)
|
|
31
|
+
? options.pullNumber
|
|
32
|
+
: [options.pullNumber];
|
|
33
|
+
return Promise.all(pullNumbers.map((pullNumber) => (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
|
|
34
|
+
...optionsFromGithub,
|
|
35
|
+
...options,
|
|
36
|
+
pullNumber,
|
|
37
|
+
})));
|
|
37
38
|
}
|
|
38
39
|
if (options.sha) {
|
|
39
40
|
const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
|
|
@@ -114,8 +114,14 @@ describe('entrypoint.module', () => {
|
|
|
114
114
|
email: 'sorenlouv@gmail.com',
|
|
115
115
|
name: 'Søren Louv-Jansen',
|
|
116
116
|
},
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
suggestedTargetBranches: ['7.x'],
|
|
118
|
+
pullRequestStates: [
|
|
119
|
+
{
|
|
120
|
+
branch: '7.x',
|
|
121
|
+
label: 'backport-to-7.x',
|
|
122
|
+
isSourceBranch: false,
|
|
123
|
+
state: 'NOT_CREATED',
|
|
124
|
+
},
|
|
119
125
|
],
|
|
120
126
|
sourceBranch: 'main',
|
|
121
127
|
sourceCommit: {
|
|
@@ -148,7 +154,13 @@ describe('entrypoint.module', () => {
|
|
|
148
154
|
const expectedCommits = [
|
|
149
155
|
{
|
|
150
156
|
author: { name: 'Søren Louv-Jansen', email: 'sorenlouv@gmail.com' },
|
|
157
|
+
suggestedTargetBranches: [],
|
|
151
158
|
sourceCommit: {
|
|
159
|
+
branchLabelMapping: {
|
|
160
|
+
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
161
|
+
'^v7.12.0$': '7.x',
|
|
162
|
+
'^v8.0.0$': 'master',
|
|
163
|
+
},
|
|
152
164
|
committedDate: '2021-01-13T20:01:44Z',
|
|
153
165
|
message: '[APM] Fix incorrect table column header (95th instead of avg) (#88188)',
|
|
154
166
|
sha: 'd1b348e6213c5ad48653dfaad6eaf4928b2c688b',
|
|
@@ -162,26 +174,28 @@ describe('entrypoint.module', () => {
|
|
|
162
174
|
},
|
|
163
175
|
},
|
|
164
176
|
sourceBranch: 'master',
|
|
165
|
-
|
|
177
|
+
pullRequestStates: [
|
|
166
178
|
{
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
state: 'MERGED',
|
|
179
|
+
branch: '7.11',
|
|
180
|
+
isSourceBranch: false,
|
|
181
|
+
label: 'v7.11.0',
|
|
171
182
|
mergeCommit: {
|
|
172
|
-
|
|
173
|
-
|
|
183
|
+
message: '[APM] Fix incorrect table column header (95th instead of avg) (#88188) (#88289)',
|
|
184
|
+
sha: 'b8194e9ec27d69f485d8b194d1cb5e4f6d8fef6d',
|
|
174
185
|
},
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
url: 'https://github.com/elastic/kibana/pull/88289',
|
|
178
186
|
number: 88289,
|
|
179
|
-
branch: '7.11',
|
|
180
187
|
state: 'MERGED',
|
|
188
|
+
url: 'https://github.com/elastic/kibana/pull/88289',
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
branch: '7.x',
|
|
181
192
|
mergeCommit: {
|
|
182
|
-
|
|
183
|
-
|
|
193
|
+
message: '[7.x] [APM] Fix incorrect table column header (95th instead of avg) (#88188) (#88288)\n\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>',
|
|
194
|
+
sha: '52710be7add6811ec4783c7d383d4159c0aa76f5',
|
|
184
195
|
},
|
|
196
|
+
number: 88288,
|
|
197
|
+
state: 'MERGED',
|
|
198
|
+
url: 'https://github.com/elastic/kibana/pull/88288',
|
|
185
199
|
},
|
|
186
200
|
],
|
|
187
201
|
},
|
|
@@ -198,7 +212,13 @@ describe('entrypoint.module', () => {
|
|
|
198
212
|
const expectedCommits = [
|
|
199
213
|
{
|
|
200
214
|
author: { name: 'Søren Louv-Jansen', email: 'sorenlouv@gmail.com' },
|
|
215
|
+
suggestedTargetBranches: [],
|
|
201
216
|
sourceCommit: {
|
|
217
|
+
branchLabelMapping: {
|
|
218
|
+
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
219
|
+
'^v7.12.0$': '7.x',
|
|
220
|
+
'^v8.0.0$': 'master',
|
|
221
|
+
},
|
|
202
222
|
committedDate: '2021-01-13T20:01:44Z',
|
|
203
223
|
message: '[APM] Fix incorrect table column header (95th instead of avg) (#88188)',
|
|
204
224
|
sha: 'd1b348e6213c5ad48653dfaad6eaf4928b2c688b',
|
|
@@ -212,27 +232,29 @@ describe('entrypoint.module', () => {
|
|
|
212
232
|
},
|
|
213
233
|
},
|
|
214
234
|
sourceBranch: 'master',
|
|
215
|
-
|
|
216
|
-
{
|
|
217
|
-
url: 'https://github.com/elastic/kibana/pull/88288',
|
|
218
|
-
number: 88288,
|
|
219
|
-
branch: '7.x',
|
|
220
|
-
state: 'MERGED',
|
|
221
|
-
mergeCommit: {
|
|
222
|
-
sha: '52710be7add6811ec4783c7d383d4159c0aa76f5',
|
|
223
|
-
message: '[7.x] [APM] Fix incorrect table column header (95th instead of avg) (#88188) (#88288)\n\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>',
|
|
224
|
-
},
|
|
225
|
-
},
|
|
235
|
+
pullRequestStates: [
|
|
226
236
|
{
|
|
227
237
|
url: 'https://github.com/elastic/kibana/pull/88289',
|
|
228
238
|
number: 88289,
|
|
229
239
|
branch: '7.11',
|
|
240
|
+
label: 'v7.11.0',
|
|
241
|
+
isSourceBranch: false,
|
|
230
242
|
state: 'MERGED',
|
|
231
243
|
mergeCommit: {
|
|
232
244
|
sha: 'b8194e9ec27d69f485d8b194d1cb5e4f6d8fef6d',
|
|
233
245
|
message: '[APM] Fix incorrect table column header (95th instead of avg) (#88188) (#88289)',
|
|
234
246
|
},
|
|
235
247
|
},
|
|
248
|
+
{
|
|
249
|
+
url: 'https://github.com/elastic/kibana/pull/88288',
|
|
250
|
+
number: 88288,
|
|
251
|
+
branch: '7.x',
|
|
252
|
+
state: 'MERGED',
|
|
253
|
+
mergeCommit: {
|
|
254
|
+
sha: '52710be7add6811ec4783c7d383d4159c0aa76f5',
|
|
255
|
+
message: '[7.x] [APM] Fix incorrect table column header (95th instead of avg) (#88188) (#88288)\n\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>',
|
|
256
|
+
},
|
|
257
|
+
},
|
|
236
258
|
],
|
|
237
259
|
},
|
|
238
260
|
];
|
|
@@ -251,21 +273,25 @@ describe('entrypoint.module', () => {
|
|
|
251
273
|
return {
|
|
252
274
|
...commit.sourceCommit,
|
|
253
275
|
message: (0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message),
|
|
276
|
+
branchLabelMapping: undefined,
|
|
254
277
|
};
|
|
255
278
|
});
|
|
256
279
|
expect(commitMessage).toMatchInlineSnapshot(`
|
|
257
280
|
Array [
|
|
258
281
|
Object {
|
|
282
|
+
"branchLabelMapping": undefined,
|
|
259
283
|
"committedDate": "2021-05-28T12:41:42Z",
|
|
260
284
|
"message": "[Observability] Fix typo in readme for new navigation (#100861)",
|
|
261
285
|
"sha": "79945fe0275b2ec9c93747e26154110133ec51fb",
|
|
262
286
|
},
|
|
263
287
|
Object {
|
|
288
|
+
"branchLabelMapping": undefined,
|
|
264
289
|
"committedDate": "2021-05-28T19:43:30Z",
|
|
265
290
|
"message": "[APM] Move APM tutorial from apm_oss to x-pack/apm (#100780)",
|
|
266
291
|
"sha": "0bcd78b0e999feb95057f5e6eafdb572b9b2fe39",
|
|
267
292
|
},
|
|
268
293
|
Object {
|
|
294
|
+
"branchLabelMapping": undefined,
|
|
269
295
|
"committedDate": "2021-05-18T10:33:16Z",
|
|
270
296
|
"message": "Migrate from Joi to @kbn/config-schema in \\"home\\" and \\"features\\" plugins (#100201)",
|
|
271
297
|
"sha": "574f6595ad2e5452fa90e6a3111220a599e473c0",
|
|
@@ -289,9 +315,11 @@ describe('entrypoint.module', () => {
|
|
|
289
315
|
"email": "sorenlouv@gmail.com",
|
|
290
316
|
"name": "Søren Louv-Jansen",
|
|
291
317
|
},
|
|
292
|
-
"
|
|
318
|
+
"pullRequestStates": Array [
|
|
293
319
|
Object {
|
|
294
320
|
"branch": "7.x",
|
|
321
|
+
"isSourceBranch": false,
|
|
322
|
+
"label": "v7.11.0",
|
|
295
323
|
"mergeCommit": Object {
|
|
296
324
|
"message": "[APM] Fix broken link to ML when time range is not set (#85976) (#86227)
|
|
297
325
|
|
|
@@ -315,6 +343,11 @@ describe('entrypoint.module', () => {
|
|
|
315
343
|
],
|
|
316
344
|
"sourceBranch": "master",
|
|
317
345
|
"sourceCommit": Object {
|
|
346
|
+
"branchLabelMapping": Object {
|
|
347
|
+
"^v(\\\\d+).(\\\\d+).\\\\d+$": "$1.$2",
|
|
348
|
+
"^v7.11.0$": "7.x",
|
|
349
|
+
"^v8.0.0$": "master",
|
|
350
|
+
},
|
|
318
351
|
"committedDate": "2020-12-16T15:17:03Z",
|
|
319
352
|
"message": "[APM] Fix broken link to ML when time range is not set (#85976)",
|
|
320
353
|
"sha": "744d6809ded7e1055bfda280c351cee3e8c0e3bf",
|
|
@@ -327,15 +360,18 @@ describe('entrypoint.module', () => {
|
|
|
327
360
|
"number": 85976,
|
|
328
361
|
"url": "https://github.com/elastic/kibana/pull/85976",
|
|
329
362
|
},
|
|
363
|
+
"suggestedTargetBranches": Array [],
|
|
330
364
|
},
|
|
331
365
|
Object {
|
|
332
366
|
"author": Object {
|
|
333
367
|
"email": "sorenlouv@gmail.com",
|
|
334
368
|
"name": "Søren Louv-Jansen",
|
|
335
369
|
},
|
|
336
|
-
"
|
|
370
|
+
"pullRequestStates": Array [
|
|
337
371
|
Object {
|
|
338
372
|
"branch": "7.x",
|
|
373
|
+
"isSourceBranch": false,
|
|
374
|
+
"label": "v7.11.0",
|
|
339
375
|
"mergeCommit": Object {
|
|
340
376
|
"message": "[7.x] [APM] Correlations polish (#85116) (#85940)
|
|
341
377
|
|
|
@@ -349,6 +385,11 @@ describe('entrypoint.module', () => {
|
|
|
349
385
|
],
|
|
350
386
|
"sourceBranch": "master",
|
|
351
387
|
"sourceCommit": Object {
|
|
388
|
+
"branchLabelMapping": Object {
|
|
389
|
+
"^v(\\\\d+).(\\\\d+).\\\\d+$": "$1.$2",
|
|
390
|
+
"^v7.11.0$": "7.x",
|
|
391
|
+
"^v8.0.0$": "master",
|
|
392
|
+
},
|
|
352
393
|
"committedDate": "2020-12-15T12:15:00Z",
|
|
353
394
|
"message": "[APM] Correlations polish (#85116)
|
|
354
395
|
|
|
@@ -365,15 +406,18 @@ describe('entrypoint.module', () => {
|
|
|
365
406
|
"number": 85116,
|
|
366
407
|
"url": "https://github.com/elastic/kibana/pull/85116",
|
|
367
408
|
},
|
|
409
|
+
"suggestedTargetBranches": Array [],
|
|
368
410
|
},
|
|
369
411
|
Object {
|
|
370
412
|
"author": Object {
|
|
371
413
|
"email": "sorenlouv@gmail.com",
|
|
372
414
|
"name": "Søren Louv-Jansen",
|
|
373
415
|
},
|
|
374
|
-
"
|
|
416
|
+
"pullRequestStates": Array [
|
|
375
417
|
Object {
|
|
376
418
|
"branch": "7.x",
|
|
419
|
+
"isSourceBranch": false,
|
|
420
|
+
"label": "v7.11.0",
|
|
377
421
|
"mergeCommit": Object {
|
|
378
422
|
"message": "[7.x] [APM] Improve pointer event hook (#85117) (#85142)",
|
|
379
423
|
"sha": "3b72a4f3cc7c0abd0541073e1d0246b85cea3def",
|
|
@@ -385,6 +429,11 @@ describe('entrypoint.module', () => {
|
|
|
385
429
|
],
|
|
386
430
|
"sourceBranch": "master",
|
|
387
431
|
"sourceCommit": Object {
|
|
432
|
+
"branchLabelMapping": Object {
|
|
433
|
+
"^v(\\\\d+).(\\\\d+).\\\\d+$": "$1.$2",
|
|
434
|
+
"^v7.11.0$": "7.x",
|
|
435
|
+
"^v8.0.0$": "master",
|
|
436
|
+
},
|
|
388
437
|
"committedDate": "2020-12-07T14:43:58Z",
|
|
389
438
|
"message": "[APM] Improve pointer event hook (#85117)",
|
|
390
439
|
"sha": "cee681afb3c5f87371112fab9a7e5dddbafea0a8",
|
|
@@ -397,6 +446,7 @@ describe('entrypoint.module', () => {
|
|
|
397
446
|
"number": 85117,
|
|
398
447
|
"url": "https://github.com/elastic/kibana/pull/85117",
|
|
399
448
|
},
|
|
449
|
+
"suggestedTargetBranches": Array [],
|
|
400
450
|
},
|
|
401
451
|
]
|
|
402
452
|
`);
|
|
@@ -143,7 +143,7 @@ async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor)
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
async function cherrypickAndHandleConflicts({ options, commit, commitAuthor, targetBranch, cherrypickSpinner, }) {
|
|
146
|
-
const mergedTargetPullRequest = commit.
|
|
146
|
+
const mergedTargetPullRequest = commit.pullRequestStates.find((pr) => pr.state === 'MERGED' && pr.branch === targetBranch);
|
|
147
147
|
let conflictingFiles;
|
|
148
148
|
let unstagedFiles;
|
|
149
149
|
let needsResolving;
|
|
@@ -84,7 +84,9 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
84
84
|
name: 'Søren Louv-Jansen',
|
|
85
85
|
},
|
|
86
86
|
sourceBranch: '7.x',
|
|
87
|
+
suggestedTargetBranches: [],
|
|
87
88
|
sourceCommit: {
|
|
89
|
+
branchLabelMapping: {},
|
|
88
90
|
committedDate: 'fff',
|
|
89
91
|
sha: 'mySha',
|
|
90
92
|
message: 'My original commit message (#1000)',
|
|
@@ -97,7 +99,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
97
99
|
message: 'My original commit message (#1000)',
|
|
98
100
|
},
|
|
99
101
|
},
|
|
100
|
-
|
|
102
|
+
pullRequestStates: [],
|
|
101
103
|
},
|
|
102
104
|
{
|
|
103
105
|
author: {
|
|
@@ -105,7 +107,9 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
105
107
|
name: 'Søren Louv-Jansen',
|
|
106
108
|
},
|
|
107
109
|
sourceBranch: '7.x',
|
|
110
|
+
suggestedTargetBranches: [],
|
|
108
111
|
sourceCommit: {
|
|
112
|
+
branchLabelMapping: {},
|
|
109
113
|
committedDate: 'ggg',
|
|
110
114
|
sha: 'mySha2',
|
|
111
115
|
message: 'My other commit message (#2000)',
|
|
@@ -118,7 +122,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
118
122
|
message: 'My other commit message (#2000)',
|
|
119
123
|
},
|
|
120
124
|
},
|
|
121
|
-
|
|
125
|
+
pullRequestStates: [],
|
|
122
126
|
},
|
|
123
127
|
];
|
|
124
128
|
const scope = (0, nock_1.default)('https://api.github.com')
|
|
@@ -206,13 +210,15 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
206
210
|
email: 'soren.louv@elastic.co',
|
|
207
211
|
name: 'Søren Louv-Jansen',
|
|
208
212
|
},
|
|
213
|
+
suggestedTargetBranches: [],
|
|
209
214
|
sourceCommit: {
|
|
215
|
+
branchLabelMapping: {},
|
|
210
216
|
committedDate: 'hhh',
|
|
211
217
|
sha: 'mySha',
|
|
212
218
|
message: 'My original commit message',
|
|
213
219
|
},
|
|
214
220
|
sourceBranch: '7.x',
|
|
215
|
-
|
|
221
|
+
pullRequestStates: [],
|
|
216
222
|
},
|
|
217
223
|
];
|
|
218
224
|
const scope = (0, nock_1.default)('https://api.github.com')
|
|
@@ -282,13 +288,15 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
282
288
|
email: 'soren.louv@elastic.co',
|
|
283
289
|
name: 'Søren Louv-Jansen',
|
|
284
290
|
},
|
|
291
|
+
suggestedTargetBranches: [],
|
|
285
292
|
sourceCommit: {
|
|
293
|
+
branchLabelMapping: {},
|
|
286
294
|
committedDate: '2021-08-18T16:11:38Z',
|
|
287
295
|
sha: 'mySha',
|
|
288
296
|
message: 'My original commit message',
|
|
289
297
|
},
|
|
290
298
|
sourceBranch: '7.x',
|
|
291
|
-
|
|
299
|
+
pullRequestStates: [],
|
|
292
300
|
},
|
|
293
301
|
],
|
|
294
302
|
targetBranch: '6.x',
|
package/dist/lib/getCommits.js
CHANGED
|
@@ -24,21 +24,26 @@ async function getCommits(options) {
|
|
|
24
24
|
try {
|
|
25
25
|
if (options.sha) {
|
|
26
26
|
const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
|
|
27
|
-
// TODO: use Intl.ListFormat to format the sha's
|
|
28
27
|
spinner.text = `Loading commit "${shas.map(commitFormatters_1.getShortSha)}"`;
|
|
29
28
|
const commits = await Promise.all(shas.map((sha) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha })));
|
|
30
|
-
spinner.stopAndPersist(getOraPersistsOption('Select commit', commits
|
|
29
|
+
spinner.stopAndPersist(getOraPersistsOption('Select commit', commits
|
|
30
|
+
.map((commit) => (0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))
|
|
31
|
+
.join(', ')));
|
|
31
32
|
return commits;
|
|
32
33
|
}
|
|
33
34
|
if (options.pullNumber) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const pullNumbers = Array.isArray(options.pullNumber)
|
|
36
|
+
? options.pullNumber
|
|
37
|
+
: [options.pullNumber];
|
|
38
|
+
spinner.text = `Loading pull request #${pullNumbers
|
|
39
|
+
.map((pullNumber) => `#${pullNumber}`)
|
|
40
|
+
.join(', ')}`;
|
|
41
|
+
const commits = await Promise.all(pullNumbers.map((pullNumber) => (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({ ...options, pullNumber })));
|
|
39
42
|
// add styles to make it look like a prompt question
|
|
40
|
-
spinner.stopAndPersist(getOraPersistsOption('Select pull request',
|
|
41
|
-
|
|
43
|
+
spinner.stopAndPersist(getOraPersistsOption('Select pull request', commits
|
|
44
|
+
.map((commit) => (0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))
|
|
45
|
+
.join(', ')));
|
|
46
|
+
return commits;
|
|
42
47
|
}
|
|
43
48
|
if (!options.interactive && !options.ls) {
|
|
44
49
|
throw new BackportError_1.BackportError('When "--interactive" is disabled either `--sha` or `--pr` must be specified');
|
|
@@ -40,12 +40,12 @@ conflictingFiles, }) {
|
|
|
40
40
|
return false;
|
|
41
41
|
}
|
|
42
42
|
// only include commit if it has an unmerged PR for the given target branch
|
|
43
|
-
const hasUnmergedPr = c.
|
|
43
|
+
const hasUnmergedPr = c.pullRequestStates.some((pr) => pr.branch === targetBranch && pr.state !== 'MERGED');
|
|
44
44
|
return hasUnmergedPr;
|
|
45
45
|
})
|
|
46
46
|
.slice(0, 10) // limit to max 10 commits
|
|
47
47
|
.map(async (c) => {
|
|
48
|
-
const results = await Promise.all(c.
|
|
48
|
+
const results = await Promise.all(c.pullRequestStates.map(async (targetPr) => {
|
|
49
49
|
if (!targetPr.mergeCommit) {
|
|
50
50
|
return false;
|
|
51
51
|
}
|
|
@@ -58,7 +58,7 @@ conflictingFiles, }) {
|
|
|
58
58
|
.filter(({ isCommitInBranch }) => !isCommitInBranch)
|
|
59
59
|
.map(({ c }) => {
|
|
60
60
|
// get pull request for the target branch (if it exists)
|
|
61
|
-
const pendingBackportPr = c.
|
|
61
|
+
const pendingBackportPr = c.pullRequestStates.find((pr) => pr.branch === targetBranch && pr.state === 'OPEN');
|
|
62
62
|
const formatted = pendingBackportPr
|
|
63
63
|
? ` - ${(0, commitFormatters_1.getFirstLine)(c.sourceCommit.message)} ${chalk_1.default.gray('(backport pending)')}\n ${pendingBackportPr.url}`
|
|
64
64
|
: ` - ${(0, commitFormatters_1.getFirstLine)(c.sourceCommit.message)} ${chalk_1.default.red('(backport missing)')}\n ${c.sourcePullRequest?.url}`;
|
|
@@ -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[];
|