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.
Files changed (62) hide show
  1. package/dist/backportRun.js +1 -5
  2. package/dist/entrypoint.module.d.ts +2 -2
  3. package/dist/entrypoint.module.js +9 -8
  4. package/dist/entrypoint.module.private.test.js +86 -32
  5. package/dist/lib/BackportError.d.ts +3 -0
  6. package/dist/lib/BackportError.js +2 -0
  7. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +4 -3
  8. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +30 -4
  9. package/dist/lib/getCommits.js +14 -9
  10. package/dist/lib/getCommitsWithoutBackports.js +3 -3
  11. package/dist/lib/getCommitsWithoutBackports.test.js +38 -15
  12. package/dist/lib/getTargetBranches.d.ts +1 -1
  13. package/dist/lib/getTargetBranches.js +6 -10
  14. package/dist/lib/getTargetBranches.test.js +9 -9
  15. package/dist/lib/git.d.ts +2 -2
  16. package/dist/lib/git.js +9 -2
  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/github/v4/validateTargetBranch.d.ts +15 -0
  29. package/dist/lib/github/v4/{validateTargetBranches.js → validateTargetBranch.js} +13 -17
  30. package/dist/lib/github/v4/{validateTargetBranches.private.test.d.ts → validateTargetBranch.private.test.d.ts} +0 -0
  31. package/dist/lib/github/v4/validateTargetBranch.private.test.js +23 -0
  32. package/dist/lib/prompt.test.js +37 -9
  33. package/dist/lib/prompts.js +5 -2
  34. package/dist/lib/setupRepo.js +3 -3
  35. package/dist/lib/sourceCommit/getPullRequestStates.d.ts +27 -0
  36. package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.js → getPullRequestStates.js} +62 -27
  37. package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.test.d.ts → getPullRequestStates.test.d.ts} +0 -0
  38. package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.test.js → getPullRequestStates.test.js} +283 -87
  39. package/dist/lib/sourceCommit/parseSourceCommit.d.ts +4 -2
  40. package/dist/lib/sourceCommit/parseSourceCommit.js +20 -5
  41. package/dist/lib/sourceCommit/parseSourceCommit.test.js +78 -25
  42. package/dist/options/ConfigOptions.d.ts +1 -1
  43. package/dist/options/config/config.d.ts +1 -1
  44. package/dist/options/config/readConfigFile.d.ts +1 -1
  45. package/dist/options/options.d.ts +1 -1
  46. package/dist/runSequentially.js +9 -3
  47. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -2
  48. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +2 -2
  49. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +10 -8
  50. package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.d.ts +1 -0
  51. package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.js +95 -0
  52. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +11 -4
  53. package/dist/test/handleUnbackportedPullRequests.private.test.js +10 -1
  54. package/dist/test/nockHelpers.js +1 -0
  55. package/dist/utils/filterUnmergedCommits.js +1 -1
  56. package/dist/utils/packageVersion.d.ts +1 -1
  57. package/dist/utils/packageVersion.js +1 -1
  58. package/package.json +13 -13
  59. package/yarn.lock +512 -425
  60. package/dist/lib/github/v4/validateTargetBranches.d.ts +0 -9
  61. package/dist/lib/github/v4/validateTargetBranches.private.test.js +0 -51
  62. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
@@ -11,7 +11,6 @@ const getCommits_1 = require("./lib/getCommits");
11
11
  const getTargetBranches_1 = require("./lib/getTargetBranches");
12
12
  const createStatusComment_1 = require("./lib/github/v3/createStatusComment");
13
13
  const apiRequestV4_1 = require("./lib/github/v4/apiRequestV4");
14
- const validateTargetBranches_1 = require("./lib/github/v4/validateTargetBranches");
15
14
  const logger_1 = require("./lib/logger");
16
15
  const ora_1 = require("./lib/ora");
17
16
  const setupRepo_1 = require("./lib/setupRepo");
