Skip to content

Commit

Permalink
feat: added support for git commit --signoff
Browse files Browse the repository at this point in the history
Signed-off-by: mbwhite <whitemat@uk.ibm.com>
  • Loading branch information
mbwhite committed Jan 4, 2024
1 parent bb08644 commit c1bd130
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ commit-and-tag-version --no-verify

If you have your GPG key set up, add the `--sign` or `-s` flag to your `commit-and-tag-version` command.

### Signed-off-by trailer

To add the "Signed-off-by" trailer to the commit message add the `--signedoff` flag to your `commit-and-tag-version` command.

### Lifecycle Scripts

`commit-and-tag-version` supports lifecycle scripts. These allow you to execute your
Expand Down
5 changes: 5 additions & 0 deletions command.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ const yargs = require('yargs')
type: 'boolean',
default: defaults.sign,
})
.option('signedoff', {
describe: 'Should the git commit have a "Signed-off-by" trailer',
type: 'boolean',
default: defaults.signedoff,
})
.option('no-verify', {
alias: 'n',
describe:
Expand Down
1 change: 1 addition & 0 deletions defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const defaults = {
infile: 'CHANGELOG.md',
firstRelease: false,
sign: false,
signedoff: false,
noVerify: false,
commitAll: false,
silent: false,
Expand Down
3 changes: 2 additions & 1 deletion lib/lifecycles/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async function execCommit(args, newVersion) {
let paths = [];
const verify = args.verify === false || args.n ? ['--no-verify'] : [];
const sign = args.sign ? ['-S'] : [];
const signedoff = args.signedoff ? ['--signoff'] : [];
const toAdd = [];

// only start with a pre-populated paths list when CHANGELOG processing is not skipped
Expand Down Expand Up @@ -59,7 +60,7 @@ async function execCommit(args, newVersion) {
await runExecFile(
args,
'git',
['commit'].concat(verify, sign, args.commitAll ? [] : toAdd, [
['commit'].concat(verify, sign, signedoff, args.commitAll ? [] : toAdd, [
'-m',
`${formatCommitMessage(args.releaseCommitMessageFormat, newVersion)}`,
]),
Expand Down
39 changes: 39 additions & 0 deletions test/core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,45 @@ describe('cli', function () {
expect(gitArgs).toHaveLength(0);
});


it('--signedoff adds signed-off-by to the commit message', async function () {
const gitArgs = [
['add', 'CHANGELOG.md', 'package.json', 'package-lock.json'],
[
'commit',
'--signoff',
'CHANGELOG.md',
'package.json',
'package-lock.json',
'-m',
'chore(release): 1.0.1',
],
['tag', '-a', 'v1.0.1', '-m', 'chore(release): 1.0.1'],
['rev-parse', '--abbrev-ref', 'HEAD'],
];

runExecFile.mockImplementation((_args, cmd, cmdArgs) => {
expect(cmd).toEqual('git');

const expected = gitArgs.shift();
expect(cmdArgs).toEqual(expected);

if (expected[0] === 'rev-parse') return Promise.resolve('master');

return Promise.resolve('');
});

mock({
bump: 'patch',
changelog: 'foo\n',
});

await exec('--signedoff', true);
expect(gitArgs).toHaveLength(0);
});



it('--tag-force forces tag replacement', async function () {
const gitArgs = [
['add', 'CHANGELOG.md', 'package.json', 'package-lock.json'],
Expand Down

0 comments on commit c1bd130

Please sign in to comment.