backport 8.4.0 → 8.4.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.
- package/README.md +11 -178
- package/dist/lib/author.d.ts +13 -0
- package/dist/lib/author.js +28 -0
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +50 -35
- package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +2 -0
- package/dist/lib/git.d.ts +11 -8
- package/dist/lib/git.js +32 -32
- package/dist/lib/git.private.test.js +13 -10
- package/dist/lib/git.test.js +52 -24
- package/dist/lib/github/v4/apiRequestV4.js +14 -8
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +1 -0
- package/dist/lib/ora.d.ts +1 -0
- package/dist/options/options.js +2 -2
- package/dist/options/options.test.js +4 -4
- package/dist/test/e2e/cli/date-filters.private.test.js +1 -0
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +122 -6
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +27 -13
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +3 -2
- package/dist/test/e2e/cli/gracefully-handles-corrupt-repo.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/gracefully-handles-corrupt-repo.private.test.js +52 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +2 -2
- package/dist/test/e2e/cli/repo-with-programatically-added-commits.mutation.test.d.ts +1 -0
- package/dist/test/e2e/cli/repo-with-programatically-added-commits.mutation.test.js +114 -0
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +8 -2
- package/dist/test/e2e/cli/runBackportViaCli.js +48 -18
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +7 -1
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +1 -1
- package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -1
- package/dist/test/replaceStringAndLinebreaks.d.ts +5 -0
- package/dist/test/replaceStringAndLinebreaks.js +8 -0
- package/dist/test/sandbox.d.ts +1 -0
- package/dist/test/sandbox.js +8 -3
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +24 -24
- package/yarn.lock +886 -992
- package/dist/lib/getGitConfigAuthor.d.ts +0 -6
- package/dist/lib/getGitConfigAuthor.js +0 -15
|
@@ -121,6 +121,7 @@ describe('git.integration', () => {
|
|
|
121
121
|
repoOwner: 'origin',
|
|
122
122
|
dir: cwd,
|
|
123
123
|
},
|
|
124
|
+
sourceBranch: 'main',
|
|
124
125
|
targetBranch: '7.x',
|
|
125
126
|
backportBranch: 'my-backport-branch',
|
|
126
127
|
});
|
|
@@ -133,6 +134,7 @@ describe('git.integration', () => {
|
|
|
133
134
|
repoOwner: 'origin',
|
|
134
135
|
dir: cwd,
|
|
135
136
|
},
|
|
137
|
+
sourceBranch: 'main',
|
|
136
138
|
targetBranch: 'foo',
|
|
137
139
|
backportBranch: 'my-backport-branch',
|
|
138
140
|
});
|
|
@@ -152,6 +154,7 @@ describe('git.integration', () => {
|
|
|
152
154
|
repoOwner: 'origin',
|
|
153
155
|
dir: cwd,
|
|
154
156
|
},
|
|
157
|
+
sourceBranch: 'main',
|
|
155
158
|
targetBranch: '7.x',
|
|
156
159
|
backportBranch: 'my-backport-branch',
|
|
157
160
|
});
|
|
@@ -169,7 +172,7 @@ describe('git.integration', () => {
|
|
|
169
172
|
});
|
|
170
173
|
}).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
171
174
|
"Error pushing to https://github.com/sqren/repo-with-conflicts. Repository does not exist. Either fork the repository (https://github.com/sqren/repo-with-conflicts) or disable fork mode via \\"--no-fork\\".
|
|
172
|
-
Read more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/
|
|
175
|
+
Read more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#fork"
|
|
173
176
|
`);
|
|
174
177
|
});
|
|
175
178
|
});
|
|
@@ -290,7 +293,7 @@ describe('git.integration', () => {
|
|
|
290
293
|
cwd,
|
|
291
294
|
});
|
|
292
295
|
expect(async () => {
|
|
293
|
-
return await (0, git_1.commitChanges)(commit, options);
|
|
296
|
+
return await (0, git_1.commitChanges)({ commit, commitAuthor, options });
|
|
294
297
|
}).not.toThrowError();
|
|
295
298
|
const message = await getMostRecentCommitMessage(cwd);
|
|
296
299
|
expect(message).toBe('Update my-file-1.txt');
|
|
@@ -306,7 +309,7 @@ describe('git.integration', () => {
|
|
|
306
309
|
filename: 'my-file-2.txt',
|
|
307
310
|
cwd,
|
|
308
311
|
});
|
|
309
|
-
await (0, git_1.commitChanges)(commit, options);
|
|
312
|
+
await (0, git_1.commitChanges)({ commit, commitAuthor, options });
|
|
310
313
|
const message = await getMostRecentCommitMessage(cwd);
|
|
311
314
|
expect(message).toBe('my fallback commit message');
|
|
312
315
|
});
|
|
@@ -326,7 +329,7 @@ describe('git.integration', () => {
|
|
|
326
329
|
}
|
|
327
330
|
// disregard conflicts and stage all files
|
|
328
331
|
await childProcess.exec('git add -A', { cwd });
|
|
329
|
-
await (0, git_1.commitChanges)(commit, options);
|
|
332
|
+
await (0, git_1.commitChanges)({ commit, commitAuthor, options });
|
|
330
333
|
const message = await getMostRecentCommitMessage(cwd);
|
|
331
334
|
expect(message).toMatchInlineSnapshot(`
|
|
332
335
|
"Add 🇩🇰 (#12)
|
|
@@ -535,11 +538,11 @@ describe('git.integration', () => {
|
|
|
535
538
|
expect(res).toBe(false);
|
|
536
539
|
});
|
|
537
540
|
});
|
|
538
|
-
describe('
|
|
541
|
+
describe('getShasInMergeCommit', () => {
|
|
539
542
|
it('returns a list of commit hashes - excluding the merge hash itself', async () => {
|
|
540
|
-
const
|
|
541
|
-
expect(
|
|
542
|
-
expect(
|
|
543
|
+
const shas = await (0, git_1.getShasInMergeCommit)({ dir: cwd }, MERGE_COMMIT_HASH_1);
|
|
544
|
+
expect(shas).not.toContain(MERGE_COMMIT_HASH_1);
|
|
545
|
+
expect(shas).toEqual([
|
|
543
546
|
'f9a760e0d9eb3ebcc64f8cb75ce885714b836496',
|
|
544
547
|
'7b92e29e88266004485ce0fae0260605b01df887',
|
|
545
548
|
'a1facf8c006fb815d6a6ecd1b2907e6e64f29576',
|
|
@@ -551,8 +554,8 @@ describe('git.integration', () => {
|
|
|
551
554
|
]);
|
|
552
555
|
});
|
|
553
556
|
it('returns empty for squash commits', async () => {
|
|
554
|
-
const
|
|
555
|
-
expect(
|
|
557
|
+
const shas = await (0, git_1.getShasInMergeCommit)({ dir: cwd }, SQUASH_COMMIT_HASH);
|
|
558
|
+
expect(shas).toEqual([]);
|
|
556
559
|
});
|
|
557
560
|
});
|
|
558
561
|
});
|
package/dist/lib/git.test.js
CHANGED
|
@@ -238,6 +238,7 @@ describe('createBackportBranch', () => {
|
|
|
238
238
|
repoOwner: 'elastic',
|
|
239
239
|
repoName: 'kibana',
|
|
240
240
|
};
|
|
241
|
+
const sourceBranch = 'main';
|
|
241
242
|
const targetBranch = '4.x';
|
|
242
243
|
const backportBranch = 'backport/4.x/commit-72f94e76';
|
|
243
244
|
it(`should handle "couldn't find remote ref" error`, async () => {
|
|
@@ -249,7 +250,12 @@ describe('createBackportBranch', () => {
|
|
|
249
250
|
stderr: "fatal: couldn't find remote ref 4.x\n",
|
|
250
251
|
});
|
|
251
252
|
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
252
|
-
await expect((0, git_1.createBackportBranch)({
|
|
253
|
+
await expect((0, git_1.createBackportBranch)({
|
|
254
|
+
options,
|
|
255
|
+
sourceBranch,
|
|
256
|
+
targetBranch,
|
|
257
|
+
backportBranch,
|
|
258
|
+
})).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
253
259
|
});
|
|
254
260
|
it('should throw "Invalid refspec" error', async () => {
|
|
255
261
|
expect.assertions(1);
|
|
@@ -260,14 +266,24 @@ describe('createBackportBranch', () => {
|
|
|
260
266
|
stderr: "fatal: Invalid refspec 'https://github.com/elastic/kibana.git'\n",
|
|
261
267
|
});
|
|
262
268
|
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
263
|
-
await expect((0, git_1.createBackportBranch)({
|
|
269
|
+
await expect((0, git_1.createBackportBranch)({
|
|
270
|
+
options,
|
|
271
|
+
sourceBranch,
|
|
272
|
+
targetBranch,
|
|
273
|
+
backportBranch,
|
|
274
|
+
})).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
264
275
|
});
|
|
265
276
|
it('should rethrow normal error', async () => {
|
|
266
277
|
expect.assertions(1);
|
|
267
278
|
const err = new Error('just a normal error');
|
|
268
279
|
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
269
280
|
expect.assertions(1);
|
|
270
|
-
await expect((0, git_1.createBackportBranch)({
|
|
281
|
+
await expect((0, git_1.createBackportBranch)({
|
|
282
|
+
options,
|
|
283
|
+
sourceBranch,
|
|
284
|
+
targetBranch,
|
|
285
|
+
backportBranch,
|
|
286
|
+
})).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
271
287
|
});
|
|
272
288
|
});
|
|
273
289
|
describe('deleteRemote', () => {
|
|
@@ -301,8 +317,7 @@ describe('cherrypick', () => {
|
|
|
301
317
|
it('should return `needsResolving: false` when no errors are encountered', async () => {
|
|
302
318
|
jest
|
|
303
319
|
.spyOn(childProcess, 'spawnPromise')
|
|
304
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock
|
|
305
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock cherrypick(...)
|
|
320
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock `git cherrypick`
|
|
306
321
|
expect(await (0, git_1.cherrypick)({
|
|
307
322
|
options,
|
|
308
323
|
sha: 'abcd',
|
|
@@ -316,8 +331,7 @@ describe('cherrypick', () => {
|
|
|
316
331
|
it('should use mainline option when specified', async () => {
|
|
317
332
|
const spawnSpy = jest
|
|
318
333
|
.spyOn(childProcess, 'spawnPromise')
|
|
319
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock
|
|
320
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock cherrypick(...)
|
|
334
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock `git cherrypick`
|
|
321
335
|
await (0, git_1.cherrypick)({
|
|
322
336
|
options: { ...options, mainline: 1 },
|
|
323
337
|
sha: 'abcd',
|
|
@@ -343,14 +357,13 @@ describe('cherrypick', () => {
|
|
|
343
357
|
it('should use signoff option when specified', async () => {
|
|
344
358
|
const spawnSpy = jest
|
|
345
359
|
.spyOn(childProcess, 'spawnPromise')
|
|
346
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock
|
|
347
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock cherrypick(...)
|
|
360
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock `git cherrypick`
|
|
348
361
|
await (0, git_1.cherrypick)({
|
|
349
362
|
options: { ...options, signoff: true },
|
|
350
363
|
sha: 'abcd',
|
|
351
364
|
commitAuthor,
|
|
352
365
|
});
|
|
353
|
-
const args = spawnSpy.mock.calls[
|
|
366
|
+
const args = spawnSpy.mock.calls[0];
|
|
354
367
|
expect(args).toEqual([
|
|
355
368
|
'git',
|
|
356
369
|
[
|
|
@@ -369,7 +382,6 @@ describe('cherrypick', () => {
|
|
|
369
382
|
it('should return `needsResolving: true` upon cherrypick error', async () => {
|
|
370
383
|
jest
|
|
371
384
|
.spyOn(childProcess, 'spawnPromise')
|
|
372
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock getIsMergeCommit(...)
|
|
373
385
|
// mock `git cherrypick`
|
|
374
386
|
.mockRejectedValueOnce(new childProcess.SpawnError({
|
|
375
387
|
code: 128,
|
|
@@ -404,8 +416,6 @@ describe('cherrypick', () => {
|
|
|
404
416
|
it('should let the user know about the "--mainline" argument when cherry-picking a merge commit without specifying it', async () => {
|
|
405
417
|
jest
|
|
406
418
|
.spyOn(childProcess, 'spawnPromise')
|
|
407
|
-
// mock getIsMergeCommit(...)
|
|
408
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
|
|
409
419
|
// mock cherry pick command
|
|
410
420
|
.mockRejectedValueOnce(new childProcess.SpawnError({
|
|
411
421
|
code: 128,
|
|
@@ -431,8 +441,6 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
431
441
|
it('should gracefully handle empty commits', async () => {
|
|
432
442
|
jest
|
|
433
443
|
.spyOn(childProcess, 'spawnPromise')
|
|
434
|
-
// mock getIsMergeCommit(...)
|
|
435
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
|
|
436
444
|
// mock cherry pick command
|
|
437
445
|
.mockRejectedValueOnce(new childProcess.SpawnError({
|
|
438
446
|
code: 1,
|
|
@@ -449,8 +457,6 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
449
457
|
it('should re-throw non-cherrypick errors', async () => {
|
|
450
458
|
jest
|
|
451
459
|
.spyOn(childProcess, 'spawnPromise')
|
|
452
|
-
// mock getIsMergeCommit(...)
|
|
453
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
|
|
454
460
|
// mock cherry pick command
|
|
455
461
|
.mockRejectedValueOnce(new Error('non-cherrypick error'))
|
|
456
462
|
// getConflictingFiles
|
|
@@ -483,7 +489,7 @@ describe('commitChanges', () => {
|
|
|
483
489
|
jest
|
|
484
490
|
.spyOn(childProcess, 'spawnPromise')
|
|
485
491
|
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
|
|
486
|
-
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
492
|
+
await expect(await (0, git_1.commitChanges)({ commit, commitAuthor, options })).toBe(undefined);
|
|
487
493
|
});
|
|
488
494
|
it('should swallow error if changes have already been committed manaully', async () => {
|
|
489
495
|
const err = new childProcess.SpawnError({
|
|
@@ -493,7 +499,7 @@ describe('commitChanges', () => {
|
|
|
493
499
|
stderr: '',
|
|
494
500
|
});
|
|
495
501
|
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
496
|
-
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
502
|
+
await expect(await (0, git_1.commitChanges)({ commit, commitAuthor, options })).toBe(undefined);
|
|
497
503
|
});
|
|
498
504
|
describe('when commit fails due to empty message', () => {
|
|
499
505
|
let spy;
|
|
@@ -514,12 +520,34 @@ describe('commitChanges', () => {
|
|
|
514
520
|
code: 0,
|
|
515
521
|
cmdArgs: [],
|
|
516
522
|
});
|
|
517
|
-
res = await (0, git_1.commitChanges)(commit, options);
|
|
523
|
+
res = await (0, git_1.commitChanges)({ commit, commitAuthor, options });
|
|
518
524
|
});
|
|
519
525
|
it('should manually set the commit message', () => {
|
|
520
526
|
expect(spy).toHaveBeenCalledTimes(2);
|
|
521
|
-
expect(spy
|
|
522
|
-
|
|
527
|
+
expect(spy.mock.calls[0]).toEqual([
|
|
528
|
+
'git',
|
|
529
|
+
[
|
|
530
|
+
'-c',
|
|
531
|
+
'user.name="Soren L"',
|
|
532
|
+
'-c',
|
|
533
|
+
'user.email="soren@mail.dk"',
|
|
534
|
+
'commit',
|
|
535
|
+
'--no-edit',
|
|
536
|
+
],
|
|
537
|
+
expect.any(String),
|
|
538
|
+
]);
|
|
539
|
+
expect(spy.mock.calls[1]).toEqual([
|
|
540
|
+
'git',
|
|
541
|
+
[
|
|
542
|
+
'-c',
|
|
543
|
+
'user.name="Soren L"',
|
|
544
|
+
'-c',
|
|
545
|
+
'user.email="soren@mail.dk"',
|
|
546
|
+
'commit',
|
|
547
|
+
'--message=The original commit message',
|
|
548
|
+
],
|
|
549
|
+
expect.any(String),
|
|
550
|
+
]);
|
|
523
551
|
});
|
|
524
552
|
it('should handle the error and resolve successfully', async () => {
|
|
525
553
|
await expect(res).toBe(undefined);
|
|
@@ -529,7 +557,7 @@ describe('commitChanges', () => {
|
|
|
529
557
|
const err = new Error('another error');
|
|
530
558
|
jest.spyOn(childProcess, 'spawnPromise').mockRejectedValueOnce(err);
|
|
531
559
|
expect.assertions(1);
|
|
532
|
-
await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"another error"`);
|
|
560
|
+
await expect((0, git_1.commitChanges)({ commit, commitAuthor, options })).rejects.toThrowErrorMatchingInlineSnapshot(`"another error"`);
|
|
533
561
|
});
|
|
534
562
|
});
|
|
535
563
|
describe('addRemote', () => {
|
|
@@ -600,7 +628,7 @@ describe('pushBackportBranch', () => {
|
|
|
600
628
|
await expect((0, git_1.pushBackportBranch)({ options, backportBranch })).rejects
|
|
601
629
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
602
630
|
"Error pushing to https://github.com/the_fork_owner/kibana. Repository does not exist. Either fork the repository (https://github.com/elastic/kibana) or disable fork mode via \\"--no-fork\\".
|
|
603
|
-
Read more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/
|
|
631
|
+
Read more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#fork"
|
|
604
632
|
`);
|
|
605
633
|
});
|
|
606
634
|
});
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getQueryName = exports.GithubV4Exception = exports.apiRequestV4 = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const printer_1 = require("graphql/language/printer");
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
9
10
|
const BackportError_1 = require("../../BackportError");
|
|
10
11
|
const logger_1 = require("../../logger");
|
|
11
12
|
async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graphql', accessToken, query, variables, }) {
|
|
@@ -28,7 +29,7 @@ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graph
|
|
|
28
29
|
return response.data.data;
|
|
29
30
|
}
|
|
30
31
|
catch (e) {
|
|
31
|
-
if (
|
|
32
|
+
if (isAxiosGithubError(e) && e.response) {
|
|
32
33
|
addDebugLogs({
|
|
33
34
|
githubApiBaseUrlV4,
|
|
34
35
|
query,
|
|
@@ -42,13 +43,10 @@ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graph
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
exports.apiRequestV4 = apiRequestV4;
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
logger_1.logger.verbose('Variables:', variables);
|
|
50
|
-
logger_1.logger.verbose('Response headers:', githubResponse.headers);
|
|
51
|
-
logger_1.logger.verbose('Response data:', githubResponse.data);
|
|
46
|
+
function isAxiosGithubError(e) {
|
|
47
|
+
return (axios_1.default.isAxiosError(e) &&
|
|
48
|
+
e.response !== undefined &&
|
|
49
|
+
(0, lodash_1.isObject)(e.response.data));
|
|
52
50
|
}
|
|
53
51
|
class GithubV4Exception extends Error {
|
|
54
52
|
constructor(githubResponse, errorMessage) {
|
|
@@ -69,3 +67,11 @@ function getQueryName(query) {
|
|
|
69
67
|
return query.definitions[0].name?.value;
|
|
70
68
|
}
|
|
71
69
|
exports.getQueryName = getQueryName;
|
|
70
|
+
function addDebugLogs({ githubApiBaseUrlV4, query, variables, githubResponse, didThrow = false, }) {
|
|
71
|
+
const gqlQueryName = getQueryName(query);
|
|
72
|
+
logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${githubResponse.status}${didThrow ? ', EXCEPTION THROWN' : ''})`);
|
|
73
|
+
logger_1.logger.verbose(`Query: ${(0, printer_1.print)(query)}`);
|
|
74
|
+
logger_1.logger.verbose('Variables:', variables);
|
|
75
|
+
logger_1.logger.verbose('Response headers:', githubResponse.headers);
|
|
76
|
+
logger_1.logger.verbose('Response data:', githubResponse.data);
|
|
77
|
+
}
|
|
@@ -6,6 +6,7 @@ const fetchCommitBySha_1 = require("./fetchCommitBySha");
|
|
|
6
6
|
const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
|
|
7
7
|
const fetchPullRequestsBySearchQuery_1 = require("./fetchPullRequestsBySearchQuery");
|
|
8
8
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
jest.setTimeout(15000);
|
|
9
10
|
describe('allFetchers', () => {
|
|
10
11
|
let commitByAuthor;
|
|
11
12
|
beforeEach(async () => {
|
package/dist/lib/ora.d.ts
CHANGED
package/dist/options/options.js
CHANGED
|
@@ -8,8 +8,8 @@ const getOptionsFromGithub_1 = require("../lib/github/v4/getOptionsFromGithub/ge
|
|
|
8
8
|
const getRepoOwnerAndNameFromGitRemotes_1 = require("../lib/github/v4/getRepoOwnerAndNameFromGitRemotes");
|
|
9
9
|
const logger_1 = require("../lib/logger");
|
|
10
10
|
const config_1 = require("./config/config");
|
|
11
|
-
const PROJECT_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/docs/
|
|
12
|
-
const GLOBAL_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/docs/
|
|
11
|
+
const PROJECT_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/docs/config-file-options.md#project-config-backportrcjson';
|
|
12
|
+
const GLOBAL_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/docs/config-file-options.md#global-config-backportconfigjson';
|
|
13
13
|
exports.defaultConfigOptions = {
|
|
14
14
|
assignees: [],
|
|
15
15
|
autoAssign: false,
|
|
@@ -71,7 +71,7 @@ describe('getOptions', () => {
|
|
|
71
71
|
"Please update your config file: \\"/myHomeDir/.backport/config.json\\".
|
|
72
72
|
It must contain a valid \\"accessToken\\".
|
|
73
73
|
|
|
74
|
-
Read more: https://github.com/sqren/backport/blob/main/docs/
|
|
74
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#global-config-backportconfigjson"
|
|
75
75
|
`);
|
|
76
76
|
});
|
|
77
77
|
it('when `targetBranches`, `targetBranchChoices` and `branchLabelMapping` are all empty', async () => {
|
|
@@ -83,7 +83,7 @@ describe('getOptions', () => {
|
|
|
83
83
|
await expect(() => (0, options_1.getOptions)({ optionsFromCliArgs: {}, optionsFromModule: {} })).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
84
84
|
"Please specify a target branch: \\"--branch 6.1\\".
|
|
85
85
|
|
|
86
|
-
Read more: https://github.com/sqren/backport/blob/main/docs/
|
|
86
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#project-config-backportrcjson"
|
|
87
87
|
`);
|
|
88
88
|
});
|
|
89
89
|
describe('whe option is an empty string', () => {
|
|
@@ -107,7 +107,7 @@ describe('getOptions', () => {
|
|
|
107
107
|
"Please update your config file: \\"/myHomeDir/.backport/config.json\\".
|
|
108
108
|
It must contain a valid \\"accessToken\\".
|
|
109
109
|
|
|
110
|
-
Read more: https://github.com/sqren/backport/blob/main/docs/
|
|
110
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#global-config-backportconfigjson"
|
|
111
111
|
`);
|
|
112
112
|
});
|
|
113
113
|
});
|
|
@@ -120,7 +120,7 @@ describe('getOptions', () => {
|
|
|
120
120
|
await expect(() => (0, options_1.getOptions)({ optionsFromCliArgs: {}, optionsFromModule: {} })).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
121
121
|
"Please specify a repository: \\"--repo elastic/kibana\\".
|
|
122
122
|
|
|
123
|
-
Read more: https://github.com/sqren/backport/blob/main/docs/
|
|
123
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#project-config-backportrcjson"
|
|
124
124
|
`);
|
|
125
125
|
});
|
|
126
126
|
it('should get repoName from the remote', async () => {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
4
4
|
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
5
5
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
6
|
+
jest.setTimeout(15000);
|
|
6
7
|
describe('date filters (dateSince, dateUntil)', () => {
|
|
7
8
|
it(`filters commits by "since" and "until"`, async () => {
|
|
8
9
|
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
3
7
|
const child_process_promisified_1 = require("../../../lib/child-process-promisified");
|
|
4
8
|
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
9
|
+
const replaceStringAndLinebreaks_1 = require("../../replaceStringAndLinebreaks");
|
|
5
10
|
const sandbox_1 = require("../../sandbox");
|
|
6
11
|
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
7
12
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
13
|
+
jest.setTimeout(40000);
|
|
8
14
|
describe('different-merge-strategies', () => {
|
|
9
15
|
it('list all commits regardless how they were merged', async () => {
|
|
10
16
|
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
@@ -24,8 +30,8 @@ describe('different-merge-strategies', () => {
|
|
|
24
30
|
7. Merge strategy: Third of many merges
|
|
25
31
|
8. Merge strategy: Second of many merges
|
|
26
32
|
9. Merge strategy: First of many merges
|
|
27
|
-
10.Using squash to merge commits (#3)
|
|
28
|
-
11.Rebase strategy: Second commit
|
|
33
|
+
10.Using squash to merge commits (#3)
|
|
34
|
+
11.Rebase strategy: Second commit
|
|
29
35
|
12.Rebase strategy: First commit
|
|
30
36
|
13.Merge pull request #1 from backport-org/merge-strategy
|
|
31
37
|
14.Merge strategy: Second commit
|
|
@@ -33,7 +39,7 @@ describe('different-merge-strategies', () => {
|
|
|
33
39
|
16.Initial commit"
|
|
34
40
|
`);
|
|
35
41
|
});
|
|
36
|
-
describe('when selecting a merge commit', () => {
|
|
42
|
+
describe('when selecting a merge commit with eight commits', () => {
|
|
37
43
|
let output;
|
|
38
44
|
let sandboxPath;
|
|
39
45
|
beforeAll(async () => {
|
|
@@ -58,8 +64,22 @@ describe('different-merge-strategies', () => {
|
|
|
58
64
|
Backporting to 7.x:
|
|
59
65
|
- Pulling latest changes
|
|
60
66
|
✔ Pulling latest changes
|
|
61
|
-
- Cherry-picking: Merge
|
|
62
|
-
✔ Cherry-picking: Merge
|
|
67
|
+
- Cherry-picking: Merge strategy: First of many merges
|
|
68
|
+
✔ Cherry-picking: Merge strategy: First of many merges
|
|
69
|
+
- Cherry-picking: Merge strategy: Second of many merges
|
|
70
|
+
✔ Cherry-picking: Merge strategy: Second of many merges
|
|
71
|
+
- Cherry-picking: Merge strategy: Third of many merges
|
|
72
|
+
✔ Cherry-picking: Merge strategy: Third of many merges
|
|
73
|
+
- Cherry-picking: Merge strategy: Fourth of many merges
|
|
74
|
+
✔ Cherry-picking: Merge strategy: Fourth of many merges
|
|
75
|
+
- Cherry-picking: Merge strategy: Fifth of many merges
|
|
76
|
+
✔ Cherry-picking: Merge strategy: Fifth of many merges
|
|
77
|
+
- Cherry-picking: Merge strategy: Sixth of many merges
|
|
78
|
+
✔ Cherry-picking: Merge strategy: Sixth of many merges
|
|
79
|
+
- Cherry-picking: Merge strategy: Seventh of many merges
|
|
80
|
+
✔ Cherry-picking: Merge strategy: Seventh of many merges
|
|
81
|
+
- Cherry-picking: Merge strategy: Eighth of many merges
|
|
82
|
+
✔ Cherry-picking: Merge strategy: Eighth of many merges
|
|
63
83
|
✔ Dry run complete"
|
|
64
84
|
`);
|
|
65
85
|
});
|
|
@@ -78,7 +98,7 @@ describe('different-merge-strategies', () => {
|
|
|
78
98
|
]);
|
|
79
99
|
});
|
|
80
100
|
});
|
|
81
|
-
describe('when selecting
|
|
101
|
+
describe('when selecting a merge commit with two commits', () => {
|
|
82
102
|
let sandboxPath;
|
|
83
103
|
beforeAll(async () => {
|
|
84
104
|
sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
@@ -101,6 +121,102 @@ describe('different-merge-strategies', () => {
|
|
|
101
121
|
]);
|
|
102
122
|
});
|
|
103
123
|
});
|
|
124
|
+
describe('when selecting a merge commit with eight commits and a conflict occurs', () => {
|
|
125
|
+
let sandboxPath;
|
|
126
|
+
let output;
|
|
127
|
+
beforeAll(async () => {
|
|
128
|
+
sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
129
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
130
|
+
const proc = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
131
|
+
'--branch=7.1',
|
|
132
|
+
'--repo=backport-org/different-merge-strategies',
|
|
133
|
+
`--accessToken=${accessToken}`,
|
|
134
|
+
`--dir=${sandboxPath}`,
|
|
135
|
+
'--pr=9',
|
|
136
|
+
'--dry-run',
|
|
137
|
+
], {
|
|
138
|
+
keepAlive: true,
|
|
139
|
+
timeoutSeconds: 5,
|
|
140
|
+
showOra: true,
|
|
141
|
+
waitForString: 'Press ENTER when the conflicts are resolved and files are staged',
|
|
142
|
+
});
|
|
143
|
+
await (0, child_process_promisified_1.exec)(`git status`, { cwd: sandboxPath });
|
|
144
|
+
await promises_1.default.writeFile(`${sandboxPath}/new-file-added-with-many-merge-commits.txt`, `File added directly to 7.1 to cause merge conflict\nPrevious merge commit didn't have enough commits\n`);
|
|
145
|
+
await (0, child_process_promisified_1.exec)(`git add -A`, { cwd: sandboxPath });
|
|
146
|
+
const res = await proc.keypress('enter', {
|
|
147
|
+
showOra: true,
|
|
148
|
+
timeoutSeconds: 5,
|
|
149
|
+
});
|
|
150
|
+
output = (0, replaceStringAndLinebreaks_1.replaceStringAndLinebreaks)({
|
|
151
|
+
haystack: res.output,
|
|
152
|
+
stringBefore: sandboxPath,
|
|
153
|
+
stringAfter: '<SANDBOX_PATH>',
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
it('has the right output', async () => {
|
|
157
|
+
expect(output).toMatchInlineSnapshot(`
|
|
158
|
+
"- Initializing...
|
|
159
|
+
? Select pull request Merge pull request #9 from backport-org/many-merge-commits
|
|
160
|
+
✔ 100% Cloning repository from github.com (one-time operation)
|
|
161
|
+
|
|
162
|
+
Backporting to 7.1:
|
|
163
|
+
- Pulling latest changes
|
|
164
|
+
✔ Pulling latest changes
|
|
165
|
+
- Cherry-picking: Merge strategy: First of many merges
|
|
166
|
+
✖ Cherry-picking: Merge strategy: First of many merges
|
|
167
|
+
|
|
168
|
+
The commit could not be backported due to conflicts
|
|
169
|
+
|
|
170
|
+
Please fix the conflicts in <SANDBOX_PATH>
|
|
171
|
+
? Fix the following conflicts manually:
|
|
172
|
+
|
|
173
|
+
Conflicting files:
|
|
174
|
+
- <SANDBOX_PATH>/new-fi
|
|
175
|
+
le-added-with-many-merge-commits.txt
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
Press ENTER when the conflicts are resolved and files are staged (Y/n) ? Fix the following conflicts manually:
|
|
179
|
+
|
|
180
|
+
Conflicting files:
|
|
181
|
+
- <SANDBOX_PATH>/new-fi
|
|
182
|
+
le-added-with-many-merge-commits.txt
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
Press ENTER when the conflicts are resolved and files are staged Yes
|
|
186
|
+
✔ Cherry-picking: Merge strategy: First of many merges
|
|
187
|
+
- Cherry-picking: Merge strategy: Second of many merges
|
|
188
|
+
✔ Cherry-picking: Merge strategy: Second of many merges
|
|
189
|
+
- Cherry-picking: Merge strategy: Third of many merges
|
|
190
|
+
✔ Cherry-picking: Merge strategy: Third of many merges
|
|
191
|
+
- Cherry-picking: Merge strategy: Fourth of many merges
|
|
192
|
+
✔ Cherry-picking: Merge strategy: Fourth of many merges
|
|
193
|
+
- Cherry-picking: Merge strategy: Fifth of many merges
|
|
194
|
+
✔ Cherry-picking: Merge strategy: Fifth of many merges
|
|
195
|
+
- Cherry-picking: Merge strategy: Sixth of many merges
|
|
196
|
+
✔ Cherry-picking: Merge strategy: Sixth of many merges
|
|
197
|
+
- Cherry-picking: Merge strategy: Seventh of many merges
|
|
198
|
+
✔ Cherry-picking: Merge strategy: Seventh of many merges
|
|
199
|
+
- Cherry-picking: Merge strategy: Eighth of many merges
|
|
200
|
+
✔ Cherry-picking: Merge strategy: Eighth of many merges
|
|
201
|
+
✔ Dry run complete"
|
|
202
|
+
`);
|
|
203
|
+
});
|
|
204
|
+
it('backports all immediate children of the merge commit', async () => {
|
|
205
|
+
const commits = await listCommits(sandboxPath);
|
|
206
|
+
expect(commits).toEqual([
|
|
207
|
+
'Merge strategy: Eighth of many merges',
|
|
208
|
+
'Merge strategy: Seventh of many merges',
|
|
209
|
+
'Merge strategy: Sixth of many merges',
|
|
210
|
+
'Merge strategy: Fifth of many merges',
|
|
211
|
+
'Merge strategy: Fourth of many merges',
|
|
212
|
+
'Merge strategy: Third of many merges',
|
|
213
|
+
'Merge strategy: Second of many merges',
|
|
214
|
+
'Merge strategy: First of many merges',
|
|
215
|
+
'Create new-file-added-with-many-merge-commits.txt',
|
|
216
|
+
'Initial commit',
|
|
217
|
+
]);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
104
220
|
});
|
|
105
221
|
async function listCommits(sandboxPath) {
|
|
106
222
|
const { stdout } = await (0, child_process_promisified_1.exec)('git --no-pager log --pretty=format:%s', {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
4
|
+
const replaceStringAndLinebreaks_1 = require("../../replaceStringAndLinebreaks");
|
|
4
5
|
const sandbox_1 = require("../../sandbox");
|
|
5
6
|
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
6
7
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
8
|
+
jest.setTimeout(15000);
|
|
7
9
|
describe('interactive error handling', () => {
|
|
8
10
|
it('when branch is missing', async () => {
|
|
9
11
|
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
@@ -14,7 +16,7 @@ describe('interactive error handling', () => {
|
|
|
14
16
|
expect(output).toMatchInlineSnapshot(`
|
|
15
17
|
"Please specify a target branch: \\"--branch 6.1\\".
|
|
16
18
|
|
|
17
|
-
Read more: https://github.com/sqren/backport/blob/main/docs/
|
|
19
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#project-config-backportrcjson"
|
|
18
20
|
`);
|
|
19
21
|
});
|
|
20
22
|
it('when supplying invalid argument', async () => {
|
|
@@ -64,17 +66,29 @@ describe('interactive error handling', () => {
|
|
|
64
66
|
waitForString: 'Press ENTER when the conflicts',
|
|
65
67
|
timeoutSeconds: 5,
|
|
66
68
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
expect((0, replaceStringAndLinebreaks_1.replaceStringAndLinebreaks)({
|
|
70
|
+
haystack: output,
|
|
71
|
+
stringBefore: backportDir,
|
|
72
|
+
stringAfter: '<BACKPORT_DIR>',
|
|
73
|
+
})).toMatchInlineSnapshot(`
|
|
74
|
+
"Backporting to 7.x:
|
|
75
|
+
|
|
76
|
+
The commit could not be backported due to conflicts
|
|
77
|
+
|
|
78
|
+
Please fix the conflicts in <BACKPORT_DIR>
|
|
79
|
+
Hint: Before fixing the conflicts manually you should consider backporting the following pull requests to \\"7.x\\":
|
|
80
|
+
- Change Barca to Braithwaite (#8) (backport missing)
|
|
81
|
+
https://github.com/backport-org/repo-with-conflicts/pull/8
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
? Fix the following conflicts manually:
|
|
85
|
+
|
|
86
|
+
Conflicting files:
|
|
87
|
+
- <BACKPORT_DIR>/l
|
|
88
|
+
a-liga.md
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
Press ENTER when the conflicts are resolved and files are staged (Y/n)"
|
|
92
|
+
`);
|
|
79
93
|
});
|
|
80
94
|
});
|