backport 8.4.3 → 8.5.1

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 (53) hide show
  1. package/dist/entrypoint.module.d.ts +2 -2
  2. package/dist/entrypoint.module.js +9 -8
  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/child-process-promisified.d.ts +1 -1
  7. package/dist/lib/child-process-promisified.js +14 -3
  8. package/dist/lib/getCommits.js +14 -9
  9. package/dist/lib/getCommitsWithoutBackports.js +3 -3
  10. package/dist/lib/getCommitsWithoutBackports.test.js +38 -15
  11. package/dist/lib/getTargetBranches.d.ts +1 -1
  12. package/dist/lib/getTargetBranches.js +6 -10
  13. package/dist/lib/getTargetBranches.test.js +9 -5
  14. package/dist/lib/git.d.ts +2 -2
  15. package/dist/lib/git.js +1 -1
  16. package/dist/lib/git.private.test.js +18 -1
  17. package/dist/lib/git.test.js +3 -1
  18. package/dist/lib/github/v3/createPullRequest.test.js +39 -13
  19. package/dist/lib/github/v3/createStatusComment.js +5 -2
  20. package/dist/lib/github/v3/createStatusComment.test.js +7 -3
  21. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +20 -1
  22. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +32 -10
  23. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +9 -1
  24. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +49 -14
  25. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +15 -5
  26. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +41 -11
  27. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -1
  28. package/dist/lib/prompt.test.js +37 -9
  29. package/dist/lib/prompts.js +5 -2
  30. package/dist/lib/setupRepo.js +3 -3
  31. package/dist/lib/setupRepo.test.js +5 -5
  32. package/dist/lib/sourceCommit/getPullRequestStates.d.ts +27 -0
  33. package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.js → getPullRequestStates.js} +62 -27
  34. package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.test.d.ts → getPullRequestStates.test.d.ts} +0 -0
  35. package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.test.js → getPullRequestStates.test.js} +283 -87
  36. package/dist/lib/sourceCommit/parseSourceCommit.d.ts +4 -2
  37. package/dist/lib/sourceCommit/parseSourceCommit.js +20 -5
  38. package/dist/lib/sourceCommit/parseSourceCommit.test.js +78 -25
  39. package/dist/options/ConfigOptions.d.ts +1 -1
  40. package/dist/options/config/config.d.ts +1 -1
  41. package/dist/options/config/readConfigFile.d.ts +1 -1
  42. package/dist/options/options.d.ts +1 -1
  43. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -2
  44. package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.d.ts +1 -0
  45. package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.js +95 -0
  46. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +11 -4
  47. package/dist/test/handleUnbackportedPullRequests.private.test.js +10 -1
  48. package/dist/utils/filterUnmergedCommits.js +1 -1
  49. package/dist/utils/packageVersion.d.ts +1 -1
  50. package/dist/utils/packageVersion.js +1 -1
  51. package/package.json +13 -13
  52. package/yarn.lock +512 -425
  53. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
@@ -1,30 +1,66 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getExpectedTargetPullRequests = void 0;
3
+ exports.getPullRequestStates = exports.getSourceCommitBranchLabelMapping = void 0;
4
4
  const lodash_1 = require("lodash");
5
5
  const filterEmpty_1 = require("../../utils/filterEmpty");
6
6
  const commitFormatters_1 = require("../github/commitFormatters");
7
7
  const remoteConfig_1 = require("../remoteConfig");
