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.
Files changed (48) hide show
  1. package/dist/entrypoint.module.d.ts +1 -1
  2. package/dist/entrypoint.module.js +8 -7
  3. package/dist/entrypoint.module.private.test.js +79 -29
  4. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +1 -1
  5. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +12 -4
  6. package/dist/lib/getCommits.js +14 -9
  7. package/dist/lib/getCommitsWithoutBackports.js +3 -3
  8. package/dist/lib/getCommitsWithoutBackports.test.js +38 -15
  9. package/dist/lib/getTargetBranches.d.ts +1 -1
  10. package/dist/lib/getTargetBranches.js +6 -10
  11. package/dist/lib/getTargetBranches.test.js +9 -5
  12. package/dist/lib/git.d.ts +2 -2
  13. package/dist/lib/git.test.js +3 -1
  14. package/dist/lib/github/v3/createPullRequest.test.js +39 -13
  15. package/dist/lib/github/v3/createStatusComment.js +5 -2
  16. package/dist/lib/github/v3/createStatusComment.test.js +7 -3
  17. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +20 -1
  18. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +32 -10
  19. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +9 -1
  20. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +49 -14
  21. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +15 -5
  22. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +41 -11
  23. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -1
  24. package/dist/lib/prompt.test.js +37 -9
  25. package/dist/lib/prompts.js +5 -2
  26. package/dist/lib/setupRepo.js +3 -3
  27. package/dist/lib/sourceCommit/getPullRequestStates.d.ts +27 -0
  28. package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.js → getPullRequestStates.js} +62 -27
  29. package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.test.d.ts → getPullRequestStates.test.d.ts} +0 -0
  30. package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.test.js → getPullRequestStates.test.js} +283 -87
  31. package/dist/lib/sourceCommit/parseSourceCommit.d.ts +4 -2
  32. package/dist/lib/sourceCommit/parseSourceCommit.js +20 -5
  33. package/dist/lib/sourceCommit/parseSourceCommit.test.js +78 -25
  34. package/dist/options/ConfigOptions.d.ts +1 -1
  35. package/dist/options/config/config.d.ts +1 -1
  36. package/dist/options/config/readConfigFile.d.ts +1 -1
  37. package/dist/options/options.d.ts +1 -1
  38. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -2
  39. package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.d.ts +1 -0
  40. package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.js +95 -0
  41. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +11 -4
  42. package/dist/test/handleUnbackportedPullRequests.private.test.js +10 -1
  43. package/dist/utils/filterUnmergedCommits.js +1 -1
  44. package/dist/utils/packageVersion.d.ts +1 -1
  45. package/dist/utils/packageVersion.js +1 -1
  46. package/package.json +13 -13
  47. package/yarn.lock +512 -425
  48. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const nock_1 = __importDefault(require("nock"));
7
- const getExpectedTargetPullRequests_1 = require("./getExpectedTargetPullRequests");
8
7
  const getMockSourceCommit_1 = require("./getMockSourceCommit");
9
- describe('getExpectedTargetPullRequests', () => {
8
+ const getPullRequestStates_1 = require("./getPullRequestStates");
9
+ describe('getPullRequestStates', () => {
10
10
  afterEach(() => {
11
11
  nock_1.default.cleanAll();
12
12
  });
@@ -17,9 +17,9 @@ describe('getExpectedTargetPullRequests', () => {
17
17
  sourceCommit: { message: 'identical messages (#1234)' },
18
18
  sourcePullRequest,
19
19
  });
20
- const expectedTargetPRs = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
20
+ const expectedTargetPRs = (0, getPullRequestStates_1.getPullRequestStates)({
21
21
  sourceCommit: mockSourceCommit,
22
- latestBranchLabelMapping: {},
22
+ branchLabelMapping: {},
23
23
  });
24
24
  expect(expectedTargetPRs).toEqual([]);
25
25
  });
@@ -36,9 +36,9 @@ describe('getExpectedTargetPullRequests', () => {
36
36
  },
37
37
  ],
38
38
  });
