diff --git a/README.md b/README.md index 2ca5f091..4b127a84 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ The above commands will start an interactive prompt. You can use the `arrow keys | --pr-description | Pull request description suffix | | string | | --pr-title | Pull request title pattern | | string | | --pr | Pull request to backport | | number | +| --resetAuthor | Set yourself as commit author | | boolean | | --sha | Sha of commit to backport | | string | | --upstream | Name of organization and repository | | string | | --username | Github username | | string | diff --git a/src/options/cliArgs.test.ts b/src/options/cliArgs.test.ts index 188b9a06..2ce90600 100644 --- a/src/options/cliArgs.test.ts +++ b/src/options/cliArgs.test.ts @@ -49,6 +49,7 @@ describe('getOptionsFromCliArgs', () => { multipleBranches: true, multipleCommits: false, prTitle: 'myPrTitle', + resetAuthor: false, sha: undefined, upstream: 'sqren/backport-demo', username: 'sqren' diff --git a/src/options/cliArgs.ts b/src/options/cliArgs.ts index a5f68dff..36d2ca38 100644 --- a/src/options/cliArgs.ts +++ b/src/options/cliArgs.ts @@ -97,6 +97,11 @@ export function getOptionsFromCliArgs( type: 'number', alias: 'pr' }) + .option('resetAuthor', { + default: false, + description: 'Set yourself as commit author', + type: 'boolean' + }) .option('sha', { description: 'Commit sha to backport', type: 'string', @@ -135,6 +140,7 @@ export function getOptionsFromCliArgs( prTitle: cliArgs.prTitle, prDescription: cliArgs.prDescription, pullNumber: cliArgs.pullNumber, + resetAuthor: cliArgs.resetAuthor, sha: cliArgs.sha, upstream: cliArgs.upstream, username: cliArgs.username diff --git a/src/options/options.test.ts b/src/options/options.test.ts index 514dfe21..e75a9865 100644 --- a/src/options/options.test.ts +++ b/src/options/options.test.ts @@ -20,6 +20,7 @@ const validOptions: OptionsFromCliArgs = { prDescription: undefined, prTitle: 'myPrTitle', pullNumber: undefined, + resetAuthor: false, sha: undefined, upstream: 'elastic/kibana', username: 'sqren' diff --git a/src/services/git.ts b/src/services/git.ts index 0eeeb40d..8465f3d0 100644 --- a/src/services/git.ts +++ b/src/services/git.ts @@ -103,6 +103,15 @@ export function cherrypick(options: BackportOptions, commitSha: string) { ); } +export function setCommitAuthor(options: BackportOptions, username: string) { + return exec( + `git commit --amend --no-edit --author "${username} <${username}@users.noreply.github.com>"`, + { + cwd: getRepoPath(options) + } + ); +} + export async function isIndexDirty(options: BackportOptions) { try { await exec(`git diff-index --quiet HEAD --`, { diff --git a/src/steps/doBackportVersions.ts b/src/steps/doBackportVersions.ts index aae3c357..cd5e8ead 100644 --- a/src/steps/doBackportVersions.ts +++ b/src/steps/doBackportVersions.ts @@ -10,7 +10,8 @@ import { deleteFeatureBranch, isIndexDirty, pushFeatureBranch, - getRemoteName + getRemoteName, + setCommitAuthor } from '../services/git'; import { confirmPrompt } from '../services/prompts'; import { createPullRequest } from '../services/github/createPullRequest'; @@ -66,6 +67,13 @@ export async function doBackportVersion( cherrypickAndConfirm(options, commit.sha) ); + if (options.resetAuthor) { + await withSpinner( + { text: `Changing author to "${options.username}"` }, + () => setCommitAuthor(options, options.username) + ); + } + const headBranchName = getHeadBranchName(options, featureBranch); await withSpinner({ text: `Pushing branch "${headBranchName}"` }, () => diff --git a/src/steps/steps.test.ts b/src/steps/steps.test.ts index e8334976..02f2dc4b 100644 --- a/src/steps/steps.test.ts +++ b/src/steps/steps.test.ts @@ -46,6 +46,7 @@ describe('run through steps', () => { pullNumber: undefined, repoName: 'kibana', repoOwner: 'elastic', + resetAuthor: false, sha: undefined, username: 'sqren' };