backport 7.3.0-beta.1 → 7.3.2-beta.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 (36) hide show
  1. package/README.md +3 -1
  2. package/bin/backport +2 -0
  3. package/dist/backportRun.js +12 -1
  4. package/dist/options/ConfigOptions.d.ts +3 -3
  5. package/dist/options/cliArgs.d.ts +3 -1
  6. package/dist/options/cliArgs.js +16 -7
  7. package/dist/options/config/config.d.ts +3 -3
  8. package/dist/options/config/readConfigFile.d.ts +3 -3
  9. package/dist/options/options.d.ts +3 -3
  10. package/dist/options/options.js +3 -1
  11. package/dist/options/options.test.js +2 -1
  12. package/dist/runSequentially.d.ts +3 -1
  13. package/dist/runSequentially.js +2 -3
  14. package/dist/services/git.d.ts +9 -10
  15. package/dist/services/git.integration.test.js +26 -12
  16. package/dist/services/git.js +6 -29
  17. package/dist/services/git.test.js +44 -16
  18. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +4 -5
  19. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +1 -1
  20. package/dist/test/e2e/cli/cli.private.test.js +6 -2
  21. package/dist/test/e2e/cli/commit-author.private.test.d.ts +1 -0
  22. package/dist/test/e2e/cli/commit-author.private.test.js +96 -0
  23. package/dist/test/e2e/module/module.mutation.test.d.ts +1 -0
  24. package/dist/test/e2e/module/module.mutation.test.js +369 -0
  25. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +3 -1
  26. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +26 -7
  27. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +14 -11
  28. package/dist/ui/getGitConfigAuthor.d.ts +6 -0
  29. package/dist/ui/getGitConfigAuthor.js +15 -0
  30. package/dist/ui/setupRepo.d.ts +1 -2
  31. package/dist/ui/setupRepo.js +4 -36
  32. package/dist/ui/setupRepo.test.js +11 -63
  33. package/dist/utils/packageVersion.d.ts +1 -1
  34. package/dist/utils/packageVersion.js +1 -1
  35. package/package.json +7 -6
  36. package/yarn.lock +58 -78
package/README.md CHANGED
@@ -53,6 +53,7 @@ Add a [project config](https://github.com/sqren/backport/blob/master/docs/config
53
53
  ```
54
54
 
55
55
  Add personal access token to [global config](https://github.com/sqren/backport/blob/master/docs/configuration.md#global-config-backportconfigjson):
56
+
56
57
  ```js
57
58
  // ~/.backport/config.json
58
59
  {
@@ -77,7 +78,7 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config
77
78
  | Option | Shorthand notation | Description | Default |
78
79
  | ------------------- | ------------------ | -------------------------------------------------------------------------- | ------------------------- |
79
80
  | --access-token | | Github access token | |
80
- | --all | -a | Show commits from any author | false |
81
+ | --all | -a | Show commits from any author. Opposite of `--author` | false |
81
82
  | --assignee | --assign | Assign users to the target PR | |
82
83
  | --author | | Filter commits by Github username. Opposite of `--all` | _Current user_ |
83
84
  | --auto-assign | | Assign current user to the target PR | false |
@@ -102,6 +103,7 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config
102
103
  | --pr-filter | | Find PRs using [Github's search syntax][2] | |
103
104
  | --pr-title | --title | Title of pull request | |
104
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_ |
105
107
  | --repo-name | | Name of repository | |
106
108
  | --repo-owner | | Owner of repository | |
107
109
  | --reset-author | | Set yourself as commit author | |
package/bin/backport ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('../dist/entrypoint.cli.js')
@@ -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',
@@ -27,11 +27,11 @@ 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;
33
- gitUserEmail: string;
34
- gitUserName: string;
35
35
  logFilePath: string;
36
36
  maxNumber: number;
37
37
  multiple: boolean;
@@ -43,6 +43,7 @@ declare type Options = Partial<{
43
43
  prTitle: string;
44
44
  publishStatusComment: boolean;
45
45
  pullNumber: number;
46
+ repoForkOwner: string;
46
47
  repoName: string;
47
48
  repoOwner: string;
48
49
  resetAuthor: boolean;
@@ -54,7 +55,6 @@ declare type Options = Partial<{
54
55
  targetBranchChoices: TargetBranchChoiceOrString[];
55
56
  targetBranches: string[];
56
57
  targetPRLabels: string[];
57
- username: string;
58
58
  verbose: boolean;
59
59
  }>;
60
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,11 +27,11 @@ 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;
33
- gitUserEmail?: string | undefined;
34
- gitUserName?: string | undefined;
35
35
  logFilePath?: string | undefined;
36
36
  maxNumber?: number | undefined;
37
37
  multiple?: boolean | undefined;
@@ -43,6 +43,7 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
43
43
  prTitle?: string | undefined;
44
44
  publishStatusComment?: boolean | undefined;
45
45
  pullNumber?: number | undefined;
46
+ repoForkOwner?: string | undefined;
46
47
  repoName?: string | undefined;
47
48
  repoOwner?: string | undefined;
48
49
  resetAuthor?: boolean | undefined;
@@ -54,7 +55,6 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
54
55
  targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
55
56
  targetBranches?: string[] | undefined;
56
57
  targetPRLabels?: string[] | undefined;
57
- username?: string | undefined;
58
58
  verbose?: boolean | undefined;
59
59
  help?: boolean | undefined;
60
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;
@@ -52,7 +54,5 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
52
54
  targetBranch: string;
53
55
  }) => boolean | Promise<boolean>) | undefined;
54
56
  backportBinary?: string | undefined;
55
- gitUserEmail?: string | undefined;
56
- gitUserName?: string | undefined;
57
57
  branchLabelMapping?: Record<string, string> | undefined;
58
58
  };