39
- const expectedTargetPRs = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
39
+ const expectedTargetPRs = (0, getPullRequestStates_1.getPullRequestStates)({
40
40
  sourceCommit: mockSourceCommit,
41
- latestBranchLabelMapping: {},
41
+ branchLabelMapping: {},
42
42
  });
43
43
  expect(expectedTargetPRs).toEqual([
44
44
  {
@@ -67,11 +67,11 @@ describe('getExpectedTargetPullRequests', () => {
67
67
  },
68
68
  ],
69
69
  });
70
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
70
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
71
71
  sourceCommit: mockSourceCommit,
72
- latestBranchLabelMapping: {},
72
+ branchLabelMapping: {},
73
73
  });
74
- expect(expectedTargetPullRequests).toEqual([]);
74
+ expect(pullRequestStates).toEqual([]);
75
75
  });
76
76
  it('should return empty when repoOwner does not match', () => {
77
77
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
@@ -87,11 +87,11 @@ describe('getExpectedTargetPullRequests', () => {
87
87
  },
88
88
  ],
89
89
  });
90
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
90
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
91
91
  sourceCommit: mockSourceCommit,
92
- latestBranchLabelMapping: {},
92
+ branchLabelMapping: {},
93
93
  });
94
- expect(expectedTargetPullRequests).toEqual([]);
94
+ expect(pullRequestStates).toEqual([]);
95
95
  });
96
96
  it('should return empty when commit messages do not match', () => {
97
97
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
@@ -106,11 +106,11 @@ describe('getExpectedTargetPullRequests', () => {
106
106
  },
107
107
  ],
108
108
  });
109
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
109
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
110
110
  sourceCommit: mockSourceCommit,
111
- latestBranchLabelMapping: {},
111
+ branchLabelMapping: {},
112
112
  });
113
- expect(expectedTargetPullRequests).toEqual([]);
113
+ expect(pullRequestStates).toEqual([]);
114
114
  });
115
115
  it('should return a result if commits messages are different but title includes message and number', () => {
116
116
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
@@ -126,11 +126,11 @@ describe('getExpectedTargetPullRequests', () => {
126
126
  },
127
127
  ],
128
128
  });
129
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
129
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
130
130
  sourceCommit: mockSourceCommit,
131
- latestBranchLabelMapping: {},
131
+ branchLabelMapping: {},
132
132
  });
133
- expect(expectedTargetPullRequests).toEqual([
133
+ expect(pullRequestStates).toEqual([
134
134
  {
135
135
  branch: '6.x',
136
136
  state: 'MERGED',
@@ -157,11 +157,11 @@ describe('getExpectedTargetPullRequests', () => {
157
157
  },
158
158
  ],
159
159
  });
160
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
160
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
161
161
  sourceCommit: mockSourceCommit,
162
- latestBranchLabelMapping: {},
162
+ branchLabelMapping: {},
163
163
  });
164
- expect(expectedTargetPullRequests).toEqual([]);
164
+ expect(pullRequestStates).toEqual([]);
165
165
  });
166
166
  it('should return a result when first line of a multiline commit message matches', () => {
167
167
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
@@ -176,11 +176,11 @@ describe('getExpectedTargetPullRequests', () => {
176
176
  },
177
177
  ],
178
178
  });
179
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
179
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
180
180
  sourceCommit: mockSourceCommit,
181
- latestBranchLabelMapping: {},
181
+ branchLabelMapping: {},
182
182
  });
