backport 7.2.0 → 7.3.1

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 (68) hide show
  1. package/README.md +12 -5
  2. package/dist/backportRun.js +12 -1
  3. package/dist/entrypoint.cli.d.ts +0 -1
  4. package/dist/entrypoint.cli.js +0 -1
  5. package/dist/entrypoint.cli.private.test.js +1 -0
  6. package/dist/options/ConfigOptions.d.ts +3 -1
  7. package/dist/options/cliArgs.d.ts +3 -1
  8. package/dist/options/cliArgs.js +16 -7
  9. package/dist/options/config/config.d.ts +3 -1
  10. package/dist/options/config/readConfigFile.d.ts +3 -1
  11. package/dist/options/options.d.ts +3 -1
  12. package/dist/options/options.js +3 -1
  13. package/dist/options/options.test.js +2 -1
  14. package/dist/runSequentially.d.ts +3 -1
  15. package/dist/runSequentially.js +2 -3
  16. package/dist/services/git.d.ts +15 -7
  17. package/dist/services/git.integration.test.js +38 -58
  18. package/dist/services/git.js +21 -28
  19. package/dist/services/git.test.js +56 -17
  20. package/dist/services/github/v3/createPullRequest.test.js +52 -0
  21. package/dist/services/github/v3/createStatusComment.test.js +12 -2
  22. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +1 -0
  23. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +1 -0
  24. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +1 -0
  25. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -0
  26. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -0
  27. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +4 -3
  28. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +1 -1
  29. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +1 -0
  30. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +20 -0
  31. package/dist/services/prompt.test.js +5 -0
  32. package/dist/services/sourceCommit/getMockSourceCommit.js +1 -0
  33. package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -0
  34. package/dist/services/sourceCommit/parseSourceCommit.js +6 -0
  35. package/dist/services/sourceCommit/parseSourceCommit.test.js +1 -0
  36. package/dist/test/e2e/cli/cli.private.test.d.ts +1 -0
  37. package/dist/test/e2e/cli/cli.private.test.js +219 -0
  38. package/dist/test/e2e/cli/commit-author.private.test.d.ts +1 -0
  39. package/dist/test/e2e/cli/commit-author.private.test.js +96 -0
  40. package/dist/test/e2e/cli/different-merge-strategies.private.test.d.ts +1 -0
  41. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +108 -0
  42. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.d.ts +1 -0
  43. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +49 -0
  44. package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -0
  45. package/dist/test/e2e/cli/runBackportViaCli.js +53 -0
  46. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.d.ts +1 -0
  47. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +73 -0
  48. package/dist/test/e2e/module/module.mutation.test.d.ts +1 -0
  49. package/dist/test/e2e/module/module.mutation.test.js +369 -0
  50. package/dist/test/e2e/module.e2e.mutation.test.d.ts +1 -0
  51. package/dist/test/e2e/module.e2e.mutation.test.js +369 -0
  52. package/dist/test/e2e/module.e2e.private.test.js +6 -0
  53. package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -0
  54. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +3 -1
  55. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +29 -10
  56. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +38 -25
  57. package/dist/ui/getCommitsWithoutBackports.test.js +20 -0
  58. package/dist/ui/getGitConfigAuthor.d.ts +6 -0
  59. package/dist/ui/getGitConfigAuthor.js +15 -0
  60. package/dist/ui/getTargetBranches.test.js +2 -0
  61. package/dist/ui/setupRepo.d.ts +2 -0
  62. package/dist/ui/setupRepo.js +56 -0
  63. package/dist/ui/setupRepo.test.d.ts +1 -0
  64. package/dist/ui/setupRepo.test.js +236 -0
  65. package/dist/utils/packageVersion.d.ts +1 -1
  66. package/dist/utils/packageVersion.js +1 -1
  67. package/package.json +11 -11
  68. package/yarn.lock +61 -81
