Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add signoff option #336

Merged
merged 3 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="[email protected]"',
'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