Skip to content

Commit

Permalink
Add signoff option (#336)
Browse files Browse the repository at this point in the history
Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
  • Loading branch information
iliapolo and sorenlouv authored Apr 15, 2022
1 parent 1695055 commit 0d81e2a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/lib/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,35 @@ describe('cherrypick', () => {
]);
});

it('should use signoff option when specified', async () => {
const spawnSpy = jest
.spyOn(childProcess, 'spawnPromise')
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock getIsMergeCommit(...)
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock cherrypick(...)

await cherrypick({
options: { ...options, signoff: true },
sha: 'abcd',
commitAuthor,
});

const args = spawnSpy.mock.calls[1];
expect(args).toEqual([
'git',
[
'-c',
'user.name="Soren L"',
'-c',
'user.email="soren@mail.dk"',
'cherry-pick',
'-x',
'--signoff',
'abcd',
],
'/myHomeDir/.backport/repositories/elastic/kibana',
]);
});

it('should return `needsResolving: true` upon cherrypick error', async () => {
jest
.spyOn(childProcess, 'spawnPromise')
Expand Down
1 change: 1 addition & 0 deletions src/lib/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ export async function cherrypick({
? ['--mainline', `${options.mainline}`]
: []),
...(options.cherrypickRef === false ? [] : ['-x']),
...(options.signoff ? ['--signoff'] : []),
shaOrRange,
];

Expand Down
1 change: 1 addition & 0 deletions src/options/ConfigOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Options = Partial<{
targetBranchChoices: TargetBranchChoiceOrString[];
targetBranches: string[];
targetPRLabels: string[];
signoff: boolean;
}>;

export type ConfigFileOptions = Options &
Expand Down
6 changes: 6 additions & 0 deletions src/options/cliArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ export function getOptionsFromCliArgs(processArgs: readonly string[]) {
},
})

.option('signoff', {
description: 'Pass the --signoff option to the cherry-pick command',
type: 'boolean',
alias: ['s'],
})

// display 10 commits to pick from
.option('maxNumber', {
description: 'Number of commits to choose from',
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 @@ -234,6 +234,7 @@ describe('getOptions', () => {
repoOwner: 'elastic',
resetAuthor: false,
reviewers: [],
signoff: false,
sourceBranch: 'default-branch-from-github',
sourcePRLabels: [],
targetBranchChoices: ['7.9', '8.0'],
Expand Down
1 change: 1 addition & 0 deletions src/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const defaultConfigOptions = {
targetBranchChoices: [] as TargetBranchChoiceOrString[],
targetBranches: [] as string[],
targetPRLabels: [] as string[],
signoff: false,
};

export async function getOptions({
Expand Down
2 changes: 2 additions & 0 deletions src/test/e2e/cli/entrypoint.cli.private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ describe('entrypoint cli', () => {
--ls List commits instead of backporting them [boolean]
--mainline Parent id of merge commit. Defaults to 1 when supplied
without arguments [number]
-s, --signoff Pass the --signoff option to the cherry-pick command
[boolean]
-n, --maxNumber, --number Number of commits to choose from [number]
--multiple Select multiple branches/commits [boolean]
--multipleBranches Backport to multiple branches [boolean]
Expand Down

0 comments on commit 0d81e2a

Please sign in to comment.