183
- expect(expectedTargetPullRequests).toEqual([
183
+ expect(pullRequestStates).toEqual([
184
184
  {
185
185
  branch: '6.x',
186
186
  state: 'MERGED',
@@ -206,13 +206,23 @@ describe('getExpectedTargetPullRequests', () => {
206
206
  'v8.0.0': 'master',
207
207
  '^v(\\d+).(\\d+).\\d+$': '$1.$2',
208
208
  };
209
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
209
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
210
210
  sourceCommit: mockSourceCommit,
211
- latestBranchLabelMapping: branchLabelMapping,
211
+ branchLabelMapping,
212
212
  });
213
- expect(expectedTargetPullRequests).toEqual([
214
- { branch: '7.2', state: 'NOT_CREATED' },
215
- { branch: '7.1', state: 'NOT_CREATED' },
213
+ expect(pullRequestStates).toEqual([
214
+ {
215
+ branch: '7.2',
216
+ label: 'v7.2.0',
217
+ isSourceBranch: false,
218
+ state: 'NOT_CREATED',
219
+ },
220
+ {
221
+ branch: '7.1',
222
+ label: 'v7.1.0',
223
+ isSourceBranch: false,
224
+ state: 'NOT_CREATED',
225
+ },
216
226
  ]);
217
227
  });
218
228
  it('should not show merged PRs as missing', () => {
@@ -236,13 +246,15 @@ describe('getExpectedTargetPullRequests', () => {
236
246
  'v8.0.0': 'master',
237
247
  '^v(\\d+).(\\d+).\\d+$': '$1.$2',
238
248
  };
239
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
249
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
240
250
  sourceCommit: mockSourceCommit,
241
- latestBranchLabelMapping: branchLabelMapping,
251
+ branchLabelMapping,
242
252
  });
243
- expect(expectedTargetPullRequests).toEqual([
253
+ expect(pullRequestStates).toEqual([
244
254
  {
245
255
  branch: '7.2',
256
+ label: 'v7.2.0',
257
+ isSourceBranch: false,
246
258
  state: 'MERGED',
247
259
  number: 5678,
248
260
  url: 'https://github.com/elastic/kibana/pull/5678',
@@ -251,7 +263,12 @@ describe('getExpectedTargetPullRequests', () => {
251
263
  sha: 'target-merge-commit-sha',
252
264
  },
253
265
  },
254
- { branch: '7.1', state: 'NOT_CREATED' },
266
+ {
267
+ branch: '7.1',
268
+ label: 'v7.1.0',
269
+ isSourceBranch: false,
270
+ state: 'NOT_CREATED',
271
+ },
255
272
  ]);
256
273
  });
257
274
  it(`should support Kibana's label format`, () => {
@@ -291,33 +308,143 @@ describe('getExpectedTargetPullRequests', () => {
291
308
  ],
292
309
  },
293
310
  });
294
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
311
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
295
312
  sourceCommit: mockSourceCommit,
296
- latestBranchLabelMapping: branchLabelMapping,
297
- });
298
- expect(expectedTargetPullRequests).toEqual([
299
- { branch: '5.4', state: 'NOT_CREATED' },
300
- { branch: '5.5', state: 'NOT_CREATED' },
301
- { branch: '5.6', state: 'NOT_CREATED' },
302
- { branch: '6.0', state: 'NOT_CREATED' },
303
- { branch: '6.1', state: 'NOT_CREATED' },
304
- { branch: '6.2', state: 'NOT_CREATED' },
305
- { branch: '6.3', state: 'NOT_CREATED' },
306
- { branch: '6.4', state: 'NOT_CREATED' },
307
- { branch: '6.5', state: 'NOT_CREATED' },
308
- { branch: '6.6', state: 'NOT_CREATED' },
309
- { branch: '6.7', state: 'NOT_CREATED' },
310
- { branch: '6.8', state: 'NOT_CREATED' },
311
- { branch: '7.0', state: 'NOT_CREATED' },
312
- { branch: '7.1', state: 'NOT_CREATED' },
313
- { branch: '7.2', state: 'NOT_CREATED' },
314
- { branch: '7.3', state: 'NOT_CREATED' },
315
- { branch: '7.4', state: 'NOT_CREATED' },
316
- { branch: '7.5', state: 'NOT_CREATED' },
317
- { branch: '7.6', state: 'NOT_CREATED' },
318
- { branch: '7.7', state: 'NOT_CREATED' },
319
- { branch: '7.x', state: 'NOT_CREATED' },
320
- { branch: 'master', state: 'NOT_CREATED' },
313
+ branchLabelMapping,
314
+ });
315
+ expect(pullRequestStates).toEqual([
316
+ {
317
+ branch: '5.4',
318
+ label: 'v5.4.3',
319
+ isSourceBranch: false,
320
+ state: 'NOT_CREATED',
321
+ },
322
+ {
323
+ branch: '5.5',
324
+ label: 'v5.5.3',
325
+ isSourceBranch: false,
326
+ state: 'NOT_CREATED',
327
+ },
328
+ {
329
+ branch: '5.6',
330
+ label: 'v5.6.16',
331
+ isSourceBranch: false,
332
+ state: 'NOT_CREATED',
333
+ },
334
+ {
335
+ branch: '6.0',
336
+ label: 'v6.0.1',
337
+ isSourceBranch: false,
338
+ state: 'NOT_CREATED',
339
+ },
340
+ {
341
+ branch: '6.1',
342
+ label: 'v6.1.4',
343
+ isSourceBranch: false,
344
+ state: 'NOT_CREATED',
345
+ },
346
+ {
347
+ branch: '6.2',
348
+ label: 'v6.2.5',
349
+ isSourceBranch: false,
350
+ state: 'NOT_CREATED',
351
+ },
352
+ {
353
+ branch: '6.3',
354
+ label: 'v6.3.3',
355
+ isSourceBranch: false,
356
+ state: 'NOT_CREATED',
357
+ },
358
+ {
359
+ branch: '6.4',
360
+ label: 'v6.4.4',
361
+ isSourceBranch: false,
362
+ state: 'NOT_CREATED',
363
+ },
364
+ {
365
+ branch: '6.5',
366
+ label: 'v6.5.5',
367
+ isSourceBranch: false,
368
+ state: 'NOT_CREATED',
369
+ },
370
+ {
371
+ branch: '6.6',
372
+ label: 'v6.6.3',
373
+ isSourceBranch: false,
374
+ state: 'NOT_CREATED',
375
+ },
376
+ {
377
+ branch: '6.7',
378
+ label: 'v6.7.2',
379
+ isSourceBranch: false,
380
+ state: 'NOT_CREATED',
381
+ },
382
+ {
383
+ branch: '6.8',
384
+ label: 'v6.8.4',
385
+ isSourceBranch: false,
386
+ state: 'NOT_CREATED',
387
+ },
388
+ {
389
+ branch: '7.0',
390
+ label: 'v7.0.2',
391
+ isSourceBranch: false,
392
+ state: 'NOT_CREATED',
393
+ },
394
+ {
395
+ branch: '7.1',
396
+ label: 'v7.1.2',
397
+ isSourceBranch: false,
398
+ state: 'NOT_CREATED',
399
+ },
400
+ {
401
+ branch: '7.2',
402
+ label: 'v7.2.2',
403
+ isSourceBranch: false,
404
+ state: 'NOT_CREATED',
405
+ },
406
+ {
407
+ branch: '7.3',
408
+ label: 'v7.3.3',
409
+ isSourceBranch: false,
410
+ state: 'NOT_CREATED',
411
+ },
412
+ {
413
+ branch: '7.4',
414
+ label: 'v7.4.1',
415
+ isSourceBranch: false,
416
+ state: 'NOT_CREATED',
417
+ },
418
+ {
419
+ branch: '7.5',
420
+ label: 'v7.5.0',
421
+ isSourceBranch: false,
422
+ state: 'NOT_CREATED',
423
+ },
424
+ {
425
+ branch: '7.6',
426
+ label: 'v7.6.0',
427
+ isSourceBranch: false,
428
+ state: 'NOT_CREATED',
429
+ },
430
+ {
431
+ branch: '7.7',
432
+ label: 'v7.7.0',
433
+ isSourceBranch: false,
434
+ state: 'NOT_CREATED',
435
+ },
436
+ {
437
+ branch: '7.x',
438
+ label: 'v7.8.0',
439
+ isSourceBranch: false,
440
+ state: 'NOT_CREATED',
441
+ },
442
+ {
443
+ branch: 'master',
444
+ label: 'v8.0.0',
445
+ isSourceBranch: false,
446
+ state: 'NOT_CREATED',
447
+ },
321
448
  ]);
322
449
  });
323
450
  it(`should support "backport-to" format`, () => {
@@ -331,13 +458,23 @@ describe('getExpectedTargetPullRequests', () => {
331
458
  labels: ['backport-to-dev', 'backport-to-v3.1.0'],
332
459
  },
333
460
  });
334
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
461
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
335
462
  sourceCommit: mockSourceCommit,
336
- latestBranchLabelMapping: branchLabelMapping,
463
+ branchLabelMapping,
337
464
  });
338
- expect(expectedTargetPullRequests).toEqual([
339
- { branch: 'dev', state: 'NOT_CREATED' },
340
- { branch: 'v3.1.0', state: 'NOT_CREATED' },
465
+ expect(pullRequestStates).toEqual([
466
+ {
467
+ branch: 'dev',
468
+ label: 'backport-to-dev',
469
+ isSourceBranch: false,
470
+ state: 'NOT_CREATED',
471
+ },
472
+ {
473
+ branch: 'v3.1.0',
474
+ label: 'backport-to-v3.1.0',
475
+ isSourceBranch: false,
476
+ state: 'NOT_CREATED',
477
+ },
341
478
  ]);
342
479
  });
343
480
  it('should only get first match', () => {
@@ -352,12 +489,17 @@ describe('getExpectedTargetPullRequests', () => {
352
489
  labels: ['label-2'],
353
490
  },
354
491
  });
355
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
492
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
356
493
  sourceCommit: mockSourceCommit,
357
- latestBranchLabelMapping: branchLabelMapping,
494
+ branchLabelMapping,
358
495
  });
