backport 6.0.0 → 6.1.3

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 (106) hide show
  1. package/README.md +179 -52
  2. package/dist/entrypoint.cli.js +2 -0
  3. package/dist/entrypoint.module.d.ts +16 -4
  4. package/dist/entrypoint.module.js +41 -13
  5. package/dist/entrypoint.module.private.test.d.ts +1 -0
  6. package/dist/entrypoint.module.private.test.js +34 -0
  7. package/dist/main.js +1 -2
  8. package/dist/options/ConfigOptions.d.ts +16 -6
  9. package/dist/options/cliArgs.d.ts +36 -37
  10. package/dist/options/cliArgs.js +25 -24
  11. package/dist/options/cliArgs.test.js +6 -10
  12. package/dist/options/config/config.d.ts +28 -52
  13. package/dist/options/config/config.js +2 -36
  14. package/dist/options/config/config.test.js +10 -27
  15. package/dist/options/config/getOptionsFromGit.d.ts +3 -2
  16. package/dist/options/config/getOptionsFromGit.js +1 -3
  17. package/dist/options/config/globalConfig.js +2 -5
  18. package/dist/options/config/globalConfig.test.js +0 -2
  19. package/dist/options/config/projectConfig.test.js +51 -14
  20. package/dist/options/config/readConfigFile.d.ts +52 -0
  21. package/dist/options/config/readConfigFile.js +28 -2
  22. package/dist/options/options.d.ts +55 -32
  23. package/dist/options/options.js +101 -7
  24. package/dist/options/options.test.js +248 -97
  25. package/dist/options/parseRequiredOptions.d.ts +3 -3
  26. package/dist/options/parseRequiredOptions.js +2 -4
  27. package/dist/options/parseRequiredOptions.test.js +6 -11
  28. package/dist/runSequentially.test.js +40 -78
  29. package/dist/services/git.d.ts +5 -2
  30. package/dist/services/git.js +11 -10
  31. package/dist/services/git.test.js +12 -9
  32. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  33. package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -3
  34. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +4 -5
  35. package/dist/services/github/v3/createPullRequest.js +10 -13
  36. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  37. package/dist/services/github/v3/createPullRequest.test.js +110 -0
  38. package/dist/services/github/v3/createStatusComment.js +12 -14
  39. package/dist/services/github/v3/createStatusComment.test.js +58 -29
  40. package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
  41. package/dist/services/github/v4/apiRequestV4.js +1 -1
  42. package/dist/services/github/v4/enablePullRequestAutoMerge.js +1 -1
  43. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -1
  44. package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
  45. package/dist/services/github/v4/fetchAuthorId.js +5 -6
  46. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
  47. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +8 -1
  48. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  49. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +6 -3
  50. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +8 -1
  51. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -1
  52. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -3
  53. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +12 -1
  54. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +6 -8
  55. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +10 -12
  56. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -7
  57. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
  58. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
  59. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +5 -5
  60. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -6
  61. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -2
  62. package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
  63. package/dist/services/github/v4/fetchProjectConfig.js +56 -0
  64. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
  65. package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
  66. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
  67. package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
  68. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +67 -0
  69. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
  70. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  71. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
  72. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +3 -1
  73. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +22 -1
  74. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +4 -1
  75. package/dist/services/github/v4/getOptionsFromGithub/query.js +3 -0
  76. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +32 -15
  77. package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -1
  78. package/dist/services/sourceCommit/parseSourceCommit.js +2 -2
  79. package/dist/services/sourceCommit/parseSourceCommit.test.js +120 -5
  80. package/dist/test/inquirer.private.test.js +33 -36
  81. package/dist/test/integration/integration.private.test.js +114 -95
  82. package/dist/test/mockConfigFiles.d.ts +5 -0
  83. package/dist/test/mockConfigFiles.js +37 -0
  84. package/dist/test/nockHelpers.d.ts +1 -1
  85. package/dist/test/nockHelpers.js +4 -4
  86. package/dist/test/private/getDevAccessToken.js +1 -1
  87. package/dist/test/setupFiles/automatic-mocks.js +1 -29
  88. package/dist/ui/cherrypickAndCreatePullRequest.test.js +80 -28
  89. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -9
  90. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +13 -48
  91. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +222 -260
  92. package/dist/ui/getCommits.d.ts +1 -1
  93. package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
  94. package/dist/ui/getCommitsWithoutBackports.js +53 -0
  95. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  96. package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
  97. package/dist/ui/getTargetBranches.d.ts +2 -1
  98. package/dist/ui/getTargetBranches.js +17 -1
  99. package/dist/ui/maybeSetupRepo.js +4 -3
  100. package/dist/ui/maybeSetupRepo.test.js +49 -3
  101. package/dist/utils/excludeUndefined.d.ts +6 -0
  102. package/dist/utils/excludeUndefined.js +7 -0
  103. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  104. package/dist/utils/excludeUndefined.test.js +24 -0
  105. package/package.json +9 -8
  106. package/yarn.lock +98 -77
