backport 7.3.0 → 7.3.2-beta.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 (35) hide show
  1. package/README.md +3 -1
  2. package/dist/backportRun.js +12 -1
  3. package/dist/options/ConfigOptions.d.ts +3 -3
  4. package/dist/options/cliArgs.d.ts +3 -1
  5. package/dist/options/cliArgs.js +16 -7
  6. package/dist/options/config/config.d.ts +3 -3
  7. package/dist/options/config/readConfigFile.d.ts +3 -3
  8. package/dist/options/options.d.ts +3 -3
  9. package/dist/options/options.js +3 -1
  10. package/dist/options/options.test.js +2 -1
  11. package/dist/runSequentially.d.ts +3 -1
  12. package/dist/runSequentially.js +2 -3
  13. package/dist/services/git.d.ts +9 -10
  14. package/dist/services/git.integration.test.js +26 -12
  15. package/dist/services/git.js +6 -29
  16. package/dist/services/git.test.js +44 -16
  17. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +4 -5
  18. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +1 -1
  19. package/dist/test/e2e/cli/cli.private.test.js +6 -2
  20. package/dist/test/e2e/cli/commit-author.private.test.d.ts +1 -0
  21. package/dist/test/e2e/cli/commit-author.private.test.js +96 -0
  22. package/dist/test/e2e/module/module.mutation.test.d.ts +1 -0
  23. package/dist/test/e2e/module/module.mutation.test.js +369 -0
  24. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +3 -1
  25. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +26 -7
  26. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +14 -11
  27. package/dist/ui/getGitConfigAuthor.d.ts +6 -0
  28. package/dist/ui/getGitConfigAuthor.js +15 -0
  29. package/dist/ui/setupRepo.d.ts +1 -2
  30. package/dist/ui/setupRepo.js +4 -36
  31. package/dist/ui/setupRepo.test.js +11 -63
  32. package/dist/utils/packageVersion.d.ts +1 -1
  33. package/dist/utils/packageVersion.js +1 -1
  34. package/package.json +6 -6
  35. package/yarn.lock +58 -78