359
- expect(expectedTargetPullRequests).toEqual([
360
- { branch: 'branch-b', state: 'NOT_CREATED' },
496
+ expect(pullRequestStates).toEqual([
497
+ {
498
+ branch: 'branch-b',
499
+ label: 'label-2',
500
+ isSourceBranch: false,
501
+ state: 'NOT_CREATED',
502
+ },
361
503
  ]);
362
504
  });
363
505
  it('shows open PRs', () => {
@@ -379,20 +521,37 @@ describe('getExpectedTargetPullRequests', () => {
379
521
  },
380
522
  ],
381
523
  });
382
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
524
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
383
525
  sourceCommit: mockSourceCommit,
384
- latestBranchLabelMapping: branchLabelMapping,
526
+ branchLabelMapping,
385
527
  });
386
- expect(expectedTargetPullRequests).toEqual([
528
+ expect(pullRequestStates).toEqual([
529
+ {
530
+ branch: 'branch-1',
531
+ label: 'label-1',
532
+ isSourceBranch: false,
533
+ state: 'NOT_CREATED',
534
+ },
535
+ {
536
+ branch: 'branch-2',
537
+ label: 'label-2',
538
+ isSourceBranch: false,
539
+ state: 'NOT_CREATED',
540
+ },
387
541
  {
388
542
  branch: 'branch-3',
543
+ label: 'label-3',
389
544
  number: 5678,
545
+ isSourceBranch: false,
390
546
  state: 'OPEN',
391
547
  url: 'https://github.com/elastic/kibana/pull/5678',
392
548
  },
393
- { branch: 'branch-1', state: 'NOT_CREATED' },
394
- { branch: 'branch-2', state: 'NOT_CREATED' },
395
- { branch: 'branch-4', state: 'NOT_CREATED' },
549
+ {
550
+ branch: 'branch-4',
551
+ label: 'label-4',
552
+ isSourceBranch: false,
553
+ state: 'NOT_CREATED',
554
+ },
396
555
  ]);
397
556
  });
