backport 8.4.2 → 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/entrypoint.module.d.ts +1 -1
- package/dist/entrypoint.module.js +8 -7
- package/dist/entrypoint.module.private.test.js +79 -29
- package/dist/lib/author.d.ts +13 -0
- package/dist/lib/author.js +28 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +14 -20
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +14 -4
- package/dist/lib/child-process-promisified.d.ts +1 -1
- package/dist/lib/child-process-promisified.js +14 -3
- package/dist/lib/getCommits.js +14 -9
- package/dist/lib/getCommitsWithoutBackports.js +3 -3
- package/dist/lib/getCommitsWithoutBackports.test.js +38 -15
- package/dist/lib/getTargetBranches.d.ts +1 -1
- package/dist/lib/getTargetBranches.js +6 -10
- package/dist/lib/getTargetBranches.test.js +9 -5
- package/dist/lib/git.d.ts +9 -7
- package/dist/lib/git.js +12 -4
- package/dist/lib/git.private.test.js +21 -4
- package/dist/lib/git.test.js +31 -7
- package/dist/lib/github/v3/createPullRequest.test.js +39 -13
- package/dist/lib/github/v3/createStatusComment.js +5 -2
- package/dist/lib/github/v3/createStatusComment.test.js +7 -3
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +20 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +32 -10
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +9 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +49 -14
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +15 -5
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +41 -11
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -1
- package/dist/lib/prompt.test.js +37 -9
- package/dist/lib/prompts.js +5 -2
- package/dist/lib/setupRepo.js +3 -3
- package/dist/lib/setupRepo.test.js +5 -5
- package/dist/lib/sourceCommit/getPullRequestStates.d.ts +27 -0
- package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.js → getPullRequestStates.js} +62 -27
- package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.test.d.ts → getPullRequestStates.test.d.ts} +0 -0
- package/dist/lib/sourceCommit/{getExpectedTargetPullRequests.test.js → getPullRequestStates.test.js} +283 -87
- package/dist/lib/sourceCommit/parseSourceCommit.d.ts +4 -2
- package/dist/lib/sourceCommit/parseSourceCommit.js +20 -5
- package/dist/lib/sourceCommit/parseSourceCommit.test.js +78 -25
- package/dist/options/ConfigOptions.d.ts +1 -1
- package/dist/options/config/config.d.ts +1 -1
- package/dist/options/config/readConfigFile.d.ts +1 -1
- package/dist/options/options.d.ts +1 -1
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -2
- package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.js +95 -0
- package/dist/test/e2e/cli/runBackportViaCli.js +1 -1
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +11 -4
- package/dist/test/handleUnbackportedPullRequests.private.test.js +10 -1
- package/dist/test/sandbox.d.ts +1 -0
- package/dist/test/sandbox.js +3 -2
- package/dist/utils/filterUnmergedCommits.js +1 -1
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +15 -15
- package/yarn.lock +561 -471
- package/dist/lib/getGitConfigAuthor.d.ts +0 -6
- package/dist/lib/getGitConfigAuthor.js +0 -15
- package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
|
@@ -26,7 +26,7 @@ export declare function getCommits(options: {
|
|
|
26
26
|
maxNumber?: number;
|
|
27
27
|
onlyMissing?: boolean;
|
|
28
28
|
prFilter?: string;
|
|
29
|
-
pullNumber?: number;
|
|
29
|
+
pullNumber?: number | number[];
|
|
30
30
|
sha?: string | string[];
|
|
31
31
|
skipRemoteConfig?: boolean;
|
|
32
32
|
sourceBranch?: string;
|
|
@@ -27,13 +27,14 @@ async function getCommits(options) {
|
|
|
27
27
|
(0, logger_1.initLogger)({ interactive: false, accessToken: options.accessToken });
|
|
28
28
|
const optionsFromGithub = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(options);
|
|
29
29
|
if (options.pullNumber) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
const pullNumbers = Array.isArray(options.pullNumber)
|
|
31
|
+
? options.pullNumber
|
|
32
|
+
: [options.pullNumber];
|
|
33
|
+
return Promise.all(pullNumbers.map((pullNumber) => (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
|
|
34
|
+
...optionsFromGithub,
|
|
35
|
+
...options,
|
|
36
|
+
pullNumber,
|
|
37
|
+
})));
|
|
37
38
|
}
|
|
38
39
|
if (options.sha) {
|
|
39
40
|
const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
|
|
@@ -114,8 +114,14 @@ describe('entrypoint.module', () => {
|
|
|
114
114
|
email: 'sorenlouv@gmail.com',
|
|
115
115
|
name: 'Søren Louv-Jansen',
|
|
116
116
|
},
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
suggestedTargetBranches: ['7.x'],
|
|
118
|
+
pullRequestStates: [
|
|
119
|
+
{
|
|
120
|
+
branch: '7.x',
|
|
121
|
+
label: 'backport-to-7.x',
|
|
122
|
+
isSourceBranch: false,
|
|
123
|
+
state: 'NOT_CREATED',
|
|
124
|
+
},
|
|
119
125
|
],
|
|
120
126
|
sourceBranch: 'main',
|
|
121
127
|
sourceCommit: {
|
|
@@ -148,7 +154,13 @@ describe('entrypoint.module', () => {
|
|
|
148
154
|
const expectedCommits = [
|
|
149
155
|
{
|
|
150
156
|
author: { name: 'Søren Louv-Jansen', email: 'sorenlouv@gmail.com' },
|
|
157
|
+
suggestedTargetBranches: [],
|
|
151
158
|
sourceCommit: {
|
|
159
|
+
branchLabelMapping: {
|
|
160
|
+
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
161
|
+
'^v7.12.0$': '7.x',
|
|
162
|
+
'^v8.0.0$': 'master',
|
|
163
|
+
},
|
|
152
164
|
committedDate: '2021-01-13T20:01:44Z',
|
|
153
165
|
message: '[APM] Fix incorrect table column header (95th instead of avg) (#88188)',
|
|
154
166
|
sha: 'd1b348e6213c5ad48653dfaad6eaf4928b2c688b',
|
|
@@ -162,26 +174,28 @@ describe('entrypoint.module', () => {
|
|
|
162
174
|
},
|
|
163
175
|
},
|
|
164
176
|
sourceBranch: 'master',
|
|
165
|
-
|
|
177
|
+
pullRequestStates: [
|
|
166
178
|
{
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
state: 'MERGED',
|
|
179
|
+
branch: '7.11',
|
|
180
|
+
isSourceBranch: false,
|
|
181
|
+
label: 'v7.11.0',
|
|
171
182
|
mergeCommit: {
|
|
172
|
-
|
|
173
|
-
|
|
183
|
+
message: '[APM] Fix incorrect table column header (95th instead of avg) (#88188) (#88289)',
|
|
184
|
+
sha: 'b8194e9ec27d69f485d8b194d1cb5e4f6d8fef6d',
|
|
174
185
|
},
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
url: 'https://github.com/elastic/kibana/pull/88289',
|
|
178
186
|
number: 88289,
|
|
179
|
-
branch: '7.11',
|
|
180
187
|
state: 'MERGED',
|
|
188
|
+
url: 'https://github.com/elastic/kibana/pull/88289',
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
branch: '7.x',
|
|
181
192
|
mergeCommit: {
|
|
182
|
-
|
|
183
|
-
|
|
193
|
+
message: '[7.x] [APM] Fix incorrect table column header (95th instead of avg) (#88188) (#88288)\n\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>',
|
|
194
|
+
sha: '52710be7add6811ec4783c7d383d4159c0aa76f5',
|
|
184
195
|
},
|
|
196
|
+
number: 88288,
|
|
197
|
+
state: 'MERGED',
|
|
198
|
+
url: 'https://github.com/elastic/kibana/pull/88288',
|
|
185
199
|
},
|
|
186
200
|
],
|
|
187
201
|
},
|
|
@@ -198,7 +212,13 @@ describe('entrypoint.module', () => {
|
|
|
198
212
|
const expectedCommits = [
|
|
199
213
|
{
|
|
200
214
|
author: { name: 'Søren Louv-Jansen', email: 'sorenlouv@gmail.com' },
|
|
215
|
+
suggestedTargetBranches: [],
|
|
201
216
|
sourceCommit: {
|
|
217
|
+
branchLabelMapping: {
|
|
218
|
+
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
219
|
+
'^v7.12.0$': '7.x',
|
|
220
|
+
'^v8.0.0$': 'master',
|
|
221
|
+
},
|
|
202
222
|
committedDate: '2021-01-13T20:01:44Z',
|
|
203
223
|
message: '[APM] Fix incorrect table column header (95th instead of avg) (#88188)',
|
|
204
224
|
sha: 'd1b348e6213c5ad48653dfaad6eaf4928b2c688b',
|
|
@@ -212,27 +232,29 @@ describe('entrypoint.module', () => {
|
|
|
212
232
|
},
|
|
213
233
|
},
|
|
214
234
|
sourceBranch: 'master',
|
|
215
|
-
|
|
216
|
-
{
|
|
217
|
-
url: 'https://github.com/elastic/kibana/pull/88288',
|
|
218
|
-
number: 88288,
|
|
219
|
-
branch: '7.x',
|
|
220
|
-
state: 'MERGED',
|
|
221
|
-
mergeCommit: {
|
|
222
|
-
sha: '52710be7add6811ec4783c7d383d4159c0aa76f5',
|
|
223
|
-
message: '[7.x] [APM] Fix incorrect table column header (95th instead of avg) (#88188) (#88288)\n\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>',
|
|
224
|
-
},
|
|
225
|
-
},
|
|
235
|
+
pullRequestStates: [
|
|
226
236
|
{
|
|
227
237
|
url: 'https://github.com/elastic/kibana/pull/88289',
|
|
228
238
|
number: 88289,
|
|
229
239
|
branch: '7.11',
|
|
240
|
+
label: 'v7.11.0',
|
|
241
|
+
isSourceBranch: false,
|
|
230
242
|
state: 'MERGED',
|
|
231
243
|
mergeCommit: {
|
|
232
244
|
sha: 'b8194e9ec27d69f485d8b194d1cb5e4f6d8fef6d',
|
|
233
245
|
message: '[APM] Fix incorrect table column header (95th instead of avg) (#88188) (#88289)',
|
|
234
246
|
},
|
|
235
247
|
},
|
|
248
|
+
{
|
|
249
|
+
url: 'https://github.com/elastic/kibana/pull/88288',
|
|
250
|
+
number: 88288,
|
|
251
|
+
branch: '7.x',
|
|
252
|
+
state: 'MERGED',
|
|
253
|
+
mergeCommit: {
|
|
254
|
+
sha: '52710be7add6811ec4783c7d383d4159c0aa76f5',
|
|
255
|
+
message: '[7.x] [APM] Fix incorrect table column header (95th instead of avg) (#88188) (#88288)\n\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>',
|
|
256
|
+
},
|
|
257
|
+
},
|
|
236
258
|
],
|
|
237
259
|
},
|
|
238
260
|
];
|
|
@@ -251,21 +273,25 @@ describe('entrypoint.module', () => {
|
|
|
251
273
|
return {
|
|
252
274
|
...commit.sourceCommit,
|
|
253
275
|
message: (0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message),
|
|
276
|
+
branchLabelMapping: undefined,
|
|
254
277
|
};
|
|
255
278
|
});
|
|
256
279
|
expect(commitMessage).toMatchInlineSnapshot(`
|
|
257
280
|
Array [
|
|
258
281
|
Object {
|
|
282
|
+
"branchLabelMapping": undefined,
|
|
259
283
|
"committedDate": "2021-05-28T12:41:42Z",
|
|
260
284
|
"message": "[Observability] Fix typo in readme for new navigation (#100861)",
|
|
261
285
|
"sha": "79945fe0275b2ec9c93747e26154110133ec51fb",
|
|
262
286
|
},
|
|
263
287
|
Object {
|
|
288
|
+
"branchLabelMapping": undefined,
|
|
264
289
|
"committedDate": "2021-05-28T19:43:30Z",
|
|
265
290
|
"message": "[APM] Move APM tutorial from apm_oss to x-pack/apm (#100780)",
|
|
266
291
|
"sha": "0bcd78b0e999feb95057f5e6eafdb572b9b2fe39",
|
|
267
292
|
},
|
|
268
293
|
Object {
|
|
294
|
+
"branchLabelMapping": undefined,
|
|
269
295
|
"committedDate": "2021-05-18T10:33:16Z",
|
|
270
296
|
"message": "Migrate from Joi to @kbn/config-schema in \\"home\\" and \\"features\\" plugins (#100201)",
|
|
271
297
|
"sha": "574f6595ad2e5452fa90e6a3111220a599e473c0",
|
|
@@ -289,9 +315,11 @@ describe('entrypoint.module', () => {
|
|
|
289
315
|
"email": "sorenlouv@gmail.com",
|
|
290
316
|
"name": "Søren Louv-Jansen",
|
|
291
317
|
},
|
|
292
|
-
"
|
|
318
|
+
"pullRequestStates": Array [
|
|
293
319
|
Object {
|
|
294
320
|
"branch": "7.x",
|
|
321
|
+
"isSourceBranch": false,
|
|
322
|
+
"label": "v7.11.0",
|
|
295
323
|
"mergeCommit": Object {
|
|
296
324
|
"message": "[APM] Fix broken link to ML when time range is not set (#85976) (#86227)
|
|
297
325
|
|
|
@@ -315,6 +343,11 @@ describe('entrypoint.module', () => {
|
|
|
315
343
|
],
|
|
316
344
|
"sourceBranch": "master",
|
|
317
345
|
"sourceCommit": Object {
|
|
346
|
+
"branchLabelMapping": Object {
|
|
347
|
+
"^v(\\\\d+).(\\\\d+).\\\\d+$": "$1.$2",
|
|
348
|
+
"^v7.11.0$": "7.x",
|
|
349
|
+
"^v8.0.0$": "master",
|
|
350
|
+
},
|
|
318
351
|
"committedDate": "2020-12-16T15:17:03Z",
|
|
319
352
|
"message": "[APM] Fix broken link to ML when time range is not set (#85976)",
|
|
320
353
|
"sha": "744d6809ded7e1055bfda280c351cee3e8c0e3bf",
|
|
@@ -327,15 +360,18 @@ describe('entrypoint.module', () => {
|
|
|
327
360
|
"number": 85976,
|
|
328
361
|
"url": "https://github.com/elastic/kibana/pull/85976",
|
|
329
362
|
},
|
|
363
|
+
"suggestedTargetBranches": Array [],
|
|
330
364
|
},
|
|
331
365
|
Object {
|
|
332
366
|
"author": Object {
|
|
333
367
|
"email": "sorenlouv@gmail.com",
|
|
334
368
|
"name": "Søren Louv-Jansen",
|
|
335
369
|
},
|
|
336
|
-
"
|
|
370
|
+
"pullRequestStates": Array [
|
|
337
371
|
Object {
|
|
338
372
|
"branch": "7.x",
|
|
373
|
+
"isSourceBranch": false,
|
|
374
|
+
"label": "v7.11.0",
|
|
339
375
|
"mergeCommit": Object {
|
|
340
376
|
"message": "[7.x] [APM] Correlations polish (#85116) (#85940)
|
|
341
377
|
|
|
@@ -349,6 +385,11 @@ describe('entrypoint.module', () => {
|
|
|
349
385
|
],
|
|
350
386
|
"sourceBranch": "master",
|
|
351
387
|
"sourceCommit": Object {
|
|
388
|
+
"branchLabelMapping": Object {
|
|
389
|
+
"^v(\\\\d+).(\\\\d+).\\\\d+$": "$1.$2",
|
|
390
|
+
"^v7.11.0$": "7.x",
|
|
391
|
+
"^v8.0.0$": "master",
|
|
392
|
+
},
|
|
352
393
|
"committedDate": "2020-12-15T12:15:00Z",
|
|
353
394
|
"message": "[APM] Correlations polish (#85116)
|
|
354
395
|
|
|
@@ -365,15 +406,18 @@ describe('entrypoint.module', () => {
|
|
|
365
406
|
"number": 85116,
|
|
366
407
|
"url": "https://github.com/elastic/kibana/pull/85116",
|
|
367
408
|
},
|
|
409
|
+
"suggestedTargetBranches": Array [],
|
|
368
410
|
},
|
|
369
411
|
Object {
|
|
370
412
|
"author": Object {
|
|
371
413
|
"email": "sorenlouv@gmail.com",
|
|
372
414
|
"name": "Søren Louv-Jansen",
|
|
373
415
|
},
|
|
374
|
-
"
|
|
416
|
+
"pullRequestStates": Array [
|
|
375
417
|
Object {
|
|
376
418
|
"branch": "7.x",
|
|
419
|
+
"isSourceBranch": false,
|
|
420
|
+
"label": "v7.11.0",
|
|
377
421
|
"mergeCommit": Object {
|
|
378
422
|
"message": "[7.x] [APM] Improve pointer event hook (#85117) (#85142)",
|
|
379
423
|
"sha": "3b72a4f3cc7c0abd0541073e1d0246b85cea3def",
|
|
@@ -385,6 +429,11 @@ describe('entrypoint.module', () => {
|
|
|
385
429
|
],
|
|
386
430
|
"sourceBranch": "master",
|
|
387
431
|
"sourceCommit": Object {
|
|
432
|
+
"branchLabelMapping": Object {
|
|
433
|
+
"^v(\\\\d+).(\\\\d+).\\\\d+$": "$1.$2",
|
|
434
|
+
"^v7.11.0$": "7.x",
|
|
435
|
+
"^v8.0.0$": "master",
|
|
436
|
+
},
|
|
388
437
|
"committedDate": "2020-12-07T14:43:58Z",
|
|
389
438
|
"message": "[APM] Improve pointer event hook (#85117)",
|
|
390
439
|
"sha": "cee681afb3c5f87371112fab9a7e5dddbafea0a8",
|
|
@@ -397,6 +446,7 @@ describe('entrypoint.module', () => {
|
|
|
397
446
|
"number": 85117,
|
|
398
447
|
"url": "https://github.com/elastic/kibana/pull/85117",
|
|
399
448
|
},
|
|
449
|
+
"suggestedTargetBranches": Array [],
|
|
400
450
|
},
|
|
401
451
|
]
|
|
402
452
|
`);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Commit } from '../entrypoint.module';
|
|
2
|
+
import { ValidConfigOptions } from '../options/options';
|
|
3
|
+
export declare type GitConfigAuthor = {
|
|
4
|
+
name?: string;
|
|
5
|
+
email?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function getGitConfigAuthor(options: ValidConfigOptions): Promise<GitConfigAuthor | undefined>;
|
|
8
|
+
export declare type CommitAuthor = Required<GitConfigAuthor>;
|
|
9
|
+
export declare function getCommitAuthor({ options, commit, gitConfigAuthor, }: {
|
|
10
|
+
options: ValidConfigOptions;
|
|
11
|
+
commit: Commit;
|
|
12
|
+
gitConfigAuthor?: GitConfigAuthor;
|
|
13
|
+
}): CommitAuthor;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCommitAuthor = exports.getGitConfigAuthor = void 0;
|
|
4
|
+
const git_1 = require("./git");
|
|
5
|
+
async function getGitConfigAuthor(options) {
|
|
6
|
+
const localRepoPath = await (0, git_1.getLocalSourceRepoPath)(options);
|
|
7
|
+
if (!localRepoPath) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
name: await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.name' }),
|
|
12
|
+
email: await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.email' }),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.getGitConfigAuthor = getGitConfigAuthor;
|
|
16
|
+
function getCommitAuthor({ options, commit, gitConfigAuthor, }) {
|
|
17
|
+
if (options.resetAuthor) {
|
|
18
|
+
return {
|
|
19
|
+
name: options.authenticatedUsername,
|
|
20
|
+
email: `<${options.authenticatedUsername}@users.noreply.github.com>`,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
name: options.gitAuthorName ?? gitConfigAuthor?.name ?? commit.author.name,
|
|
25
|
+
email: options.gitAuthorEmail ?? gitConfigAuthor?.email ?? commit.author.email,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.getCommitAuthor = getCommitAuthor;
|
|
@@ -7,10 +7,10 @@ exports.cherrypickAndCreateTargetPullRequest = void 0;
|
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const lodash_1 = require("lodash");
|
|
9
9
|
const BackportError_1 = require("./BackportError");
|
|
10
|
+
const author_1 = require("./author");
|
|
10
11
|
const child_process_promisified_1 = require("./child-process-promisified");
|
|
11
12
|
const env_1 = require("./env");
|
|
12
13
|
const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
|
|
13
|
-
const getGitConfigAuthor_1 = require("./getGitConfigAuthor");
|
|
14
14
|
const git_1 = require("./git");
|
|
15
15
|
const commitFormatters_1 = require("./github/commitFormatters");
|
|
16
16
|
const addAssigneesToPullRequest_1 = require("./github/v3/addAssigneesToPullRequest");
|
|
@@ -35,7 +35,7 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
|
|
|
35
35
|
(0, logger_1.consoleLog)(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
|
|
36
36
|
const sourceBranch = getSourceBranchFromCommits(commits);
|
|
37
37
|
const [gitConfigAuthor] = await Promise.all([
|
|
38
|
-
(0,
|
|
38
|
+
(0, author_1.getGitConfigAuthor)(options),
|
|
39
39
|
(0, git_1.createBackportBranch)({
|
|
40
40
|
options,
|
|
41
41
|
sourceBranch,
|
|
@@ -123,11 +123,18 @@ function getBackportBranchName(targetBranch, commits) {
|
|
|
123
123
|
async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor) {
|
|
124
124
|
const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))}`;
|
|
125
125
|
const cherrypickSpinner = (0, ora_1.ora)(options.interactive, spinnerText).start();
|
|
126
|
-
|
|
126
|
+
const commitAuthor = (0, author_1.getCommitAuthor)({ options, commit, gitConfigAuthor });
|
|
127
|
+
await cherrypickAndHandleConflicts({
|
|
128
|
+
options,
|
|
129
|
+
commit,
|
|
130
|
+
commitAuthor,
|
|
131
|
+
targetBranch,
|
|
132
|
+
cherrypickSpinner,
|
|
133
|
+
});
|
|
127
134
|
// Conflicts should be resolved and files staged at this point
|
|
128
135
|
try {
|
|
129
|
-
// Run `git commit`
|
|
130
|
-
await (0, git_1.commitChanges)(commit,
|
|
136
|
+
// Run `git commit` in case conflicts were not manually committed
|
|
137
|
+
await (0, git_1.commitChanges)({ options, commit, commitAuthor });
|
|
131
138
|
cherrypickSpinner.succeed();
|
|
132
139
|
}
|
|
133
140
|
catch (e) {
|
|
@@ -135,9 +142,8 @@ async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor)
|
|
|
135
142
|
throw e;
|
|
136
143
|
}
|
|
137
144
|
}
|
|
138
|
-
async function cherrypickAndHandleConflicts(options, commit, targetBranch, cherrypickSpinner,
|
|
139
|
-
const mergedTargetPullRequest = commit.
|
|
140
|
-
const commitAuthor = getCommitAuthor({ options, gitConfigAuthor, commit });
|
|
145
|
+
async function cherrypickAndHandleConflicts({ options, commit, commitAuthor, targetBranch, cherrypickSpinner, }) {
|
|
146
|
+
const mergedTargetPullRequest = commit.pullRequestStates.find((pr) => pr.state === 'MERGED' && pr.branch === targetBranch);
|
|
141
147
|
let conflictingFiles;
|
|
142
148
|
let unstagedFiles;
|
|
143
149
|
let needsResolving;
|
|
@@ -249,15 +255,3 @@ async function listConflictingAndUnstagedFiles({ retries, options, conflictingFi
|
|
|
249
255
|
unstagedFiles: _unstagedFiles,
|
|
250
256
|
});
|
|
251
257
|
}
|
|
252
|
-
function getCommitAuthor({ options, gitConfigAuthor, commit, }) {
|
|
253
|
-
if (options.resetAuthor) {
|
|
254
|
-
return {
|
|
255
|
-
name: options.authenticatedUsername,
|
|
256
|
-
email: `<${options.authenticatedUsername}@users.noreply.github.com>`,
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
return {
|
|
260
|
-
name: options.gitAuthorName ?? gitConfigAuthor?.name ?? commit.author.name,
|
|
261
|
-
email: options.gitAuthorEmail ?? gitConfigAuthor?.email ?? commit.author.email,
|
|
262
|
-
};
|
|
263
|
-
}
|
|
@@ -63,6 +63,8 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
63
63
|
const options = {
|
|
64
64
|
assignees: [],
|
|
65
65
|
authenticatedUsername: 'sqren_authenticated',
|
|
66
|
+
gitAuthorName: 'Soren L',
|
|
67
|
+
gitAuthorEmail: 'soren@louv.dk',
|
|
66
68
|
author: 'sqren',
|
|
67
69
|
fork: true,
|
|
68
70
|
interactive: true,
|
|
@@ -82,7 +84,9 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
82
84
|
name: 'Søren Louv-Jansen',
|
|
83
85
|
},
|
|
84
86
|
sourceBranch: '7.x',
|
|
87
|
+
suggestedTargetBranches: [],
|
|
85
88
|
sourceCommit: {
|
|
89
|
+
branchLabelMapping: {},
|
|
86
90
|
committedDate: 'fff',
|
|
87
91
|
sha: 'mySha',
|
|
88
92
|
message: 'My original commit message (#1000)',
|
|
@@ -95,7 +99,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
95
99
|
message: 'My original commit message (#1000)',
|
|
96
100
|
},
|
|
97
101
|
},
|
|
98
|
-
|
|
102
|
+
pullRequestStates: [],
|
|
99
103
|
},
|
|
100
104
|
{
|
|
101
105
|
author: {
|
|
@@ -103,7 +107,9 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
103
107
|
name: 'Søren Louv-Jansen',
|
|
104
108
|
},
|
|
105
109
|
sourceBranch: '7.x',
|
|
110
|
+
suggestedTargetBranches: [],
|
|
106
111
|
sourceCommit: {
|
|
112
|
+
branchLabelMapping: {},
|
|
107
113
|
committedDate: 'ggg',
|
|
108
114
|
sha: 'mySha2',
|
|
109
115
|
message: 'My other commit message (#2000)',
|
|
@@ -116,7 +122,7 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
116
122
|
message: 'My other commit message (#2000)',
|
|
117
123
|
},
|
|
118
124
|
},
|
|
119
|
-
|
|
125
|
+
pullRequestStates: [],
|
|
120
126
|
},
|
|
121
127
|
];
|
|
122
128
|
const scope = (0, nock_1.default)('https://api.github.com')
|
|
@@ -204,13 +210,15 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
204
210
|
email: 'soren.louv@elastic.co',
|
|
205
211
|
name: 'Søren Louv-Jansen',
|
|
206
212
|
},
|
|
213
|
+
suggestedTargetBranches: [],
|
|
207
214
|
sourceCommit: {
|
|
215
|
+
branchLabelMapping: {},
|
|
208
216
|
committedDate: 'hhh',
|
|
209
217
|
sha: 'mySha',
|
|
210
218
|
message: 'My original commit message',
|
|
211
219
|
},
|
|
212
220
|
sourceBranch: '7.x',
|
|
213
|
-
|
|
221
|
+
pullRequestStates: [],
|
|
214
222
|
},
|
|
215
223
|
];
|
|
216
224
|
const scope = (0, nock_1.default)('https://api.github.com')
|
|
@@ -280,13 +288,15 @@ describe('cherrypickAndCreateTargetPullRequest', () => {
|
|
|
280
288
|
email: 'soren.louv@elastic.co',
|
|
281
289
|
name: 'Søren Louv-Jansen',
|
|
282
290
|
},
|
|
291
|
+
suggestedTargetBranches: [],
|
|
283
292
|
sourceCommit: {
|
|
293
|
+
branchLabelMapping: {},
|
|
284
294
|
committedDate: '2021-08-18T16:11:38Z',
|
|
285
295
|
sha: 'mySha',
|
|
286
296
|
message: 'My original commit message',
|
|
287
297
|
},
|
|
288
298
|
sourceBranch: '7.x',
|
|
289
|
-
|
|
299
|
+
pullRequestStates: [],
|
|
290
300
|
},
|
|
291
301
|
],
|
|
292
302
|
targetBranch: '6.x',
|
|
@@ -12,7 +12,7 @@ export declare function spawnPromise(cmd: string, cmdArgs: string[], cwd: string
|
|
|
12
12
|
stderr: string;
|
|
13
13
|
stdout: string;
|
|
14
14
|
}>;
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const spawnStream: (cmd: string, cmdArgs: ReadonlyArray<string>) => childProcess.ChildProcessWithoutNullStreams;
|
|
16
16
|
export declare type SpawnErrorContext = {
|
|
17
17
|
cmdArgs: string[];
|
|
18
18
|
code: number;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SpawnError = exports.
|
|
6
|
+
exports.SpawnError = exports.spawnStream = exports.spawnPromise = exports.exec = void 0;
|
|
7
7
|
const child_process_1 = __importDefault(require("child_process"));
|
|
8
8
|
const util_1 = require("util");
|
|
9
9
|
const logger_1 = require("./logger");
|
|
@@ -12,6 +12,8 @@ async function exec(cmd, options) {
|
|
|
12
12
|
const res = await execPromisified(cmd, {
|
|
13
13
|
maxBuffer: 100 * 1024 * 1024,
|
|
14
14
|
...options,
|
|
15
|
+
// ensure that git commands return english error messages
|
|
16
|
+
env: { ...process.env, LANG: 'en_US' },
|
|
15
17
|
});
|
|
16
18
|
return res;
|
|
17
19
|
}
|
|
@@ -20,7 +22,11 @@ async function spawnPromise(cmd, cmdArgs, cwd) {
|
|
|
20
22
|
const fullCmd = `${cmd} ${cmdArgs.join(' ')}`;
|
|
21
23
|
logger_1.logger.info(`Running command: "${fullCmd}"`);
|
|
22
24
|
return new Promise(function (resolve, reject) {
|
|
23
|
-
const subprocess = child_process_1.default.spawn(cmd, cmdArgs, {
|
|
25
|
+
const subprocess = child_process_1.default.spawn(cmd, cmdArgs, {
|
|
26
|
+
cwd,
|
|
27
|
+
// ensure that git commands return english error messages
|
|
28
|
+
env: { ...process.env, LANG: 'en_US' },
|
|
29
|
+
});
|
|
24
30
|
let stderr = '';
|
|
25
31
|
let stdout = '';
|
|
26
32
|
subprocess.stdout.on('data', (data) => {
|
|
@@ -45,7 +51,12 @@ async function spawnPromise(cmd, cmdArgs, cwd) {
|
|
|
45
51
|
});
|
|
46
52
|
}
|
|
47
53
|
exports.spawnPromise = spawnPromise;
|
|
48
|
-
|
|
54
|
+
const spawnStream = (cmd, cmdArgs) => {
|
|
55
|
+
return child_process_1.default.spawn(cmd, cmdArgs, {
|
|
56
|
+
env: { ...process.env, LANG: 'en_US' },
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
exports.spawnStream = spawnStream;
|
|
49
60
|
class SpawnError extends Error {
|
|
50
61
|
constructor(context) {
|
|
51
62
|
const cmdArgs = context.cmdArgs.join(' ');
|
package/dist/lib/getCommits.js
CHANGED
|
@@ -24,21 +24,26 @@ async function getCommits(options) {
|
|
|
24
24
|
try {
|
|
25
25
|
if (options.sha) {
|
|
26
26
|
const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
|
|
27
|
-
// TODO: use Intl.ListFormat to format the sha's
|
|
28
27
|
spinner.text = `Loading commit "${shas.map(commitFormatters_1.getShortSha)}"`;
|
|
29
28
|
const commits = await Promise.all(shas.map((sha) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha })));
|
|
30
|
-
spinner.stopAndPersist(getOraPersistsOption('Select commit', commits
|
|
29
|
+
spinner.stopAndPersist(getOraPersistsOption('Select commit', commits
|
|
30
|
+
.map((commit) => (0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))
|
|
31
|
+
.join(', ')));
|
|
31
32
|
return commits;
|
|
32
33
|
}
|
|
33
34
|
if (options.pullNumber) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const pullNumbers = Array.isArray(options.pullNumber)
|
|
36
|
+
? options.pullNumber
|
|
37
|
+
: [options.pullNumber];
|
|
38
|
+
spinner.text = `Loading pull request #${pullNumbers
|
|
39
|
+
.map((pullNumber) => `#${pullNumber}`)
|
|
40
|
+
.join(', ')}`;
|
|
41
|
+
const commits = await Promise.all(pullNumbers.map((pullNumber) => (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({ ...options, pullNumber })));
|
|
39
42
|
// add styles to make it look like a prompt question
|
|
40
|
-
spinner.stopAndPersist(getOraPersistsOption('Select pull request',
|
|
41
|
-
|
|
43
|
+
spinner.stopAndPersist(getOraPersistsOption('Select pull request', commits
|
|
44
|
+
.map((commit) => (0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))
|
|
45
|
+
.join(', ')));
|
|
46
|
+
return commits;
|
|
42
47
|
}
|
|
43
48
|
if (!options.interactive && !options.ls) {
|
|
44
49
|
throw new BackportError_1.BackportError('When "--interactive" is disabled either `--sha` or `--pr` must be specified');
|
|
@@ -40,12 +40,12 @@ conflictingFiles, }) {
|
|
|
40
40
|
return false;
|
|
41
41
|
}
|
|
42
42
|
// only include commit if it has an unmerged PR for the given target branch
|
|
43
|
-
const hasUnmergedPr = c.
|
|
43
|
+
const hasUnmergedPr = c.pullRequestStates.some((pr) => pr.branch === targetBranch && pr.state !== 'MERGED');
|
|
44
44
|
return hasUnmergedPr;
|
|
45
45
|
})
|
|
46
46
|
.slice(0, 10) // limit to max 10 commits
|
|
47
47
|
.map(async (c) => {
|
|
48
|
-
const results = await Promise.all(c.
|
|
48
|
+
const results = await Promise.all(c.pullRequestStates.map(async (targetPr) => {
|
|
49
49
|
if (!targetPr.mergeCommit) {
|
|
50
50
|
return false;
|
|
51
51
|
}
|
|
@@ -58,7 +58,7 @@ conflictingFiles, }) {
|
|
|
58
58
|
.filter(({ isCommitInBranch }) => !isCommitInBranch)
|
|
59
59
|
.map(({ c }) => {
|
|
60
60
|
// get pull request for the target branch (if it exists)
|
|
61
|
-
const pendingBackportPr = c.
|
|
61
|
+
const pendingBackportPr = c.pullRequestStates.find((pr) => pr.branch === targetBranch && pr.state === 'OPEN');
|
|
62
62
|
const formatted = pendingBackportPr
|
|
63
63
|
? ` - ${(0, commitFormatters_1.getFirstLine)(c.sourceCommit.message)} ${chalk_1.default.gray('(backport pending)')}\n ${pendingBackportPr.url}`
|
|
64
64
|
: ` - ${(0, commitFormatters_1.getFirstLine)(c.sourceCommit.message)} ${chalk_1.default.red('(backport missing)')}\n ${c.sourcePullRequest?.url}`;
|