@@ -32,6 +32,7 @@ beforeEach(() => {
32
32
  afterEach(() => {
33
33
  jest.restoreAllMocks();
34
34
  });
35
+ const commitAuthor = { name: 'Soren L', email: 'soren@mail.dk' };
35
36
  describe('getUnstagedFiles', () => {
36
37
  it('should split lines and remove empty', async () => {
37
38
  jest.spyOn(childProcess, 'exec').mockResolvedValueOnce({
@@ -289,7 +290,11 @@ describe('cherrypick', () => {
289
290
  .mockResolvedValueOnce({ stderr: '', stdout: '' })
290
291
  // mock cherrypick(...)
291
292
  .mockResolvedValueOnce({ stderr: '', stdout: '' });
292
- expect(await (0, git_1.cherrypick)(options, 'abcd')).toEqual({
293
+ expect(await (0, git_1.cherrypick)({
294
+ options,
295
+ sha: 'abcd',
296
+ commitAuthor,
297
+ })).toEqual({
293
298
  conflictingFiles: [],
294
299
  unstagedFiles: [],
295
300
  needsResolving: false,
@@ -302,15 +307,19 @@ describe('cherrypick', () => {
302
307
  .mockResolvedValueOnce({ stderr: '', stdout: '' })
303
308
  // mock cherry pick command
304
309
  .mockResolvedValueOnce({ stderr: '', stdout: '' });
305
- await (0, git_1.cherrypick)({ ...options, mainline: 1 }, 'abcd');
306
- expect(execSpy.mock.calls[0][0]).toBe('git cherry-pick -x --mainline 1 abcd');
310
+ await (0, git_1.cherrypick)({
311
+ options: { ...options, mainline: 1 },
312
+ sha: 'abcd',
313
+ commitAuthor,
314
+ });
315
+ expect(execSpy.mock.calls[0][0]).toBe('git -c user.name="Soren L" -c user.email="soren@mail.dk" cherry-pick -x --mainline 1 abcd');
307
316
  });
308
317
  it('should return `needsResolving: true` upon cherrypick error', async () => {
309
318
  jest
310
319
  .spyOn(childProcess, 'exec')
311
320
  // mock getIsMergeCommit(...)
312
321
  .mockResolvedValueOnce({ stderr: '', stdout: '' })
313
- // mock cherry pick command
322
+ // mock `git cherrypick`
314
323
  .mockRejectedValueOnce(new ExecError_1.ExecError({
315
324
  killed: false,
316
325
  code: 128,
@@ -327,7 +336,11 @@ describe('cherrypick', () => {
327
336
  }))
328
337
  // mock getUnstagedFiles
329
338
  .mockResolvedValueOnce({ stdout: '', stderr: '' });
330
- expect(await (0, git_1.cherrypick)(options, 'abcd')).toEqual({
339
+ expect(await (0, git_1.cherrypick)({
340
+ options,
341
+ sha: 'abcd',
342
+ commitAuthor,
343
+ })).toEqual({
331
344
  conflictingFiles: [
332
345
  {
333
346
  absolute: '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
@@ -352,7 +365,11 @@ describe('cherrypick', () => {
352
365
  stdout: '',
353
366
  stderr: 'error: commit 381c7b604110257437a289b1f1742685eb8d79c5 is a merge but no -m option was given.\nfatal: cherry-pick failed\n',
354
367
  }));
355
- await expect((0, git_1.cherrypick)(options, 'abcd')).rejects
368
+ await expect((0, git_1.cherrypick)({
369
+ options,
370
+ sha: 'abcd',
371
+ commitAuthor,
372
+ })).rejects
356
373
  .toThrowError(`Cherrypick failed because the selected commit was a merge commit. Please try again by specifying the parent with the \`mainline\` argument:
357
374
 
358
375
  > backport --mainline
@@ -377,7 +394,11 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
377
394
  stdout: 'On branch backport/7.x/pr-58692\nYou are currently cherry-picking commit fe6b13b83cc.\n\nnothing to commit, working tree clean\n',
378
395
  stderr: "The previous cherry-pick is now empty, possibly due to conflict resolution.\nIf you wish to commit it anyway, use:\n\n git commit --allow-empty\n\nOtherwise, please use 'git cherry-pick --skip'\n",
379
396
  }));
380
- await expect((0, git_1.cherrypick)(options, 'abcd')).rejects.toThrowError(`Cherrypick failed because the selected commit (abcd) is empty. Did you already backport this commit?`);
397
+ await expect((0, git_1.cherrypick)({
398
+ options,
399
+ sha: 'abcd',
400
+ commitAuthor,
401
+ })).rejects.toThrowError(`Cherrypick failed because the selected commit (abcd) is empty. Did you already backport this commit?`);
381
402
  });
382
403
  it('gracefully handles missing git info', async () => {
383
404
  jest
@@ -393,10 +414,12 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
393
414
  stdout: '',
394
415
  stderr: '\n*** Please tell me who you are.\n\nRun\n\n git config --global user.email "you@example.com"\n git config --global user.name "Your Name"\n\nto set your account\'s default identity.\nOmit --global to set the identity only in this repository.\n\nfatal: empty ident name (for <foo@bar.net>) not allowed\n',
395
416
  }));
396
- await expect((0, git_1.cherrypick)(options, 'abcd')).rejects
397
- .toThrowErrorMatchingInlineSnapshot(`
398
- "Cherrypick failed:
399
-
417
+ await expect((0, git_1.cherrypick)({
418
+ options,
419
+ sha: 'abcd',
420
+ commitAuthor,
421
+ })).rejects.toThrowErrorMatchingInlineSnapshot(`
422
+ "
400
423
  *** Please tell me who you are.
401
424
 
402
425
  Run
@@ -422,7 +445,11 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
422
445
  .mockResolvedValueOnce({ stdout: '', stderr: '' })
423
446
  // getUnstagedFiles
424
447
  .mockResolvedValueOnce({ stdout: '', stderr: '' });
425
- await expect((0, git_1.cherrypick)(options, 'abcd')).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
448
+ await expect((0, git_1.cherrypick)({
449
+ options,
450
+ sha: 'abcd',
451
+ commitAuthor,
452
+ })).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
426
453
  });
427
454
  });
428
455
  describe('commitChanges', () => {
@@ -486,10 +513,10 @@ describe('commitChanges', () => {
486
513
  });
487
514
  });
488
515
  it('should re-throw other errors', async () => {
489
- const err = new Error('non-cherrypick error');
516
+ const err = new Error('another error');
490
517
  jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
491
518
  expect.assertions(1);
492
- await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
519
+ await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"another error"`);
493
520
  });
494
521
  });
495
522
  describe('addRemote', () => {
@@ -525,8 +552,9 @@ describe('pushBackportBranch', () => {
525
552
  const options = {
526
553
  authenticatedUsername: 'sqren_authenticated',
527
554
  fork: true,
528
- repoOwner: 'elastic',
555
+ repoForkOwner: 'the_fork_owner',
529
556
  repoName: 'kibana',
557
+ repoOwner: 'elastic',
530
558
  };
531
559
  const backportBranch = 'backport/7.x/pr-2';
532
560
  it('should handle missing fork error', async () => {
@@ -538,6 +566,6 @@ describe('pushBackportBranch', () => {
538
566
  stdout: '',
539
567
  stderr: "remote: Repository not found.\nfatal: repository 'https://github.com/sqren/kibana.git/' not found\n",
540
568
  });
541
- await expect((0, git_1.pushBackportBranch)({ options, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"Error pushing to https://github.com/sqren_authenticated/kibana. Repository does not exist. Either fork the source repository (https://github.com/elastic/kibana) or disable fork mode \\"--no-fork\\". Read more about \\"fork mode\\" in the docs: https://github.com/sqren/backport/blob/3a182b17e0e7237c12915895aea9d71f49eb2886/docs/configuration.md#fork"`);
569
+ await expect((0, git_1.pushBackportBranch)({ options, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"Error pushing to https://github.com/the_fork_owner/kibana. Repository does not exist. Either fork the source repository (https://github.com/elastic/kibana) or disable fork mode \\"--no-fork\\". Read more about \\"fork mode\\" in the docs: https://github.com/sqren/backport/blob/3a182b17e0e7237c12915895aea9d71f49eb2886/docs/configuration.md#fork"`);
542
570
  });
543
571
  });
@@ -1,12 +1,11 @@
1
1
  export declare type OptionsFromGithub = Awaited<ReturnType<typeof getOptionsFromGithub>>;
2
2
  export declare function getOptionsFromGithub(options: {
3
3
  accessToken: string;
4
+ cwd?: string;
4
5
  githubApiBaseUrlV4?: string;
5
6
  repoName: string;
6
7
  repoOwner: string;
7
- username?: string;
8
8
  skipRemoteConfig?: boolean;
9
- cwd?: string;
10
9
  }): Promise<{
11
10
  accessToken?: string | undefined;
12
11
  assignees?: string[] | undefined;
@@ -29,11 +28,11 @@ export declare function getOptionsFromGithub(options: {
29
28
  dir?: string | undefined;
30
29
  editor?: string | undefined;
31
30
  fork?: boolean | undefined;
31
+ gitAuthorEmail?: string | undefined;
32
+ gitAuthorName?: string | undefined;
32
33
  gitHostname?: string | undefined;
33
34
  githubApiBaseUrlV3?: string | undefined;
34
35
  githubApiBaseUrlV4?: string | undefined;
35
- gitUserEmail?: string | undefined;
36
- gitUserName?: string | undefined;
37
36
  logFilePath?: string | undefined;
38
37
  maxNumber?: number | undefined;
39
38
  multiple?: boolean | undefined;
@@ -45,6 +44,7 @@ export declare function getOptionsFromGithub(options: {
45
44
  prTitle?: string | undefined;
46
45
  publishStatusComment?: boolean | undefined;
47
46
  pullNumber?: number | undefined;
47
+ repoForkOwner?: string | undefined;
48
48
  repoName?: string | undefined;
49
49
  repoOwner?: string | undefined;
50
50
  resetAuthor?: boolean | undefined;
@@ -56,7 +56,6 @@ export declare function getOptionsFromGithub(options: {
56
56
  targetBranchChoices?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
57
57
  targetBranches?: string[] | undefined;
58
58
  targetPRLabels?: string[] | undefined;
59
- username?: string | undefined;
60
59
  verbose?: boolean | undefined;
61
60
  help?: boolean | undefined;
62
61
  version?: boolean | undefined;
@@ -32,7 +32,7 @@ async function getOptionsFromGithub(options) {
32
32
  }
33
33
  const remoteConfig = await getRemoteConfigFileOptions(res, options.cwd, options.skipRemoteConfig);
34
34
  return {
35
- authenticatedUsername: options.username ?? res.viewer.login,
35
+ authenticatedUsername: res.viewer.login,
36
36
  sourceBranch: res.repository.defaultBranchRef.name,
37
37
  ...remoteConfig,
38
38
  };
@@ -70,7 +70,10 @@ describe('backport cli', () => {
70
70
  --editor Editor to be opened during conflict resolution [string]
71
71
  --skipRemoteConfig Use local .backportrc.json config instead of loading from
72
72
  Github [boolean]
73
- --fork Create backports in fork or origin repo [boolean]
73
+ --fork Create backports in fork or origin repo. Defaults to true
74
+ [boolean]
75
+ --gitAuthorName Set commit author name [string]
76
+ --gitAuthorEmail Set commit author email [string]
74
77
  --mainline Parent id of merge commit. Defaults to 1 when supplied
75
78
  without arguments [number]
76
79
  -n, --maxNumber, --number Number of commits to choose from [number]
@@ -90,6 +93,8 @@ describe('backport cli', () => {
90
93
  --pullNumber, --pr Pull request to backport [number]
91
94
  --resetAuthor Set yourself as commit author [boolean]
92
95
  --reviewer Add reviewer to the target PR [array]
96
+ --repoForkOwner The owner of the fork where the backport branch is pushed.
97
+ Defaults to the currently authenticated user [string]
93
98
  --repoOwner Repository owner [string]
94
99
  --repoName Repository name [string]
95
100
  --repo Repo owner and name [string]
@@ -100,7 +105,6 @@ describe('backport cli', () => {
100
105
  -b, --targetBranch, --branch Branch(es) to backport to [array]
101
106
  --targetBranchChoice List branches to backport to [array]
102
107
  -l, --targetPRLabel, --label Add labels to the target (backport) PR [array]
103
- --username Defaults to the authenticated user [string]
104
108
  --verbose Show additional debug information [boolean]
105
109
  --verify Opposite of no-verify [boolean]
106
110
  --help Show help [boolean]
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const promises_1 = __importDefault(require("fs/promises"));
7
+ const child_process_promisified_1 = require("../../../services/child-process-promisified");
8
+ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
9
+ const sandbox_1 = require("../../sandbox");
10
+ const runBackportViaCli_1 = require("./runBackportViaCli");
11
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
12
+ describe('commit author', () => {
13
+ let sourceRepo;
14
+ let backportRepo;
15
+ beforeEach(async () => {
16
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
17
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
18
+ sourceRepo = `${sandboxPath}/sourceRepo`;
19
+ backportRepo = `${sandboxPath}/backportRepo`;
20
+ await (0, child_process_promisified_1.exec)(`git clone https://github.com/backport-org/commit-author.git ${sourceRepo}`, { cwd: sandboxPath });
21
+ await promises_1.default.writeFile(`${sandboxPath}/.backportrc.json`, JSON.stringify({
22
+ repoName: 'commit-author',
23
+ repoOwner: 'backport-org',
24
+ }));
25
+ });
26
+ // eslint-disable-next-line jest/no-commented-out-tests
27
+ // it('use commit author from source commit', async () => {
28
+ // await runBackportViaCli(
29
+ // [
30
+ // `--accessToken=${accessToken}`,
31
+ // `--dir=${backportRepo}`,
32
+ // '--branch=production',
33
+ // '--pr=2',
34
+ // '--dry-run',
35
+ // ],
36
+ // { waitForString: 'Dry run complete', cwd: sourceRepo, showOra: true }
37
+ // );
38
+ // const { authorEmail, authorName } = await getCommitAuthor({
39
+ // cwd: backportRepo,
40
+ // });
41
+ // expect(authorName).toEqual('Sonny Long (demo)');
42
+ // expect(authorEmail).toEqual('71195571+sqren-demo@users.noreply.github.com');
43
+ // });
44
+ it('use commit author from git config in source repo', async () => {
45
+ await (0, child_process_promisified_1.exec)(`git config user.name "Peter Kanin"`, { cwd: sourceRepo });
46
+ await (0, child_process_promisified_1.exec)(`git config user.email "kanin@zoo.dk"`, { cwd: sourceRepo });
47
+ await (0, runBackportViaCli_1.runBackportViaCli)([
48
+ `--accessToken=${accessToken}`,
49
+ `--dir=${backportRepo}`,
50
+ '--branch=production',
51
+ '--pr=2',
52
+ '--dry-run',
53
+ ], { waitForString: 'Dry run complete', cwd: sourceRepo, showOra: true });
54
+ const { authorEmail, authorName } = await getCommitAuthor({
55
+ cwd: backportRepo,
56
+ });
57
+ expect(authorName).toEqual('Peter Kanin');
58
+ expect(authorEmail).toEqual('kanin@zoo.dk');
59
+ });
60
+ it('use commit author from cli args', async () => {
61
+ await (0, runBackportViaCli_1.runBackportViaCli)([
62
+ `--accessToken=${accessToken}`,
63
+ `--dir=${backportRepo}`,
64
+ '--branch=production',
65
+ '--pr=2',
66
+ '--dry-run',
67
+ '--gitAuthorName="Donald Duck"',
68
+ '--gitAuthorEmail=duck@disney.com',
69
+ ], { waitForString: 'Dry run complete', cwd: sourceRepo, showOra: true });
70
+ const { authorEmail, authorName } = await getCommitAuthor({
71
+ cwd: backportRepo,
72
+ });
73
+ expect(authorName).toEqual('Donald Duck');
74
+ expect(authorEmail).toEqual('duck@disney.com');
75
+ });
76
+ it('use resetAuthor option to set current user as author of commit', async () => {
77
+ await (0, runBackportViaCli_1.runBackportViaCli)([
78
+ `--accessToken=${accessToken}`,
79
+ `--dir=${backportRepo}`,
80
+ '--branch=production',
81
+ '--pr=2',
82
+ '--dry-run',
83
+ '--reset-author',
84
+ ], { waitForString: 'Dry run complete', cwd: sourceRepo, showOra: true });
85
+ const { authorEmail, authorName } = await getCommitAuthor({
86
+ cwd: backportRepo,
87
+ });
88
+ expect(authorName).toEqual('sqren');
89
+ expect(authorEmail).toEqual('sqren@users.noreply.github.com');
90
+ });
91
+ });
92
+ async function getCommitAuthor({ cwd }) {
93
+ const { stdout: authorName } = await (0, child_process_promisified_1.exec)('git --no-pager log -1 --format=format:"%cn"', { cwd });
94
+ const { stdout: authorEmail } = await (0, child_process_promisified_1.exec)('git --no-pager log -1 --format=format:"%ce"', { cwd });
95
+ return { authorName, authorEmail };
96
+ }
@@ -0,0 +1 @@
1
+ export {};