@@ -52,10 +51,7 @@ async function backportRun({ processArgs, optionsFromModule = {}, exitCodeOnFail
52
51
  }
53
52
  const targetBranches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
54
53
  logger.info('Target branches', targetBranches);
55
- await Promise.all([
56
- (0, setupRepo_1.setupRepo)(options),
57
- (0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches),
58
- ]);
54
+ await (0, setupRepo_1.setupRepo)(options);
59
55
  const results = await (0, runSequentially_1.runSequentially)({
60
56
  options,
61
57
  commits,
@@ -10,7 +10,7 @@ export type { ConfigFileOptions } from './options/ConfigOptions';
10
10
  export { fetchRemoteProjectConfig as getRemoteProjectConfig } from './lib/github/v4/fetchRemoteProjectConfig';
11
11
  export { getGlobalConfig as getLocalGlobalConfig } from './options/config/globalConfig';
12
12
  export declare function backportRun({ options, processArgs, exitCodeOnFailure, }: {
13
- options: ConfigFileOptions;
13
+ options?: ConfigFileOptions;
14
14
  processArgs?: string[];
15
15
  exitCodeOnFailure?: boolean;
16
16
  }): Promise<BackportResponse>;
@@ -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;
@@ -15,7 +15,7 @@ var fetchRemoteProjectConfig_1 = require("./lib/github/v4/fetchRemoteProjectConf
15
15
  Object.defineProperty(exports, "getRemoteProjectConfig", { enumerable: true, get: function () { return fetchRemoteProjectConfig_1.fetchRemoteProjectConfig; } });
16
16
  var globalConfig_1 = require("./options/config/globalConfig");
17
17
  Object.defineProperty(exports, "getLocalGlobalConfig", { enumerable: true, get: function () { return globalConfig_1.getGlobalConfig; } });
18
- function backportRun({ options, processArgs = [], exitCodeOnFailure = true, }) {
18
+ function backportRun({ options = {}, processArgs = [], exitCodeOnFailure = true, }) {
19
19
  return (0, backportRun_1.backportRun)({
20
20
  optionsFromModule: (0, excludeUndefined_1.excludeUndefined)(options),
21
21
  processArgs,
@@ -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
- return [
31
- await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
32
- ...optionsFromGithub,
33
- ...options,
34
- pullNumber: options.pullNumber,
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];
@@ -56,9 +56,13 @@ describe('entrypoint.module', () => {
56
56
  },
57
57
  }));
58
58
  });
59
- it('should correct error code', async () => {
60
- expect(response.status).toBe('failure');
61
- expect(response.error.message).toBe('The branch "--foo" does not exist');
59
+ it('should return handled error', async () => {
60
+ expect(response.status).toBe('success');
61
+ // @ts-expect-error
62
+ expect(response.results[0].error.errorContext).toEqual({
63
+ code: 'invalid-branch-exception',
64
+ branchName: '--foo',
65
+ });
62
66
  });
63
67
  });
64
68
  describe('when missing branches to backport to', () => {
@@ -114,8 +118,14 @@ describe('entrypoint.module', () => {
114
118
  email: 'sorenlouv@gmail.com',
115
119
  name: 'Søren Louv-Jansen',
116
120
  },
117
- expectedTargetPullRequests: [
118
- { branch: '7.x', state: 'NOT_CREATED' },
121
+ suggestedTargetBranches: ['7.x'],
122
+ pullRequestStates: [
123
+ {
124
+ branch: '7.x',
125
+ label: 'backport-to-7.x',
126
+ isSourceBranch: false,
127
+ state: 'NOT_CREATED',
128
+ },
119
129
  ],
120
130
  sourceBranch: 'main',
121
131
  sourceCommit: {
@@ -148,7 +158,13 @@ describe('entrypoint.module', () => {
148
158
  const expectedCommits = [
149
159
  {
150
160
  author: { name: 'Søren Louv-Jansen', email: 'sorenlouv@gmail.com' },
161
+ suggestedTargetBranches: [],
151
162
  sourceCommit: {
163
+ branchLabelMapping: {
164
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
165
+ '^v7.12.0$': '7.x',
166
+ '^v8.0.0$': 'master',
167
+ },
152
168
  committedDate: '2021-01-13T20:01:44Z',
153
169
  message: '[APM] Fix incorrect table column header (95th instead of avg) (#88188)',
154
170
  sha: 'd1b348e6213c5ad48653dfaad6eaf4928b2c688b',
@@ -162,26 +178,28 @@ describe('entrypoint.module', () => {
162
178
  },
163
179
  },
164
180
  sourceBranch: 'master',
165
- expectedTargetPullRequests: [
181
+ pullRequestStates: [
166
182
  {
167
- url: 'https://github.com/elastic/kibana/pull/88288',
168
- number: 88288,
169
- branch: '7.x',
170
- state: 'MERGED',
183
+ branch: '7.11',
184
+ isSourceBranch: false,
185
+ label: 'v7.11.0',
171
186
  mergeCommit: {
172
- sha: '52710be7add6811ec4783c7d383d4159c0aa76f5',
173
- 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>',
187
+ message: '[APM] Fix incorrect table column header (95th instead of avg) (#88188) (#88289)',
188
+ sha: 'b8194e9ec27d69f485d8b194d1cb5e4f6d8fef6d',
174
189
  },
175
- },
176
- {
177
- url: 'https://github.com/elastic/kibana/pull/88289',
178
190
  number: 88289,
179
- branch: '7.11',
180
191
  state: 'MERGED',
192
+ url: 'https://github.com/elastic/kibana/pull/88289',
193
+ },
194
+ {
195
+ branch: '7.x',
181
196
  mergeCommit: {
182
- sha: 'b8194e9ec27d69f485d8b194d1cb5e4f6d8fef6d',
183
- message: '[APM] Fix incorrect table column header (95th instead of avg) (#88188) (#88289)',
197
+ 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>',
198
+ sha: '52710be7add6811ec4783c7d383d4159c0aa76f5',
184
199
  },
200
+ number: 88288,
201
+ state: 'MERGED',
202
+ url: 'https://github.com/elastic/kibana/pull/88288',
185
203
  },
186
204
  ],
187
205
  },
@@ -198,7 +216,13 @@ describe('entrypoint.module', () => {
198
216
  const expectedCommits = [
199
217
  {
200
218
  author: { name: 'Søren Louv-Jansen', email: 'sorenlouv@gmail.com' },
219
+ suggestedTargetBranches: [],
201
220
  sourceCommit: {
221
+ branchLabelMapping: {
222
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
223
+ '^v7.12.0$': '7.x',
224
+ '^v8.0.0$': 'master',
225
+ },
202
226
  committedDate: '2021-01-13T20:01:44Z',
203
227
  message: '[APM] Fix incorrect table column header (95th instead of avg) (#88188)',
204
228
  sha: 'd1b348e6213c5ad48653dfaad6eaf4928b2c688b',
@@ -212,27 +236,29 @@ describe('entrypoint.module', () => {
212
236
  },
213
237
  },
214
238
  sourceBranch: 'master',
215
- expectedTargetPullRequests: [
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
- },
239
+ pullRequestStates: [
226
240
  {
227
241
  url: 'https://github.com/elastic/kibana/pull/88289',
228
242
  number: 88289,
229
243
  branch: '7.11',
244
+ label: 'v7.11.0',
245
+ isSourceBranch: false,
230
246
  state: 'MERGED',
231
247
  mergeCommit: {
232
248
  sha: 'b8194e9ec27d69f485d8b194d1cb5e4f6d8fef6d',
233
249
  message: '[APM] Fix incorrect table column header (95th instead of avg) (#88188) (#88289)',
234
250
  },
235
251
  },
252
+ {
253
+ url: 'https://github.com/elastic/kibana/pull/88288',
254
+ number: 88288,
255
+ branch: '7.x',
256
+ state: 'MERGED',
257
+ mergeCommit: {
258
+ sha: '52710be7add6811ec4783c7d383d4159c0aa76f5',
259
+ 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>',
260
+ },
261
+ },
236
262
  ],
237
263
  },
238
264
  ];
@@ -251,21 +277,25 @@ describe('entrypoint.module', () => {
251
277
  return {
252
278
  ...commit.sourceCommit,
253
279
  message: (0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message),
280
+ branchLabelMapping: undefined,
254
281
  };
255
282
  });
256
283
  expect(commitMessage).toMatchInlineSnapshot(`
257
284
  Array [
258
285
  Object {
286
+ "branchLabelMapping": undefined,
259
287
  "committedDate": "2021-05-28T12:41:42Z",
260
288
  "message": "[Observability] Fix typo in readme for new navigation (#100861)",
261
289
  "sha": "79945fe0275b2ec9c93747e26154110133ec51fb",
262
290
  },
263
291
  Object {
292
+ "branchLabelMapping": undefined,
264
293
  "committedDate": "2021-05-28T19:43:30Z",
265
294
  "message": "[APM] Move APM tutorial from apm_oss to x-pack/apm (#100780)",
266
295
  "sha": "0bcd78b0e999feb95057f5e6eafdb572b9b2fe39",
267
296
  },
268
297
  Object {
298
+ "branchLabelMapping": undefined,
269
299
  "committedDate": "2021-05-18T10:33:16Z",
270
300
  "message": "Migrate from Joi to @kbn/config-schema in \\"home\\" and \\"features\\" plugins (#100201)",
271
301
  "sha": "574f6595ad2e5452fa90e6a3111220a599e473c0",
@@ -289,9 +319,11 @@ describe('entrypoint.module', () => {
289
319
  "email": "sorenlouv@gmail.com",
290
320
  "name": "Søren Louv-Jansen",
291
321
  },
292
- "expectedTargetPullRequests": Array [
322
+ "pullRequestStates": Array [
293
323
  Object {
294
324
  "branch": "7.x",
325
+ "isSourceBranch": false,
326
+ "label": "v7.11.0",
295
327
  "mergeCommit": Object {
296
328
  "message": "[APM] Fix broken link to ML when time range is not set (#85976) (#86227)
297
329
 
@@ -315,6 +347,11 @@ describe('entrypoint.module', () => {
315
347
  ],
316
348
  "sourceBranch": "master",
317
349
  "sourceCommit": Object {
350
+ "branchLabelMapping": Object {
351
+ "^v(\\\\d+).(\\\\d+).\\\\d+$": "$1.$2",
352
+ "^v7.11.0$": "7.x",
353
+ "^v8.0.0$": "master",
354
+ },
318
355
  "committedDate": "2020-12-16T15:17:03Z",
319
356
  "message": "[APM] Fix broken link to ML when time range is not set (#85976)",
320
357
  "sha": "744d6809ded7e1055bfda280c351cee3e8c0e3bf",
@@ -327,15 +364,18 @@ describe('entrypoint.module', () => {
327
364
  "number": 85976,
328
365
  "url": "https://github.com/elastic/kibana/pull/85976",
329
366
  },
367
+ "suggestedTargetBranches": Array [],
330
368
  },
331
369
  Object {
332
370
  "author": Object {
333
371
  "email": "sorenlouv@gmail.com",
334
372
  "name": "Søren Louv-Jansen",
335
373
  },
336
- "expectedTargetPullRequests": Array [
374
+ "pullRequestStates": Array [
337
375
  Object {
338
376
  "branch": "7.x",
377
+ "isSourceBranch": false,
378
+ "label": "v7.11.0",
339
379
  "mergeCommit": Object {
340
380
  "message": "[7.x] [APM] Correlations polish (#85116) (#85940)
341
381
 
@@ -349,6 +389,11 @@ describe('entrypoint.module', () => {
349
389
  ],
350
390
  "sourceBranch": "master",
351
391
  "sourceCommit": Object {
392
+ "branchLabelMapping": Object {
393
+ "^v(\\\\d+).(\\\\d+).\\\\d+$": "$1.$2",
394
+ "^v7.11.0$": "7.x",
395
+ "^v8.0.0$": "master",
396
+ },
352
397
  "committedDate": "2020-12-15T12:15:00Z",
353
398
  "message": "[APM] Correlations polish (#85116)
354
399
 
@@ -365,15 +410,18 @@ describe('entrypoint.module', () => {
365
410
  "number": 85116,
366
411
  "url": "https://github.com/elastic/kibana/pull/85116",
367
412
  },
413
+ "suggestedTargetBranches": Array [],
368
414
  },
369
415
  Object {
370
416
  "author": Object {
371
417
  "email": "sorenlouv@gmail.com",
372
418
  "name": "Søren Louv-Jansen",
373
419
  },
374
- "expectedTargetPullRequests": Array [
420
+ "pullRequestStates": Array [
375
421
  Object {
376
422
  "branch": "7.x",
423
+ "isSourceBranch": false,
424
+ "label": "v7.11.0",
377
425
  "mergeCommit": Object {
378
426
  "message": "[7.x] [APM] Improve pointer event hook (#85117) (#85142)",
379
427
  "sha": "3b72a4f3cc7c0abd0541073e1d0246b85cea3def",
@@ -385,6 +433,11 @@ describe('entrypoint.module', () => {
385
433
  ],
386
434
  "sourceBranch": "master",
387
435
  "sourceCommit": Object {
436
+ "branchLabelMapping": Object {
437
+ "^v(\\\\d+).(\\\\d+).\\\\d+$": "$1.$2",
438
+ "^v7.11.0$": "7.x",
439
+ "^v8.0.0$": "master",
440
+ },
388
441
  "committedDate": "2020-12-07T14:43:58Z",
389
442
  "message": "[APM] Improve pointer event hook (#85117)",
390
443
  "sha": "cee681afb3c5f87371112fab9a7e5dddbafea0a8",
@@ -397,6 +450,7 @@ describe('entrypoint.module', () => {
397
450
  "number": 85117,
398
451
  "url": "https://github.com/elastic/kibana/pull/85117",
399
452
  },
453
+ "suggestedTargetBranches": Array [],
400
454
  },
401
455
  ]
402
456
  `);
@@ -9,6 +9,9 @@ declare type ErrorContext = {
9
9
  } | {
10
10
  code: 'message-only-exception';
11
11
  message: string;
12
+ } | {
13
+ code: 'invalid-branch-exception';
14
+ branchName: string;
12
15
  } | {
13
16
  code: 'no-branches-exception' | 'abort-conflict-resolution-exception';
14
17
  };
@@ -9,6 +9,8 @@ function getMessage(errorContext) {
9
9
  return 'There are no branches to backport to. Aborting.';
10
10
  case 'abort-conflict-resolution-exception':
11
11
  return 'Conflict resolution was aborted by the user';
12
+ case 'invalid-branch-exception':
13
+ return `The branch "${errorContext.branchName}" does not exist`;
12
14
  case 'message-only-exception':
13
15
  return errorContext.message;
14
16
  }
@@ -19,6 +19,7 @@ const addReviewersToPullRequest_1 = require("./github/v3/addReviewersToPullReque
19
19
  const createPullRequest_1 = require("./github/v3/createPullRequest");
20
20
  const enablePullRequestAutoMerge_1 = require("./github/v4/enablePullRequestAutoMerge");
21
21
  const fetchCommitBySha_1 = require("./github/v4/fetchCommits/fetchCommitBySha");
22
+ const validateTargetBranch_1 = require("./github/v4/validateTargetBranch");
22
23
  const logger_1 = require("./logger");
23
24
  const ora_1 = require("./ora");
24
25
  const prompts_1 = require("./prompts");
@@ -33,12 +34,12 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
33
34
  const backportBranch = getBackportBranchName(targetBranch, commits);
34
35
  const repoForkOwner = (0, git_1.getRepoForkOwner)(options);
35
36
  (0, logger_1.consoleLog)(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
36
- const sourceBranch = getSourceBranchFromCommits(commits);
37
+ await (0, validateTargetBranch_1.validateTargetBranch)({ ...options, branchName: targetBranch });
37
38
  const [gitConfigAuthor] = await Promise.all([
38
39
  (0, author_1.getGitConfigAuthor)(options),
39
40
  (0, git_1.createBackportBranch)({
40
41
  options,
41
- sourceBranch,
42
+ sourceBranch: getSourceBranchFromCommits(commits),
42
43
  targetBranch,
43
44
  backportBranch,
44
45
  }),
@@ -143,7 +144,7 @@ async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor)
143
144
  }
144
145
  }
145
146
  async function cherrypickAndHandleConflicts({ options, commit, commitAuthor, targetBranch, cherrypickSpinner, }) {
146
- const mergedTargetPullRequest = commit.expectedTargetPullRequests.find((pr) => pr.state === 'MERGED' && pr.branch === targetBranch);
147
+ const mergedTargetPullRequest = commit.pullRequestStates.find((pr) => pr.state === 'MERGED' && pr.branch === targetBranch);
147
148
  let conflictingFiles;
148
149
  let unstagedFiles;
149
150
  let needsResolving;
@@ -76,6 +76,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
76
76
  sourceBranch: 'myDefaultSourceBranch',
77
77
  sourcePRLabels: [],
78
78
  targetPRLabels: ['backport'],
79
+ githubApiBaseUrlV4: 'http://localhost/graphql',
79
80
  };
80
81
  const commits = [
81
82
  {
@@ -84,7 +85,9 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
84
85
  name: 'Søren Louv-Jansen',
85
86
  },
86
87
  sourceBranch: '7.x',
88
+ suggestedTargetBranches: [],
87
89
  sourceCommit: {
90
+ branchLabelMapping: {},
88
91
  committedDate: 'fff',
89
92
  sha: 'mySha',
90
93
  message: 'My original commit message (#1000)',
@@ -97,7 +100,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
97
100
  message: 'My original commit message (#1000)',
98
101
  },
99
102
  },
100
- expectedTargetPullRequests: [],
103
+ pullRequestStates: [],
101
104
  },
102
105
  {
103
106
  author: {
@@ -105,7 +108,9 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
105
108
  name: 'Søren Louv-Jansen',
106
109
  },
107
110
  sourceBranch: '7.x',
111
+ suggestedTargetBranches: [],
108
112
  sourceCommit: {
113
+ branchLabelMapping: {},
109
114
  committedDate: 'ggg',
110
115
  sha: 'mySha2',
111
116
  message: 'My other commit message (#2000)',
@@ -118,9 +123,14 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
118
123
  message: 'My other commit message (#2000)',
119
124
  },
120
125
  },
121
- expectedTargetPullRequests: [],
126
+ pullRequestStates: [],
122
127
  },
123
128
  ];
129
+ (0, nockHelpers_1.mockGqlRequest)({
130
+ name: 'GetBranchId',
131
+ statusCode: 200,
132
+ body: { data: { repository: { ref: { id: 'foo' } } } },
133
+ });
124
134
  const scope = (0, nock_1.default)('https://api.github.com')
125
135
  .post('/repos/elastic/kibana/pulls')
126
136
  .reply(200, { number: 1337, html_url: 'myHtmlUrl' });
@@ -172,6 +182,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
172
182
  expect(ora_1.default.mock.calls.map((call) => call[0].text))
173
183
  .toMatchInlineSnapshot(`
174
184
  Array [
185
+ "",
175
186
  "Pulling latest changes",
176
187
  "Cherry-picking: My original commit message (#1000)",
177
188
  "Cherry-picking: My other commit message (#2000)",
@@ -199,6 +210,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
199
210
  reviewers: [],
200
211
  sourcePRLabels: [],
201
212
  targetPRLabels: ['backport'],
213
+ githubApiBaseUrlV4: 'http://localhost/graphql',
202
214
  };
203
215
  const commits = [
204
216
  {
@@ -206,15 +218,22 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
206
218
  email: 'soren.louv@elastic.co',
207
219
  name: 'Søren Louv-Jansen',
208
220
  },
221
+ suggestedTargetBranches: [],
209
222
  sourceCommit: {
223
+ branchLabelMapping: {},
210
224
  committedDate: 'hhh',
211
225
  sha: 'mySha',
212
226
  message: 'My original commit message',
213
227
  },
214
228
  sourceBranch: '7.x',
215
- expectedTargetPullRequests: [],
229
+ pullRequestStates: [],
216
230
  },
217
231
  ];
232
+ (0, nockHelpers_1.mockGqlRequest)({
233
+ name: 'GetBranchId',
234
+ statusCode: 200,
235
+ body: { data: { repository: { ref: { id: 'foo' } } } },
236
+ });
218
237
  const scope = (0, nock_1.default)('https://api.github.com')
219
238
  .post('/repos/elastic/kibana/pulls')
220
239
  .reply(200, { number: 1337, html_url: 'myHtmlUrl' });
@@ -270,6 +289,11 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
270
289
  sourcePRLabels: [],
271
290
  targetPRLabels: ['backport'],
272
291
  };
292
+ (0, nockHelpers_1.mockGqlRequest)({
293
+ name: 'GetBranchId',
294
+ statusCode: 200,
295
+ body: { data: { repository: { ref: { id: 'foo' } } } },
296
+ });
273
297
  const scope = (0, nock_1.default)('https://api.github.com')
274
298
  .post('/repos/elastic/kibana/pulls')
275
299
  .reply(200, { number: 1337, html_url: 'myHtmlUrl' });
@@ -282,13 +306,15 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
282
306
  email: 'soren.louv@elastic.co',
283
307
  name: 'Søren Louv-Jansen',
284
308
  },
309
+ suggestedTargetBranches: [],
285
310
  sourceCommit: {
311
+ branchLabelMapping: {},
286
312
  committedDate: '2021-08-18T16:11:38Z',
287
313
  sha: 'mySha',
288
314
  message: 'My original commit message',
289
315
  },
290
316
  sourceBranch: '7.x',
291
- expectedTargetPullRequests: [],
317
+ pullRequestStates: [],
292
318
  },
293
319
  ],
294
320
  targetBranch: '6.x',
@@ -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.map((commit) => commit.sourceCommit.message).join(', ')));
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
- spinner.text = `Loading pull request #${options.pullNumber}`;
35
- const commit = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
36
- ...options,
37
- pullNumber: options.pullNumber, // must extract pullNumber to satisfy the ts gods
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', (0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message)));
41
- return [commit];
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.expectedTargetPullRequests.some((pr) => pr.branch === targetBranch && pr.state !== 'MERGED');
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.expectedTargetPullRequests.map(async (targetPr) => {
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.expectedTargetPullRequests.find((pr) => pr.branch === targetBranch && pr.state === 'OPEN');
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}`;