Skip to content

Commit

Permalink
Add —reset-author flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Sep 1, 2019
1 parent eb8ef38 commit 3d28d41
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
1 change: 1 addition & 0 deletions src/options/cliArgs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('getOptionsFromCliArgs', () => {
multipleBranches: true,
multipleCommits: false,
prTitle: 'myPrTitle',
resetAuthor: false,
sha: undefined,
upstream: 'sqren/backport-demo',
username: 'sqren'
Expand Down
6 changes: 6 additions & 0 deletions src/options/cliArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/options/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const validOptions: OptionsFromCliArgs = {
prDescription: undefined,
prTitle: 'myPrTitle',
pullNumber: undefined,
resetAuthor: false,
sha: undefined,
upstream: 'elastic/kibana',
username: 'sqren'
Expand Down
9 changes: 9 additions & 0 deletions src/services/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 --`, {
Expand Down
10 changes: 9 additions & 1 deletion src/steps/doBackportVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}"` }, () =>
Expand Down
1 change: 1 addition & 0 deletions src/steps/steps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('run through steps', () => {
pullNumber: undefined,
repoName: 'kibana',
repoOwner: 'elastic',
resetAuthor: false,
sha: undefined,
username: 'sqren'
};
Expand Down

0 comments on commit 3d28d41

Please sign in to comment.