398
557
  it('ignores closed PRs (treats them as NOT_CREATED)', () => {
@@ -414,15 +573,35 @@ describe('getExpectedTargetPullRequests', () => {
414
573
  },
415
574
  ],
416
575
  });
417
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
576
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
418
577
  sourceCommit: mockSourceCommit,
419
- latestBranchLabelMapping: branchLabelMapping,
578
+ branchLabelMapping,
420
579
  });
421
- expect(expectedTargetPullRequests).toEqual([
422
- { branch: 'branch-1', state: 'NOT_CREATED' },
423
- { branch: 'branch-2', state: 'NOT_CREATED' },
424
- { branch: 'branch-3', state: 'NOT_CREATED' },
425
- { branch: 'branch-4', state: 'NOT_CREATED' },
580
+ expect(pullRequestStates).toEqual([
581
+ {
582
+ branch: 'branch-1',
583
+ label: 'label-1',
584
+ isSourceBranch: false,
585
+ state: 'NOT_CREATED',
586
+ },
587
+ {
588
+ branch: 'branch-2',
589
+ label: 'label-2',
590
+ isSourceBranch: false,
591
+ state: 'NOT_CREATED',
592
+ },
593
+ {
594
+ branch: 'branch-3',
595
+ label: 'label-3',
596
+ isSourceBranch: false,
597
+ state: 'NOT_CREATED',
598
+ },
599
+ {
600
+ branch: 'branch-4',
601
+ label: 'label-4',
602
+ isSourceBranch: false,
603
+ state: 'NOT_CREATED',
604
+ },
426
605
  ]);
427
606
  });