@@ -12,7 +12,7 @@ describe('getExpectedTargetPullRequests', () => {
12
12
  });
13
13
  it('should return empty when there is no associated PR', () => {
14
14
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
15
- sourceCommitMessage: 'identical messages (#1234)',
15
+ sourceCommit: { message: 'identical messages (#1234)' },
16
16
  sourcePullRequest: null,
17
17
  });
18
18
  const branchLabelMapping = {};
@@ -21,7 +21,7 @@ describe('getExpectedTargetPullRequests', () => {
21
21
  });
22
22
  it('should return a result when sourceCommit message matches the commit of the target pull request', () => {
23
23
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
24
- sourceCommitMessage: 'identical messages (#1234)',
24
+ sourceCommit: { message: 'identical messages (#1234)' },
25
25
  sourcePullRequest: { number: 1234 },
26
26
  timelineItems: [
27
27
  {
@@ -45,7 +45,7 @@ describe('getExpectedTargetPullRequests', () => {
45
45
  });
46
46
  it('should return empty when repoName does not match', () => {
47
47
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
48
- sourceCommitMessage: 'identical messages (#1234)',
48
+ sourceCommit: { message: 'identical messages (#1234)' },
49
49
  sourcePullRequest: { number: 1234 },
50
50
  timelineItems: [
51
51
  {
@@ -63,7 +63,7 @@ describe('getExpectedTargetPullRequests', () => {
63
63
  });
64
64
  it('should return empty when repoOwner does not match', () => {
65
65
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
66
- sourceCommitMessage: 'identical messages (#1234)',
66
+ sourceCommit: { message: 'identical messages (#1234)' },
67
67
  sourcePullRequest: { number: 1234 },
68
68
  timelineItems: [
69
69
  {
@@ -81,7 +81,7 @@ describe('getExpectedTargetPullRequests', () => {
81
81
  });
82
82
  it('should return empty when commit messages do not match', () => {
83
83
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
84
- sourceCommitMessage: 'message one (#1234)',
84
+ sourceCommit: { message: 'message one (#1234)' },
85
85
  sourcePullRequest: {
86
86
  number: 1234,
87
87
  },
@@ -100,7 +100,7 @@ describe('getExpectedTargetPullRequests', () => {
100
100
  });
101
101
  it('should return a result if commits messages are different but title includes message and number', () => {
102
102
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
103
- sourceCommitMessage: 'message one (#1234)',
103
+ sourceCommit: { message: 'message one (#1234)' },
104
104
  sourcePullRequest: {
105
105
  number: 1234,
106
106
  },
@@ -127,7 +127,7 @@ describe('getExpectedTargetPullRequests', () => {
127
127
  });
128
128
  it('should return empty when only pull request title (but not pull number) matches', () => {
129
129
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
130
- sourceCommitMessage: 'message one (#1234)',
130
+ sourceCommit: { message: 'message one (#1234)' },
131
131
  sourcePullRequest: {
132
132
  number: 1234,
133
133
  },
@@ -147,7 +147,7 @@ describe('getExpectedTargetPullRequests', () => {
147
147
  });
148
148
  it('should return a result when first line of a multiline commit message matches', () => {
149
149
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
150
- sourceCommitMessage: 'message one (#1234)',
150
+ sourceCommit: { message: 'message one (#1234)' },
151
151
  sourcePullRequest: {
152
152
  number: 1234,
153
153
  },
@@ -173,7 +173,7 @@ describe('getExpectedTargetPullRequests', () => {
173
173
  });
174
174
  it('should return missing target pull requests', () => {
175
175
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
176
- sourceCommitMessage: 'message one (#1234)',
176
+ sourceCommit: { message: 'message one (#1234)' },
177
177
  sourcePullRequest: {
178
178
  number: 1234,
179
179
  labels: ['v7.2.0', 'v7.1.0'],
@@ -192,7 +192,7 @@ describe('getExpectedTargetPullRequests', () => {
192
192
  });
193
193
  it('should not show merged PRs as missing', () => {
194
194
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
195
- sourceCommitMessage: 'identical messages (#1234)',
195
+ sourceCommit: { message: 'identical messages (#1234)' },
196
196
  sourcePullRequest: {
197
197
  number: 1234,
198
198
  labels: ['v7.2.0', 'v7.1.0'],
@@ -229,7 +229,7 @@ describe('getExpectedTargetPullRequests', () => {
229
229
  '^v(\\d+).(\\d+).\\d+$': '$1.$2', // all other branches
230
230
  };
231
231
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
232
- sourceCommitMessage: 'identical messages (#1234)',
232
+ sourceCommit: { message: 'identical messages (#1234)' },
233
233
  sourcePullRequest: {
234
234
  number: 1234,
235
235
  labels: [
@@ -285,13 +285,30 @@ describe('getExpectedTargetPullRequests', () => {
285
285
  { branch: 'master', state: 'MISSING' },
286
286
  ]);
287
287
  });
288
+ it(`should support "backport-to" format`, () => {
289
+ const branchLabelMapping = {
290
+ '^backport-to-(.+)$': '$1',
291
+ };
292
+ const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
293
+ sourceCommit: { message: 'identical messages (#1234)' },
294
+ sourcePullRequest: {
295
+ number: 1234,
296
+ labels: ['backport-to-dev', 'backport-to-v3.1.0'],
297
+ },
298
+ });
299
+ const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)(mockSourceCommit, branchLabelMapping);
300
+ expect(expectedTargetPullRequests).toEqual([
301
+ { branch: 'dev', state: 'MISSING' },
302
+ { branch: 'v3.1.0', state: 'MISSING' },
303
+ ]);
304
+ });
288
305
  it('should only get first match', () => {
289
306
  const branchLabelMapping = {
290
307
  'label-2': 'branch-b',
291
308
  'label-(\\d+)': 'branch-$1',
292
309
  };
293
310
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
294
- sourceCommitMessage: 'identical messages (#1234)',
311
+ sourceCommit: { message: 'identical messages (#1234)' },
295
312
  sourcePullRequest: {
296
313
  number: 1234,
297
314
  labels: ['label-2'],
@@ -307,7 +324,7 @@ describe('getExpectedTargetPullRequests', () => {
307
324
  'label-(\\d+)': 'branch-$1',
308
325
  };
309
326
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
310
- sourceCommitMessage: 'identical messages (#1234)',
327
+ sourceCommit: { message: 'identical messages (#1234)' },
311
328
  sourcePullRequest: {
312
329
  number: 1234,
313
330
  labels: ['label-1', 'label-2', 'label-3', 'label-4'],
@@ -339,7 +356,7 @@ describe('getExpectedTargetPullRequests', () => {
339
356
  'label-(\\d+)': 'branch-$1',
340
357
  };
341
358
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
342
- sourceCommitMessage: 'identical messages (#1234)',
359
+ sourceCommit: { message: 'identical messages (#1234)' },
343
360
  sourcePullRequest: {
344
361
  number: 1234,
345
362
  labels: ['label-1', 'label-2', 'label-3', 'label-4'],
@@ -366,7 +383,7 @@ describe('getExpectedTargetPullRequests', () => {
366
383
  'label-(\\d+)': 'branch-$1',
367
384
  };
368
385
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
369
- sourceCommitMessage: 'identical messages (#1234)',
386
+ sourceCommit: { message: 'identical messages (#1234)' },
370
387
  sourcePullRequest: {
371
388
  number: 1234,
372
389
  labels: ['label-1', 'label-2', 'label-3', 'label-4'],
@@ -69,7 +69,11 @@ export declare type SourceCommitWithTargetPullRequest = InnerCommitNode & {
69
69
  };
70
70
  export declare function parseSourceCommit({ sourceCommit, options, }: {
71
71
  sourceCommit: SourceCommitWithTargetPullRequest;
72
- options: ValidConfigOptions;
72
+ options: {
73
+ branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
74
+ historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
75
+ sourceBranch: string;
76
+ };
73
77
  }): Commit;
74
78
  export declare const sourceCommitWithTargetPullRequestFragment: {
75
79
  name: string;
@@ -86,11 +86,11 @@ exports.sourceCommitWithTargetPullRequestFragment = {
86
86
  }
87
87
  `,
88
88
  };
89
- function getBranchLabelMappingForCommit(sourceCommit, branchLabelMapping, historicalBranchLabelMappings) {
89
+ function getBranchLabelMappingForCommit(sourceCommit, branchLabelMapping, historicalBranchLabelMappings = []) {
90
90
  if ((0, lodash_1.isEmpty)(historicalBranchLabelMappings)) {
91
91
  return branchLabelMapping;
92
92
  }
93
93
  const match = historicalBranchLabelMappings.find((branchLabelMapping) => sourceCommit.committedDate > branchLabelMapping.committedDate);
94
94
  return (match?.branchLabelMapping ??
95
- historicalBranchLabelMappings[0]?.branchLabelMapping);
95
+ historicalBranchLabelMappings[0].branchLabelMapping);
96
96
  }
@@ -6,7 +6,7 @@ describe('parseSourceCommit', () => {
6
6
  describe('pullNumber', () => {
7
7
  it('receives `pullNumber` from the associated pull request', () => {
8
8
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
9
- sourceCommitMessage: 'My commit message (#1234)',
9
+ sourceCommit: { message: 'My commit message (#1234)' },
10
10
  sourcePullRequest: { number: 55 },
11
11
  });
12
12
  const commit = (0, parseSourceCommit_1.parseSourceCommit)({
@@ -17,7 +17,7 @@ describe('parseSourceCommit', () => {
17
17
  });
18
18
  it('extracts `pullNumber` from commit message if it doesnt have any associated PRs', () => {
19
19
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
20
- sourceCommitMessage: 'My commit message (#66)',
20
+ sourceCommit: { message: 'My commit message (#66)' },
21
21
  sourcePullRequest: null,
22
22
  });
23
23
  const commit = (0, parseSourceCommit_1.parseSourceCommit)({
@@ -30,7 +30,7 @@ describe('parseSourceCommit', () => {
30
30
  describe('sourceBranch', () => {
31
31
  it('sets sourceBranch based on `baseRefName` from associated PR', () => {
32
32
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
33
- sourceCommitMessage: 'My commit message (#66)',
33
+ sourceCommit: { message: 'My commit message (#66)' },
34
34
  sourcePullRequest: { number: 55, sourceBranch: 'a sourcebranch' },
35
35
  });
36
36
  const commit = (0, parseSourceCommit_1.parseSourceCommit)({
@@ -41,7 +41,7 @@ describe('parseSourceCommit', () => {
41
41
  });
42
42
  it('sets uses options.sourceBranch as fallback', () => {
43
43
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
44
- sourceCommitMessage: 'My commit message (#66)',
44
+ sourceCommit: { message: 'My commit message (#66)' },
45
45
  sourcePullRequest: null,
46
46
  });
47
47
  const commit = (0, parseSourceCommit_1.parseSourceCommit)({
@@ -53,9 +53,124 @@ describe('parseSourceCommit', () => {
53
53
  expect(commit.sourceBranch).toBe('sourcebranch-from-options');
54
54
  });
55
55
  });
56
+ describe('expectedTargetPullRequests', () => {
57
+ it('uses options.branchLabelMapping when historicalBranchLabelMappings is empty', () => {
58
+ const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
59
+ sourceCommit: {
60
+ message: 'My commit message (#66)',
61
+ commitedDate: '2021-03-03T00:00:00Z',
62
+ },
63
+ sourcePullRequest: {
64
+ sourceBranch: 'main',
65
+ number: 55,
66
+ labels: ['v6.4.0', 'v6.3.0', 'v6.2.0', 'v6.1.0'],
67
+ },
68
+ timelineItems: [
69
+ {
70
+ state: 'MERGED',
71
+ targetBranch: '6.3',
72
+ commitMessages: ['My commit message (#66)'],
73
+ number: 5678,
74
+ },
75
+ {
76
+ state: 'OPEN',
77
+ targetBranch: '6.2',
78
+ commitMessages: ['My commit message (#66)'],
79
+ number: 9876,
80
+ },
81
+ ],
82
+ });
83
+ const commit = (0, parseSourceCommit_1.parseSourceCommit)({
84
+ sourceCommit: mockSourceCommit,
85
+ options: {
86
+ branchLabelMapping: {
87
+ '^v6.4.0$': 'main',
88
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
89
+ },
90
+ historicalBranchLabelMappings: [],
91
+ },
92
+ });
93
+ expect(commit.expectedTargetPullRequests).toEqual([
94
+ {
95
+ branch: '6.3',
96
+ number: 5678,
97
+ state: 'MERGED',
98
+ url: 'https://github.com/elastic/kibana/pull/5678',
99
+ },
100
+ {
101
+ branch: '6.2',
102
+ number: 9876,
103
+ state: 'OPEN',
104
+ url: 'https://github.com/elastic/kibana/pull/9876',
105
+ },
106
+ {
107
+ branch: '6.1',
108
+ state: 'MISSING',
109
+ },
110
+ ]);
111
+ });
112
+ it('uses the historical branchLabelMapping from 2021-02-02', () => {
113
+ const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
114
+ sourceCommit: {
115
+ message: 'My commit message (#66)',
116
+ commitedDate: '2021-03-03T00:00:00Z',
117
+ },
118
+ sourcePullRequest: {
119
+ sourceBranch: 'main',
120
+ number: 55,
121
+ labels: ['v6.3.0', 'v6.2.0', 'v6.1.0'],
122
+ },
123
+ timelineItems: [
124
+ {
125
+ state: 'OPEN',
126
+ targetBranch: '6.2',
127
+ commitMessages: ['My commit message (#66)'],
128
+ number: 9876,
129
+ },
130
+ ],
131
+ });
132
+ const commit = (0, parseSourceCommit_1.parseSourceCommit)({
133
+ sourceCommit: mockSourceCommit,
134
+ options: {
135
+ branchLabelMapping: {
136
+ '^v6.4.0$': 'main',
137
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
138
+ },
139
+ historicalBranchLabelMappings: [
140
+ {
141
+ branchLabelMapping: {
142
+ '^v6.4.0$': 'main',
143
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
144
+ },
145
+ committedDate: '2021-04-04T00:00:00Z',
146
+ },
147
+ {
148
+ branchLabelMapping: {
149
+ '^v6.3.0$': 'main',
150
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
151
+ },
152
+ committedDate: '2021-02-02T00:00:00Z',
153
+ },
154
+ ],
155
+ },
156
+ });
157
+ expect(commit.expectedTargetPullRequests).toEqual([
158
+ {
159
+ branch: '6.2',
160
+ number: 9876,
161
+ state: 'OPEN',
162
+ url: 'https://github.com/elastic/kibana/pull/9876',
163
+ },
164
+ {
165
+ branch: '6.1',
166
+ state: 'MISSING',
167
+ },
168
+ ]);
169
+ });
170
+ });
56
171
  it('returns the correct source commit', () => {
57
172
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
58
- sourceCommitMessage: 'My commit message (#1234)',
173
+ sourceCommit: { message: 'My commit message (#1234)' },
59
174
  sourcePullRequest: {
60
175
  number: 1234,
61
176
  labels: ['v6.3.0', 'v6.2.0', 'v6.1.0'],
@@ -26,47 +26,42 @@ describe('inquirer cli', () => {
26
26
  });
27
27
  it('should return error when branch is missing', async () => {
28
28
  const res = await runBackportAsync([
29
- '--force-local-config',
30
- '--upstream',
31
- 'backport-org/backport-e2e',
32
- '--username',
29
+ '--skip-remote-config',
30
+ '--repo-owner',
31
+ 'backport-org',
32
+ '--repo-name',
33
+ 'backport-e2e',
34
+ '--author',
33
35
  'sqren',
34
36
  '--accessToken',
35
37
  devAccessToken,
36
38
  ]);
37
39
  expect(res).toMatchInlineSnapshot(`
38
- "You must specify a target branch
39
- You can specify it via either:
40
- - Config file (recommended): \\".backportrc.json\\". Read more: https://github.com/sqren/backport/blob/e119d71d6dc03cd061f6ad9b9a8b1cd995f98961/docs/configuration.md#project-config-backportrcjson
41
- - CLI: \\"--branch 6.1\\""
40
+ "Please specify a target branch: \\"--branch 6.1\\".
41
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
42
42
  `);
43
43
  });
44
- it('should return error when upstream is missing', async () => {
44
+ it('should list commits based on .git/config when `repoOwner`/`repoName` is missing', async () => {
45
45
  const res = await runBackportAsync([
46
- '--force-local-config',
46
+ '--skip-remote-config',
47
47
  '--branch',
48
48
  'foo',
49
- '--upstream',
50
- '',
51
- '--username',
52
- 'sqren',
53
49
  '--accessToken',
54
50
  devAccessToken,
55
51
  ]);
56
- expect(res).toMatchInlineSnapshot(`
57
- "You must specify a valid Github repository
58
- You can specify it via either:
59
- - Config file (recommended): \\".backportrc.json\\". Read more: https://github.com/sqren/backport/blob/e119d71d6dc03cd061f6ad9b9a8b1cd995f98961/docs/configuration.md#project-config-backportrcjson
60
- - CLI: \\"--upstream elastic/kibana\\""
61
- `);
52
+ const lineCount = res.split('\n').length;
53
+ expect(lineCount).toBe(11);
54
+ expect(res.includes('Select commit (Use arrow keys)')).toBe(true);
62
55
  });
63
56
  it('should return error when access token is invalid', async () => {
64
57
  const res = await runBackportAsync([
65
58
  '--branch',
66
59
  'foo',
67
- '--upstream',
68
- 'foo/bar',
69
- '--username',
60
+ '--repo-owner',
61
+ 'foo',
62
+ '--repo-name',
63
+ 'bar',
64
+ '--author',
70
65
  'some-user',
71
66
  '--accessToken',
72
67
  'some-token',
@@ -77,9 +72,11 @@ describe('inquirer cli', () => {
77
72
  const res = await runBackportAsync([
78
73
  '--branch',
79
74
  'foo',
80
- '--upstream',
81
- 'foo/bar',
82
- '--username',
75
+ '--repo-owner',
76
+ 'foo',
77
+ '--repo-name',
78
+ 'bar',
79
+ '--author',
83
80
  'sqren',
84
81
  '--accessToken',
85
82
  devAccessToken,
@@ -91,14 +88,14 @@ describe('inquirer cli', () => {
91
88
  const output = await runBackportAsync([
92
89
  '--branch',
93
90
  'foo',
94
- '--upstream',
95
- 'backport-org/backport-e2e',
96
- '--username',
91
+ '--repo-owner',
92
+ 'backport-org',
93
+ '--repo-name',
94
+ 'backport-e2e',
95
+ '--author',
97
96
  'sqren',
98
97
  '--accessToken',
99
98
  devAccessToken,
100
- '--author',
101
- 'sqren',
102
99
  '--max-number',
103
100
  '6',
104
101
  ], { waitForString: 'Select commit' });
@@ -116,14 +113,14 @@ describe('inquirer cli', () => {
116
113
  const output = await runBackportAsync([
117
114
  '--branch',
118
115
  'foo',
119
- '--upstream',
120
- 'backport-org/backport-e2e',
121
- '--username',
116
+ '--repo-owner',
117
+ 'backport-org',
118
+ '--repo-name',
119
+ 'backport-e2e',
120
+ '--author',
122
121
  'sqren',
123
122
  '--accessToken',
124
123
  devAccessToken,
125
- '--author',
126
- 'sqren',
127
124
  '--max-number',
128
125
  '6',
129
126
  '--source-branch',