@@ -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[];
@@ -52,8 +54,6 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
52
54
  targetBranch: string;
53
55
  }) => boolean | Promise<boolean>) | undefined;
54
56
  backportBinary: string;
55
- gitUserEmail?: string | undefined;
56
- gitUserName?: string | undefined;
57
57
  multiple?: boolean | undefined;
58
58
  help?: boolean | undefined;
59
59
  version?: boolean | undefined;
@@ -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 setupRepo_1 = require("./ui/setupRepo");
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, setupRepo_1.setupRepo)(options, commits);
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,
@@ -28,7 +28,15 @@ export declare function addRemote(options: ValidConfigOptions, remoteName: strin
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,19 +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
- }>;
50
54
  export declare function getGitConfig({ dir, key, }: {
51
55
  dir: string;
52
56
  key: 'user.name' | 'user.email';
53
57
  }): Promise<string | undefined>;
54
- export declare function setGitConfig({ dir, key, value, }: {
55
- dir: string;
56
- key: 'user.name' | 'user.email';
57
- value: string;
58
- }): Promise<void>;
59
58
  export declare function createBackportBranch({ options, targetBranch, backportBranch, }: {
60
59
  options: ValidConfigOptions;
61
60
  targetBranch: string;
@@ -30,6 +30,7 @@ const git_1 = require("./git");
30
30
  const commitFormatters_1 = require("./github/commitFormatters");
31
31
  jest.unmock('del');
32
32
  jest.unmock('make-dir');
33
+ const commitAuthor = { name: 'Soren L', email: 'soren@mail.dk' };
33
34
  describe('git.integration', () => {
34
35
  describe('getIsCommitInBranch', () => {
35
36
  let firstSha;
@@ -116,13 +117,21 @@ describe('git.integration', () => {
116
117
  });
117
118
  it('should not cherrypick commit that already exists', async () => {
118
119
  const shortSha = (0, commitFormatters_1.getShortSha)(firstSha);
119
- 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?`);
120
125
  });
121
126
  it('should cherrypick commit cleanly', async () => {
122
127
  const res = await (0, git_1.cherrypick)({
123
- cherrypickRef: false,
124
- dir: sandboxPath,
125
- }, secondSha);
128
+ options: {
129
+ cherrypickRef: false,
130
+ dir: sandboxPath,
131
+ },
132
+ sha: secondSha,
133
+ commitAuthor,
134
+ });
126
135
  expect(res).toEqual({
127
136
  conflictingFiles: [],
128
137
  needsResolving: false,
@@ -133,9 +142,13 @@ describe('git.integration', () => {
133
142
  });
134
143
  it('should cherrypick commit cleanly and append "(cherry picked from commit...)"', async () => {
135
144
  const res = await (0, git_1.cherrypick)({
136
- cherrypickRef: true,
137
- dir: sandboxPath,
138
- }, secondSha);
145
+ options: {
146
+ cherrypickRef: true,
147
+ dir: sandboxPath,
148
+ },
149
+ sha: secondSha,
150
+ commitAuthor,
151
+ });
139
152
  expect(res).toEqual({
140
153
  conflictingFiles: [],
141
154
  needsResolving: false,
@@ -145,14 +158,15 @@ describe('git.integration', () => {
145
158
  expect(message).toEqual(`Update bar.md\n\n(cherry picked from commit ${secondSha})`);
146
159
  });
147
160
  it('should cherrypick commit with conflicts', async () => {
148
- 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
+ });
149
166
  expect(res).toEqual({
150
167
  needsResolving: true,
151
168
  conflictingFiles: [
152
- {
153
- absolute: `${sandboxPath}/foo.md`,
154
- relative: 'foo.md',
155
- },
169
+ { absolute: `${sandboxPath}/foo.md`, relative: 'foo.md' },
156
170
  ],
157
171
  unstagedFiles: [`${sandboxPath}/foo.md`],
158
172
  });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLocalRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setGitConfig = exports.getGitConfig = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.getCommitsInMergeCommit = exports.getIsMergeCommit = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRootPath = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
3
+ exports.getLocalRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.getGitConfig = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.getCommitsInMergeCommit = exports.getIsMergeCommit = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRootPath = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
4
4
  const path_1 = require("path");
5
5
  const lodash_1 = require("lodash");
6
6
  const ora_1 = require("../ui/ora");
@@ -180,7 +180,7 @@ async function getCommitsInMergeCommit(options, sha) {
180
180
  }
181
181
  }
182
182
  exports.getCommitsInMergeCommit = getCommitsInMergeCommit;
183
- async function cherrypick(options, sha, mergedTargetPullRequest) {
183
+ async function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor, }) {
184
184
  const mainlinArg = options.mainline != undefined ? ` --mainline ${options.mainline}` : '';
185
185
  const cherrypickRefArg = options.cherrypickRef === false ? '' : ' -x';
186
186
  let shaOrRange = sha;
@@ -200,7 +200,7 @@ async function cherrypick(options, sha, mergedTargetPullRequest) {
200
200
  }
201
201
  }
202
202
  }
203
- const cmd = `git cherry-pick${cherrypickRefArg}${mainlinArg} ${shaOrRange}`;
203
+ const cmd = `git -c user.name="${commitAuthor.name}" -c user.email="${commitAuthor.email}" cherry-pick${cherrypickRefArg}${mainlinArg} ${shaOrRange}`;
204
204
  try {
205
205
  await (0, child_process_promisified_1.exec)(cmd, { cwd: (0, env_1.getRepoPath)(options) });
206
206
  return { conflictingFiles: [], unstagedFiles: [], needsResolving: false };
@@ -219,12 +219,12 @@ async function cherrypick(options, sha, mergedTargetPullRequest) {
219
219
  }
220
220
  // git info missing
221
221
  if (e.message.includes('Please tell me who you are')) {
222
- throw new HandledError_1.HandledError(`Cherrypick failed:\n${e.message}`);
222
+ throw new HandledError_1.HandledError(e.message);
223
223
  }
224
224
  if (e.message.includes(`bad object ${sha}`)) {
225
225
  throw new HandledError_1.HandledError(`Cherrypick failed because commit "${sha}" was not found`);
226
226
  }
227
- const isCherryPickError = e.cmd === cmd;
227
+ const isCherryPickError = e.cmd?.includes('cherry-pick') && e.code > 0;
228
228
  if (isCherryPickError) {
229
229
  const [conflictingFiles, unstagedFiles] = await Promise.all([
230
230
  getConflictingFiles(options),
@@ -306,19 +306,6 @@ async function getUnstagedFiles(options) {
306
306
  return (0, lodash_1.uniq)(files);
307
307
  }
308
308
  exports.getUnstagedFiles = getUnstagedFiles;
309
- async function setCommitAuthor(options, author) {
310
- const spinner = (0, ora_1.ora)(options.ci, `Changing author to "${author}"`).start();
311
- try {
312
- const res = await (0, child_process_promisified_1.exec)(`git commit --amend --no-edit --author "${author} <${author}@users.noreply.github.com>"`, { cwd: (0, env_1.getRepoPath)(options) });
313
- spinner.succeed();
314
- return res;
315
- }
316
- catch (e) {
317
- spinner.fail();
318
- throw e;
319
- }
320
- }
321
- exports.setCommitAuthor = setCommitAuthor;
322
309
  async function getGitConfig({ dir, key, }) {
323
310
  try {
324
311
  const res = await (0, child_process_promisified_1.exec)(`git config ${key}`, { cwd: dir });
@@ -329,16 +316,6 @@ async function getGitConfig({ dir, key, }) {
329
316
  }
330
317
  }
331
318
  exports.getGitConfig = getGitConfig;
332
- async function setGitConfig({ dir, key, value, }) {
333
- try {
334
- await (0, child_process_promisified_1.exec)(`git config ${key} ${value}`, { cwd: dir });
335
- }
336
- catch (e) {
337
- logger_1.logger.error(`Could not set git config: ${key}=${value}`, e);
338
- return;
339
- }
340
- }
341
- exports.setGitConfig = setGitConfig;
342
319
  // How the commit flows:
343
320
  // ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
344
321
  // master -> backport/7.x/pr-1234 -> 7.x
@@ -370,7 +347,7 @@ exports.deleteBackportBranch = deleteBackportBranch;
370
347
  * Returns the repo owner of the forked repo or the source repo
371
348
  */
372
349
  function getRepoForkOwner(options) {
373
- return options.fork ? options.authenticatedUsername : options.repoOwner;
350
+ return options.fork ? options.repoForkOwner : options.repoOwner;
374
351
  }
375
352
  exports.getRepoForkOwner = getRepoForkOwner;
376
353
  async function pushBackportBranch({ options, backportBranch, }) {