8
- function getExpectedTargetPullRequests({ sourceCommit, latestBranchLabelMapping, }) {
9
- const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
8
+ function getSourcePullRequest(sourceCommit) {
9
+ return sourceCommit.associatedPullRequests.edges?.[0]?.node;
10
+ }
11
+ function getSourceCommitBranchLabelMapping(sourceCommit) {
12
+ const sourcePullRequest = getSourcePullRequest(sourceCommit);
10
13
  const remoteConfig = sourcePullRequest?.mergeCommit.remoteConfigHistory.edges?.[0]?.remoteConfig;
11
- const branchLabelMapping = (remoteConfig && (0, remoteConfig_1.parseRemoteConfig)(remoteConfig)?.branchLabelMapping) ??
12
- latestBranchLabelMapping;
14
+ if (remoteConfig) {
15
+ return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig)?.branchLabelMapping;
16
+ }
17
+ }
18
+ exports.getSourceCommitBranchLabelMapping = getSourceCommitBranchLabelMapping;
19
+ function mergeByKey(obj1, obj2, key) {
20
+ const merged = (0, lodash_1.merge)((0, lodash_1.keyBy)(obj1, key), (0, lodash_1.keyBy)(obj2, key));
21
+ const a = (0, lodash_1.values)(merged);
22
+ return a;
23
+ }
24
+ function getPullRequestStates({ sourceCommit, branchLabelMapping, }) {
25
+ const sourcePullRequest = getSourcePullRequest(sourceCommit);
13
26
  // if there is no source pull request the commit was pushed directly to the source branch
14
27
  // in that case there will be no labels, and thus not possible to deduce the expected target branches
15
28
  if (!sourcePullRequest) {
16
29
  return [];
17
30
  }
18
- const existingTargetPullRequests = getExistingTargetPullRequests(sourceCommit, sourcePullRequest);
19
- // if there's no `branchLabelMapping`, it's not possible to deduce the missing target branches
31
+ const createdTargetPullRequests = getCreatedTargetPullRequests(sourceCommit);
32
+ // if there's no `branchLabelMapping`, it's not possible to determine the missing target branches
20
33
  if (!branchLabelMapping) {
21
- return existingTargetPullRequests;
34
+ return createdTargetPullRequests;
22
35
  }
23
- const missingTargetPullRequests = getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping);
24
- return [...existingTargetPullRequests, ...missingTargetPullRequests];
36
+ const targetBranchesFromLabels = getTargetBranchesFromLabels(sourcePullRequest, branchLabelMapping);
37
+ return mergeByKey(targetBranchesFromLabels, createdTargetPullRequests, 'branch').map((res) => {
38
+ if (res.state) {
39
+ return { ...res, state: res.state };
40
+ }
41
+ // MERGED (source branch)
42
+ if (res.isSourceBranch) {
43
+ return {
44
+ ...res,
45
+ state: 'MERGED',
46
+ url: sourcePullRequest.url,
47
+ number: sourcePullRequest.number,
48
+ mergeCommit: {
49
+ message: sourcePullRequest.mergeCommit.message,
50
+ sha: sourcePullRequest.mergeCommit.sha,
51
+ },
52
+ };
53
+ }
54
+ // NOT_CREATED
55
+ return { ...res, state: 'NOT_CREATED' };
56
+ });
25
57
  }
26
- exports.getExpectedTargetPullRequests = getExpectedTargetPullRequests;
27
- function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
58
+ exports.getPullRequestStates = getPullRequestStates;
59
+ function getCreatedTargetPullRequests(sourceCommit) {
60
+ const sourcePullRequest = getSourcePullRequest(sourceCommit);
61
+ if (!sourcePullRequest) {
62
+ return [];
63
+ }
28
64
  const sourceCommitMessage = (0, commitFormatters_1.getFirstLine)(sourceCommit.message);
29
65
  return sourcePullRequest.timelineItems.edges
30
66
  .filter(filterEmpty_1.filterNil)
@@ -65,26 +101,25 @@ function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
65
101
  };
66
102
  });
67
103
  }
68
- function getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping) {
69
- const labels = sourcePullRequest.labels.nodes.map((label) => label.name);
70
- const targetBranchesFromLabels = labels
71
- .map((label) => getTargetBranchForLabel({ branchLabelMapping, label }))
72
- .filter(filterEmpty_1.filterNil)
73
- .filter((targetBranch) => targetBranch !== sourcePullRequest.baseRefName);
74
- const expectedTargetBranches = existingTargetPullRequests.map((pr) => pr.branch);
75
- const expected = (0, lodash_1.uniq)(targetBranchesFromLabels);
76
- return expected
77
- .filter((targetBranch) => !expectedTargetBranches.includes(targetBranch))
78
- .map((branch) => {
79
- return { branch, state: 'NOT_CREATED' };
80
- });
81
- }
82
104
  // narrow TimelineEdge to TimelinePullRequestEdge
83
105
  function filterPullRequests(item) {
84
106
  const { targetPullRequest } = item.node;
85
107
  return targetPullRequest.__typename === 'PullRequest';
86
108
  }
87
- function getTargetBranchForLabel({ branchLabelMapping, label, }) {
109
+ function getTargetBranchesFromLabels(sourcePullRequest, branchLabelMapping) {
110
+ const targetBranchesFromLabels = sourcePullRequest.labels.nodes
111
+ .map((label) => label.name)
112
+ .map((label) => {
113
+ const branch = getTargetBranchFromLabel({ branchLabelMapping, label });
114
+ if (branch) {
115
+ const isSourceBranch = branch === sourcePullRequest.baseRefName;
116
+ return { branch, label, isSourceBranch };
117
+ }
118
+ })
119
+ .filter(filterEmpty_1.filterNil);
120
+ return (0, lodash_1.uniqBy)(targetBranchesFromLabels, ({ branch }) => branch);
121
+ }
122
+ function getTargetBranchFromLabel({ branchLabelMapping, label, }) {
88
123
  // only get first match
89
124
  const result = Object.entries(branchLabelMapping).find(([labelPattern]) => {
90
125
  const regex = new RegExp(labelPattern);
@@ -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
  });