428
607
  it('shows merged PRs', () => {
@@ -444,13 +623,27 @@ describe('getExpectedTargetPullRequests', () => {
444
623
  },
445
624
  ],
446
625
  });
447
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
626
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
448
627
  sourceCommit: mockSourceCommit,
449
- latestBranchLabelMapping: branchLabelMapping,
628
+ branchLabelMapping,
450
629
  });
451
- expect(expectedTargetPullRequests).toEqual([
630
+ expect(pullRequestStates).toEqual([
631
+ {
632
+ branch: 'branch-1',
633
+ label: 'label-1',
634
+ isSourceBranch: false,
635
+ state: 'NOT_CREATED',
636
+ },
637
+ {
638
+ branch: 'branch-2',
639
+ label: 'label-2',
640
+ isSourceBranch: false,
641
+ state: 'NOT_CREATED',
642
+ },
452
643
  {
453
644
  branch: 'branch-3',
645
+ label: 'label-3',
646
+ isSourceBranch: false,
454
647
  number: 5678,
455
648
  state: 'MERGED',
456
649
  url: 'https://github.com/elastic/kibana/pull/5678',
@@ -459,9 +652,12 @@ describe('getExpectedTargetPullRequests', () => {
459
652
  sha: 'target-merge-commit-sha',
460
653
  },
461
654
  },
462
- { branch: 'branch-1', state: 'NOT_CREATED' },
463
- { branch: 'branch-2', state: 'NOT_CREATED' },
464
- { branch: 'branch-4', state: 'NOT_CREATED' },
655
+ {
656
+ branch: 'branch-4',
657
+ label: 'label-4',
658
+ isSourceBranch: false,
659
+ state: 'NOT_CREATED',
660
+ },
465
661
  ]);
466
662
  });
467
663
  });