package/README.md CHANGED
@@ -29,6 +29,10 @@ After installation you should add an access token to the [global config](https:/
29
29
 
30
30
  ## Quick start
31
31
 
32
+ ```
33
+ npm install backport
34
+ ```
35
+
32
36
  Add a [project config](https://github.com/sqren/backport/blob/master/docs/configuration.md#project-config-backportrcjson) to the root of your repository:
33
37
 
34
38
  ```js
@@ -48,10 +52,13 @@ Add a [project config](https://github.com/sqren/backport/blob/master/docs/config
48
52
  }
49
53
  ```
50
54
 
51
- Install locally:
55
+ Add personal access token to [global config](https://github.com/sqren/backport/blob/master/docs/configuration.md#global-config-backportconfigjson):
52
56
 
53
- ```
54
- npm install backport
57
+ ```js
58
+ // ~/.backport/config.json
59
+ {
60
+ "accessToken": "ghp_very_secret"
61
+ }
55
62
  ```
56
63
 
57
64
  Run:
@@ -71,7 +78,7 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config
71
78
  | Option | Shorthand notation | Description | Default |
72
79
  | ------------------- | ------------------ | -------------------------------------------------------------------------- | ------------------------- |
73
80
  | --access-token | | Github access token | |
74
- | --all | -a | Show commits from any author | false |
81
+ | --all | -a | Show commits from any author. Opposite of `--author` | false |
75
82
  | --assignee | --assign | Assign users to the target PR | |
76
83
  | --author | | Filter commits by Github username. Opposite of `--all` | _Current user_ |
77
84
  | --auto-assign | | Assign current user to the target PR | false |
@@ -96,6 +103,7 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config
96
103
  | --pr-filter | | Find PRs using [Github's search syntax][2] | |
97
104
  | --pr-title | --title | Title of pull request | |
98
105
  | --pull-number | --pr | Backport pull request by number | |
106
+ | --repo-fork-owner | | The owner of the fork where the backport branch is pushed. | _Current user_ |
99
107
  | --repo-name | | Name of repository | |
100
108
  | --repo-owner | | Owner of repository | |
101
109
  | --reset-author | | Set yourself as commit author | |
@@ -265,6 +273,5 @@ See [CONTRIBUTING.md](https://github.com/sqren/backport/blob/master/CONTRIBUTING
265
273
  [1]: https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt--x
266
274
  [2]: https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax
267
275
 
268
- [![Build Status](https://travis-ci.com/sqren/backport.svg?branch=master)](https://app.travis-ci.com/github/sqren/backport)
269
276
  [![NPM version](https://img.shields.io/npm/v/backport.svg)](https://www.npmjs.com/package/backport)
270
277
  [![Coverage Status](https://coveralls.io/repos/github/sqren/backport/badge.svg?branch=master)](https://coveralls.io/github/sqren/backport?branch=master)
@@ -14,8 +14,10 @@ const createStatusComment_1 = require("./services/github/v3/createStatusComment"
14
14
  const apiRequestV4_1 = require("./services/github/v4/apiRequestV4");
15
15
  const logger_1 = require("./services/logger");
16
16
  const getCommits_1 = require("./ui/getCommits");
17
+ const getGitConfigAuthor_1 = require("./ui/getGitConfigAuthor");
17
18
  const getTargetBranches_1 = require("./ui/getTargetBranches");
18
19
  const ora_1 = require("./ui/ora");
20
+ const setupRepo_1 = require("./ui/setupRepo");
19
21
  async function backportRun(processArgs, optionsFromModule = {}) {
20
22
  const argv = (0, yargs_parser_1.default)(processArgs);
21
23
  const ci = argv.ci ?? optionsFromModule.ci;
@@ -36,7 +38,16 @@ async function backportRun(processArgs, optionsFromModule = {}) {
36
38
  logger_1.logger.info('Commits', commits);
37
39
  const targetBranches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
38
40
  logger_1.logger.info('Target branches', targetBranches);
39
- const results = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
41
+ const [gitConfigAuthor] = await Promise.all([
42
+ (0, getGitConfigAuthor_1.getGitConfigAuthor)(options),
43
+ (0, setupRepo_1.setupRepo)(options),
44
+ ]);
45
+ const results = await (0, runSequentially_1.runSequentially)({
46
+ options,
47
+ commits,
48
+ targetBranches,
49
+ gitConfigAuthor,
50
+ });
40
51
  logger_1.logger.info('Results', results);
41
52
  const backportResponse = {
42
53
  status: 'success',
@@ -1,2 +1 @@
1
- #!/usr/bin/env node
2
1
  export {};
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  "use strict";
3
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -13,6 +13,7 @@ describe('entrypoint.module', () => {
13
13
  });
14
14
  const expectedCommits = [
15
15
  {
16
+ author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
16
17
  sourceCommit: {
17
18
  committedDate: '2020-08-15T10:44:04Z',
18
19
  message: 'Add family emoji (#2)',
@@ -27,6 +27,8 @@ declare type Options = Partial<{
27
27
  dir: string;
28
28
  editor: string;
29
29
  fork: boolean;
30
+ gitAuthorEmail: string;
31
+ gitAuthorName: string;
30
32
  gitHostname: string;
31
33
  githubApiBaseUrlV3: string;
32
34
  githubApiBaseUrlV4: string;
@@ -41,6 +43,7 @@ declare type Options = Partial<{
41
43
  prTitle: string;
42
44
  publishStatusComment: boolean;
43
45
  pullNumber: number;
46
+ repoForkOwner: string;
44
47
  repoName: string;
45
48
  repoOwner: string;
46
49
  resetAuthor: boolean;
@@ -52,7 +55,6 @@ declare type Options = Partial<{
52
55
  targetBranchChoices: TargetBranchChoiceOrString[];
53
56
  targetBranches: string[];
54
57
  targetPRLabels: string[];
55
- username: string;
56
58
  verbose: boolean;
57
59
  }>;
58
60
  export declare type ConfigFileOptions = Options & Partial<{
@@ -22,11 +22,14 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
22
22
  gitHostname?: string | undefined;
23
23
  githubApiBaseUrlV3?: string | undefined;
24
24
  githubApiBaseUrlV4?: string | undefined;
25
+ gitAuthorName?: string | undefined;
26
+ gitAuthorEmail?: string | undefined;
25
27
  mainline?: number | undefined;
26
28
  maxNumber?: number | undefined;
27
29
  multipleBranches?: boolean | undefined;
28
30
  multipleCommits?: boolean | undefined;
29
31
  noVerify?: boolean | undefined;
32
+ repoForkOwner?: string | undefined;
30
33
  prDescription?: string | undefined;
31
34
  prTitle?: string | undefined;
32
35
  prFilter?: string | undefined;
@@ -36,7 +39,6 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
36
39
  repoOwner?: string | undefined;
37
40
  repoName?: string | undefined;
38
41
  sourceBranch?: string | undefined;
39
- username?: string | undefined;
40
42
  dateSince?: string | undefined;
41
43
  dateUntil?: string | undefined;
42
44
  commitPaths?: string[] | undefined;
@@ -96,9 +96,9 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
96
96
  description: 'Use local .backportrc.json config instead of loading from Github',
97
97
  type: 'boolean',
98
98
  })
99
- // push target branch to {authenticatedUsername}/{repoName}
99
+ // push target branch to {repoForkOwner}/{repoName}
100
100
  .option('fork', {
101
- description: 'Create backports in fork or origin repo',
101
+ description: 'Create backports in fork or origin repo. Defaults to true',
102
102
  type: 'boolean',
103
103
  conflicts: ['noFork'],
104
104
  })
@@ -116,6 +116,14 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
116
116
  hidden: true,
117
117
  description: `Base url for Github's GraphQL (v4) API`,
118
118
  type: 'string',
119
+ })
120
+ .option('gitAuthorName', {
121
+ description: `Set commit author name`,
122
+ type: 'string',
123
+ })
124
+ .option('gitAuthorEmail', {
125
+ description: `Set commit author email`,
126
+ type: 'string',
119
127
  })
120
128
  .option('logFilePath', {
121
129
  hidden: true,
@@ -179,7 +187,7 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
179
187
  .option('noFork', {
180
188
  description: 'Create backports in the origin repo',
181
189
  type: 'boolean',
182
- conflicts: ['fork'],
190
+ conflicts: ['fork', 'repoForkOwner'],
183
191
  })
184
192
  .option('path', {
185
193
  description: 'Only list commits touching files under the specified path',
@@ -216,6 +224,11 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
216
224
  description: 'Add reviewer to the target PR',
217
225
  type: 'array',
218
226
  string: true,
227
+ })
228
+ .option('repoForkOwner', {
229
+ description: 'The owner of the fork where the backport branch is pushed. Defaults to the currently authenticated user',
230
+ type: 'string',
231
+ conflicts: ['noFork'],
219
232
  })
220
233
  .option('repoOwner', {
221
234
  description: 'Repository owner',
@@ -264,10 +277,6 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
264
277
  alias: ['label', 'l'],
265
278
  type: 'array',
266
279
  string: true,
267
- })
268
- .option('username', {
269
- description: 'Defaults to the authenticated user ',
270
- type: 'string',
271
280
  })
272
281
  .option('verbose', {
273
282
  description: 'Show additional debug information',
@@ -27,6 +27,8 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
27
27
  dir?: string | undefined;
28
28
  editor?: string | undefined;
29
29
  fork?: boolean | undefined;
30
+ gitAuthorEmail?: string | undefined;
31
+ gitAuthorName?: string | undefined;
30
32
  gitHostname?: string | undefined;
31
33
  githubApiBaseUrlV3?: string | undefined;
32
34
  githubApiBaseUrlV4?: string | undefined;
@@ -41,6 +43,7 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
41
43
  prTitle?: string | undefined;
42
44
  publishStatusComment?: boolean | undefined;
43
45
  pullNumber?: number | undefined;
46
+ repoForkOwner?: string | undefined;
44
47
  repoName?: string | undefined;
45
48
  repoOwner?: string | undefined;
46
49
  resetAuthor?: boolean | undefined;
@@ -52,7 +55,6 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
52
55
  targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
53
56
  targetBranches?: string[] | undefined;
54
57
  targetPRLabels?: string[] | undefined;
55
- username?: string | undefined;
56
58
  verbose?: boolean | undefined;
57
59
  help?: boolean | undefined;
58
60
  version?: boolean | undefined;
@@ -21,11 +21,14 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
21
21
  gitHostname?: string | undefined;
22
22
  githubApiBaseUrlV3?: string | undefined;
23
23
  githubApiBaseUrlV4?: string | undefined;
24
+ gitAuthorName?: string | undefined;
25
+ gitAuthorEmail?: string | undefined;
24
26
  maxNumber?: number | undefined;
25
27
  multiple?: boolean | undefined;
26
28
  multipleBranches?: boolean | undefined;
27
29
  multipleCommits?: boolean | undefined;
28
30
  noVerify?: boolean | undefined;
31
+ repoForkOwner?: string | undefined;
29
32
  prDescription?: string | undefined;
30
33
  prTitle?: string | undefined;
31
34
  prFilter?: string | undefined;
@@ -35,7 +38,6 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
35
38
  repoOwner?: string | undefined;
36
39
  repoName?: string | undefined;
37
40
  sourceBranch?: string | undefined;
38
- username?: string | undefined;
39
41
  version?: boolean | undefined;
40
42
  v?: boolean | undefined;
41
43
  commitPaths?: string[] | undefined;
@@ -23,11 +23,14 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
23
23
  gitHostname: string;
24
24
  githubApiBaseUrlV3?: string | undefined;
25
25
  githubApiBaseUrlV4?: string | undefined;
26
+ gitAuthorName?: string | undefined;
27
+ gitAuthorEmail?: string | undefined;
26
28
  mainline?: number | undefined;
27
29
  maxNumber: number;
28
30
  multipleBranches: boolean;
29
31
  multipleCommits: boolean;
30
32
  noVerify: boolean;
33
+ repoForkOwner: string;
31
34
  prDescription?: string | undefined;
32
35
  prTitle?: string | undefined;
33
36
  prFilter?: string | undefined;
@@ -35,7 +38,6 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
35
38
  sha?: string | string[] | undefined;
36
39
  resetAuthor: boolean;
37
40
  sourceBranch: string;
38
- username?: string | undefined;
39
41
  dateSince: string | null;
40
42
  dateUntil: string | null;
41
43
  commitPaths: string[];
@@ -64,6 +64,8 @@ async function getOptions(processArgs, optionsFromModule) {
64
64
  const options = {
65
65
  // default author
66
66
  author: optionsFromGithub.authenticatedUsername,
67
+ // default fork owner
68
+ repoForkOwner: optionsFromGithub.authenticatedUsername,
67
69
  // default values have lowest precedence
68
70
  ...defaultConfigOptions,
69
71
  // local config options override default options
@@ -132,11 +134,11 @@ function throwForRequiredOptions(options) {
132
134
  'prDescription',
133
135
  'prFilter',
134
136
  'prTitle',
137
+ 'repoForkOwner',
135
138
  'repoName',
136
139
  'repoOwner',
137
140
  'sha',
138
141
  'sourceBranch',
139
- 'username',
140
142
  ];
141
143
  // Disallow empty strings
142
144
  // this is primarily an issue in Github actions where inputs default to empty strings instead of undefined
@@ -83,7 +83,7 @@ describe('getOptions', () => {
83
83
  });
84
84
  describe('whe option is an empty string', () => {
85
85
  it('throws for "username"', async () => {
86
- await expect(() => (0, options_1.getOptions)([], { username: '', author: 'sqren' })).rejects.toThrowErrorMatchingInlineSnapshot(`"\\"username\\" cannot be empty!"`);
86
+ await expect(() => (0, options_1.getOptions)([], { repoForkOwner: '', author: 'sqren' })).rejects.toThrowErrorMatchingInlineSnapshot(`"\\"repoForkOwner\\" cannot be empty!"`);
87
87
  });
88
88
  it('throws for "author"', async () => {
89
89
  await expect(() => (0, options_1.getOptions)([], { author: '' })).rejects.toThrowErrorMatchingInlineSnapshot(`"\\"author\\" cannot be empty!"`);
@@ -180,6 +180,7 @@ describe('getOptions', () => {
180
180
  multipleCommits: false,
181
181
  noVerify: true,
182
182
  publishStatusComment: true,
183
+ repoForkOwner: 'john.diller',
183
184
  repoName: 'kibana',
184
185
  repoOwner: 'elastic',
185
186
  resetAuthor: false,
@@ -1,6 +1,7 @@
1
1
  import { ValidConfigOptions } from './options/options';
2
2
  import { HandledError } from './services/HandledError';
3
3
  import { Commit } from './services/sourceCommit/parseSourceCommit';
4
+ import { GitConfigAuthor } from './ui/getGitConfigAuthor';
4
5
  export declare type Result = {
5
6
  status: 'success';
6
7
  didUpdate: boolean;
@@ -12,8 +13,9 @@ export declare type Result = {
12
13
  targetBranch: string;
13
14
  error: HandledError;
14
15
  };
15
- export declare function runSequentially({ options, commits, targetBranches, }: {
16
+ export declare function runSequentially({ options, commits, targetBranches, gitConfigAuthor, }: {
16
17
  options: ValidConfigOptions;
17
18
  commits: Commit[];
18
19
  targetBranches: string[];
20
+ gitConfigAuthor?: GitConfigAuthor;
19
21
  }): Promise<Result[]>;
@@ -4,10 +4,8 @@ exports.runSequentially = void 0;
4
4
  const logger_1 = require("./services/logger");
5
5
  const sequentially_1 = require("./services/sequentially");
6
6
  const cherrypickAndCreateTargetPullRequest_1 = require("./ui/cherrypickAndCreateTargetPullRequest");
7
- const maybeSetupRepo_1 = require("./ui/maybeSetupRepo");
8
- async function runSequentially({ options, commits, targetBranches, }) {
7
+ async function runSequentially({ options, commits, targetBranches, gitConfigAuthor, }) {
9
8
  logger_1.logger.verbose('Backport options', options);
10
- await (0, maybeSetupRepo_1.maybeSetupRepo)(options);
11
9
  const results = [];
12
10
  await (0, sequentially_1.sequentially)(targetBranches, async (targetBranch) => {
13
11
  logger_1.logger.info(`Backporting ${JSON.stringify(commits)} to ${targetBranch}`);
@@ -16,6 +14,7 @@ async function runSequentially({ options, commits, targetBranches, }) {
16
14
  options,
17
15
  commits,
18
16
  targetBranch,
17
+ gitConfigAuthor: gitConfigAuthor,
19
18
  });
20
19
  results.push({
21
20
  targetBranch,
@@ -21,14 +21,22 @@ export declare function getRepoInfoFromGitRemotes({ cwd }: {
21
21
  repoOwner: string;
22
22
  repoName: string;
23
23
  }[]>;
24
- export declare function getGitProjectRoot(dir: string): Promise<string | undefined>;
24
+ export declare function getGitProjectRootPath(dir: string): Promise<string | undefined>;
25
25
  export declare function getIsCommitInBranch(options: ValidConfigOptions, commitSha: string): Promise<boolean>;
26
26
  export declare function deleteRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
27
27
  export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
28
28
  export declare function fetchBranch(options: ValidConfigOptions, branch: string): Promise<void>;
29
29
  export declare function getIsMergeCommit(options: ValidConfigOptions, sha: string): Promise<boolean>;
30
30
  export declare function getCommitsInMergeCommit(options: ValidConfigOptions, sha: string): Promise<string[]>;
31
- export declare function cherrypick(options: ValidConfigOptions, sha: string, mergedTargetPullRequest?: ExpectedTargetPullRequest): Promise<{
31
+ export declare function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor, }: {
32
+ options: ValidConfigOptions;
33
+ sha: string;
34
+ mergedTargetPullRequest?: ExpectedTargetPullRequest;
35
+ commitAuthor: {
36
+ name: string;
37
+ email: string;
38
+ };
39
+ }): Promise<{
32
40
  conflictingFiles: {
33
41
  absolute: string;
34
42
  relative: string;
@@ -43,10 +51,10 @@ export declare function getConflictingFiles(options: ValidConfigOptions): Promis
43
51
  relative: string;
44
52
  }[]>;
45
53
  export declare function getUnstagedFiles(options: ValidConfigOptions): Promise<string[]>;
46
- export declare function setCommitAuthor(options: ValidConfigOptions, author: string): Promise<{
47
- stdout: string;
48
- stderr: string;
49
- }>;
54
+ export declare function getGitConfig({ dir, key, }: {
55
+ dir: string;
56
+ key: 'user.name' | 'user.email';
57
+ }): Promise<string | undefined>;
50
58
  export declare function createBackportBranch({ options, targetBranch, backportBranch, }: {
51
59
  options: ValidConfigOptions;
52
60
  targetBranch: string;
@@ -67,4 +75,4 @@ export declare function pushBackportBranch({ options, backportBranch, }: {
67
75
  stdout: string;
68
76
  stderr: string;
69
77
  }>;
70
- export declare function getSourceRepoPath(options: ValidConfigOptions): Promise<string>;
78
+ export declare function getLocalRepoPath(options: ValidConfigOptions): Promise<string | undefined>;
@@ -24,13 +24,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  const promises_1 = require("fs/promises");
26
26
  const make_dir_1 = __importDefault(require("make-dir"));
27
- const nockHelpers_1 = require("../test/nockHelpers");
28
27
  const sandbox_1 = require("../test/sandbox");
29
28
  const childProcess = __importStar(require("./child-process-promisified"));
30
29
  const git_1 = require("./git");
31
30
  const commitFormatters_1 = require("./github/commitFormatters");
32
31
  jest.unmock('del');
33
32
  jest.unmock('make-dir');
33
+ const commitAuthor = { name: 'Soren L', email: 'soren@mail.dk' };
34
34
  describe('git.integration', () => {
35
35
  describe('getIsCommitInBranch', () => {
36
36
  let firstSha;
@@ -117,13 +117,21 @@ describe('git.integration', () => {
117
117
  });
118
118
  it('should not cherrypick commit that already exists', async () => {
119
119
  const shortSha = (0, commitFormatters_1.getShortSha)(firstSha);
120
- return expect(() => (0, git_1.cherrypick)({ dir: sandboxPath }, firstSha)).rejects.toThrowError(`Cherrypick failed because the selected commit (${shortSha}) is empty. Did you already backport this commit?`);
120
+ return expect(() => (0, git_1.cherrypick)({
121
+ options: { dir: sandboxPath },
122
+ sha: firstSha,
123
+ commitAuthor: { name: 'Soren L', email: 'soren@mail.dk' },
124
+ })).rejects.toThrowError(`Cherrypick failed because the selected commit (${shortSha}) is empty. Did you already backport this commit?`);
121
125
  });
122
126
  it('should cherrypick commit cleanly', async () => {
123
127
  const res = await (0, git_1.cherrypick)({
124
- cherrypickRef: false,
125
- dir: sandboxPath,
126
- }, secondSha);
128
+ options: {
129
+ cherrypickRef: false,
130
+ dir: sandboxPath,
131
+ },
132
+ sha: secondSha,
133
+ commitAuthor,
134
+ });
127
135
  expect(res).toEqual({
128
136
  conflictingFiles: [],
129
137
  needsResolving: false,
@@ -134,9 +142,13 @@ describe('git.integration', () => {
134
142
  });
135
143
  it('should cherrypick commit cleanly and append "(cherry picked from commit...)"', async () => {
136
144
  const res = await (0, git_1.cherrypick)({
137
- cherrypickRef: true,
138
- dir: sandboxPath,
139
- }, secondSha);
145
+ options: {
146
+ cherrypickRef: true,
147
+ dir: sandboxPath,
148
+ },
149
+ sha: secondSha,
150
+ commitAuthor,
151
+ });
140
152
  expect(res).toEqual({
141
153
  conflictingFiles: [],
142
154
  needsResolving: false,
@@ -146,14 +158,15 @@ describe('git.integration', () => {
146
158
  expect(message).toEqual(`Update bar.md\n\n(cherry picked from commit ${secondSha})`);
147
159
  });
148
160
  it('should cherrypick commit with conflicts', async () => {
149
- const res = await (0, git_1.cherrypick)({ dir: sandboxPath }, fourthSha);
161
+ const res = await (0, git_1.cherrypick)({
162
+ options: { dir: sandboxPath },
163
+ sha: fourthSha,
164
+ commitAuthor,
165
+ });
150
166
  expect(res).toEqual({
151
167
  needsResolving: true,
152
168
  conflictingFiles: [
153
- {
154
- absolute: `${sandboxPath}/foo.md`,
155
- relative: 'foo.md',
156
- },
169
+ { absolute: `${sandboxPath}/foo.md`, relative: 'foo.md' },
157
170
  ],
158
171
  unstagedFiles: [`${sandboxPath}/foo.md`],
159
172
  });
@@ -186,44 +199,36 @@ describe('git.integration', () => {
186
199
  await expect(() => (0, promises_1.access)(`${backportRepo}/my-file.txt`)).not.toThrowError();
187
200
  });
188
201
  });
189
- describe('getSourceRepoPath', () => {
190
- let sourceRepo;
202
+ describe('getLocalRepoPath', () => {
203
+ let sandboxPath;
191
204
  beforeEach(async () => {
192
- const sandboxPath = (0, sandbox_1.getSandboxPath)({
205
+ sandboxPath = (0, sandbox_1.getSandboxPath)({
193
206
  filename: __filename,
194
- specname: 'getSourceRepoPath',
207
+ specname: 'getLocalRepoPath',
195
208
  });
196
- sourceRepo = `${sandboxPath}/source-repo`;
197
209
  await (0, sandbox_1.resetSandbox)(sandboxPath);
198
- await (0, make_dir_1.default)(sourceRepo);
199
- const execOpts = { cwd: sourceRepo };
210
+ const execOpts = { cwd: sandboxPath };
200
211
  await childProcess.exec(`git init`, execOpts);
201
- await childProcess.exec(`git remote add origin git@github.com:elastic/kibana.git`, execOpts);
202
- mockRepoOwnerAndName({
203
- childRepoOwner: 'sqren',
204
- parentRepoOwner: 'elastic',
205
- repoName: 'kibana',
206
- });
212
+ await childProcess.exec(`git remote add sqren git@github.com:sqren/kibana.git`, execOpts);
213
+ await childProcess.exec(`git remote add elastic git@github.com:elastic/kibana.git`, execOpts);
207
214
  });
208
215
  it('returns local source repo, when one remote matches', async () => {
209
216
  const options = {
210
- accessToken: 'verysecret',
211
217
  repoName: 'kibana',
212
218
  repoOwner: 'elastic',
213
- cwd: sourceRepo,
219
+ cwd: sandboxPath,
214
220
  githubApiBaseUrlV4: 'http://localhost/graphql', // required to mock the response
215
221
  };
216
- expect(await (0, git_1.getSourceRepoPath)(options)).toBe(sourceRepo);
222
+ expect(await (0, git_1.getLocalRepoPath)(options)).toBe(sandboxPath);
217
223
  });
218
- it("returns remote source repo when remotes don't match", async () => {
224
+ it('returns undefined when no remotes match', async () => {
219
225
  const options = {
220
- accessToken: 'verysecret',
221
226
  repoName: 'kibana',
222
227
  repoOwner: 'not-a-match',
223
- cwd: sourceRepo,
228
+ cwd: sandboxPath,
224
229
  githubApiBaseUrlV4: 'http://localhost/graphql', // required to mock the response
225
230
  };
226
- expect(await (0, git_1.getSourceRepoPath)(options)).toBe('https://x-access-token:verysecret@github.com/not-a-match/kibana.git');
231
+ expect(await (0, git_1.getLocalRepoPath)(options)).toBe(undefined);
227
232
  });
228
233
  });
229
234
  describe('when cloning "backport-org/different-merge-strategies"', () => {
@@ -293,28 +298,3 @@ async function getCurrentMessage(execOpts) {
293
298
  const { stdout } = await childProcess.exec('git --no-pager log -1 --pretty=%B', execOpts);
294
299
  return stdout.trim();
295
300
  }
296
- function mockRepoOwnerAndName({ repoName, parentRepoOwner, childRepoOwner, }) {
297
- return (0, nockHelpers_1.mockGqlRequest)({
298
- name: 'RepoOwnerAndName',
299
- statusCode: 200,
300
- body: {
301
- data: {
302
- // @ts-expect-error
303
- repository: {
304
- isFork: !!parentRepoOwner,
305
- name: repoName,
306
- owner: {
307
- login: childRepoOwner,
308
- },
309
- parent: parentRepoOwner
310
- ? {
311
- owner: {
312
- login: parentRepoOwner,
313
- },
314
- }
315
- : null,
316
- },
317
- },
318
- },
319
- });
320
- }