@@ -1,12 +1,13 @@
1
1
  import { ValidConfigOptions } from '../../options/options';
2
2
  import { RemoteConfigHistory } from '../remoteConfig';
3
- import { ExpectedTargetPullRequest } from './getExpectedTargetPullRequests';
3
+ import { TargetPullRequest } from './getPullRequestStates';
4
4
  export interface Commit {
5
5
  author: SourceCommitWithTargetPullRequest['author'];
6
6
  sourceCommit: {
7
7
  committedDate: string;
8
8
  message: string;
9
9
  sha: string;
10
+ branchLabelMapping: ValidConfigOptions['branchLabelMapping'];
10
11
  };
11
12
  sourcePullRequest?: {
12
13
  number: number;
@@ -17,7 +18,8 @@ export interface Commit {
17
18
  };
18
19
  };
19
20
  sourceBranch: string;
20
- expectedTargetPullRequests: ExpectedTargetPullRequest[];
21
+ suggestedTargetBranches: string[];
22
+ pullRequestStates: TargetPullRequest[];
21
23
  }
22
24
  export interface SourcePullRequestNode {
23
25
  baseRefName: string;
@@ -5,16 +5,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SourceCommitWithTargetPullRequestFragment = exports.parseSourceCommit = void 0;
7
7
  const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const lodash_1 = require("lodash");
8
9
  const remoteConfig_1 = require("../remoteConfig");
9
- const getExpectedTargetPullRequests_1 = require("./getExpectedTargetPullRequests");
10
+ const getPullRequestStates_1 = require("./getPullRequestStates");
11
+ function getSuggestedTargetBranches(sourceCommit, pullRequestStates, branchLabelMapping) {
12
+ const missingPrs = (0, getPullRequestStates_1.getPullRequestStates)({
13
+ sourceCommit,
14
+ branchLabelMapping,
15
+ }).filter((pr) => pr.state === 'NOT_CREATED' || pr.state === 'CLOSED');
16
+ const mergedPrs = pullRequestStates.filter((pr) => pr.state === 'MERGED');
17
+ return (0, lodash_1.differenceBy)(missingPrs, mergedPrs, (pr) => pr.label).map((pr) => pr.branch);
18
+ }
10
19
  function parseSourceCommit({ sourceCommit, options, }) {
11
20
  const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
21
+ const sourceCommitBranchLabelMapping = (0, getPullRequestStates_1.getSourceCommitBranchLabelMapping)(sourceCommit);
22
+ const currentBranchLabelMapping = options.branchLabelMapping;
23
+ const pullRequestStates = (0, getPullRequestStates_1.getPullRequestStates)({
24
+ sourceCommit,
25
+ branchLabelMapping: sourceCommitBranchLabelMapping ?? currentBranchLabelMapping,
26
+ });
27
+ const suggestedTargetBranches = getSuggestedTargetBranches(sourceCommit, pullRequestStates, currentBranchLabelMapping);
12
28
  return {
13
29
  author: sourceCommit.author,
14
30
  sourceCommit: {
15
31
  committedDate: sourceCommit.committedDate,
16
32
  message: sourceCommit.message,
17
33
  sha: sourceCommit.sha,
34
+ branchLabelMapping: sourceCommitBranchLabelMapping,
18
35
  },
19
36
  sourcePullRequest: sourcePullRequest
20
37
  ? {
@@ -27,10 +44,8 @@ function parseSourceCommit({ sourceCommit, options, }) {
27
44
  }
28
45
  : undefined,
29
46
  sourceBranch: sourcePullRequest?.baseRefName ?? options.sourceBranch,
30
- expectedTargetPullRequests: (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
31
- sourceCommit,
32
- latestBranchLabelMapping: options.branchLabelMapping,
33
- }),
47
+ suggestedTargetBranches,
48
+ pullRequestStates,
34
49
  };
35
50
  }
36
51
  exports.parseSourceCommit = parseSourceCommit;