Skip to content

Commit d107e38

Browse files
authored
feat: Add signoff option (#120)
* chore(release): 13.0.0 * feat: added support for git commit --signoff Signed-off-by: mbwhite <[email protected]> --------- Signed-off-by: mbwhite <[email protected]>
1 parent cd0f921 commit d107e38

File tree

6 files changed

+51
-4
lines changed

6 files changed

+51
-4
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ commit-and-tag-version --no-verify
279279

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

282+
### Signed-off-by trailer
283+
284+
To add the "Signed-off-by" trailer to the commit message add the `--signoff` flag to your `commit-and-tag-version` command.
285+
282286
### Lifecycle Scripts
283287

284288
`commit-and-tag-version` supports lifecycle scripts. These allow you to execute your

command.js

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ const yargs = require('yargs')
4848
type: 'boolean',
4949
default: defaults.sign,
5050
})
51+
.option('signoff', {
52+
describe: 'Should the git commit have a "Signed-off-by" trailer',
53+
type: 'boolean',
54+
default: defaults.signoff,
55+
})
5156
.option('no-verify', {
5257
alias: 'n',
5358
describe:

defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const defaults = {
44
infile: 'CHANGELOG.md',
55
firstRelease: false,
66
sign: false,
7+
signoff: false,
78
noVerify: false,
89
commitAll: false,
910
silent: false,

lib/lifecycles/commit.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ async function execCommit(args, newVersion) {
1818
let paths = [];
1919
const verify = args.verify === false || args.n ? ['--no-verify'] : [];
2020
const sign = args.sign ? ['-S'] : [];
21+
const signoff = args.signoff ? ['--signoff'] : [];
2122
const toAdd = [];
2223

2324
// only start with a pre-populated paths list when CHANGELOG processing is not skipped
@@ -59,7 +60,7 @@ async function execCommit(args, newVersion) {
5960
await runExecFile(
6061
args,
6162
'git',
62-
['commit'].concat(verify, sign, args.commitAll ? [] : toAdd, [
63+
['commit'].concat(verify, sign, signoff, args.commitAll ? [] : toAdd, [
6364
'-m',
6465
`${formatCommitMessage(args.releaseCommitMessageFormat, newVersion)}`,
6566
]),

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/core.spec.js

+36
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,42 @@ describe('cli', function () {
14751475
expect(gitArgs).toHaveLength(0);
14761476
});
14771477

1478+
it('--signedoff adds signed-off-by to the commit message', async function () {
1479+
const gitArgs = [
1480+
['add', 'CHANGELOG.md', 'package.json', 'package-lock.json'],
1481+
[
1482+
'commit',
1483+
'--signoff',
1484+
'CHANGELOG.md',
1485+
'package.json',
1486+
'package-lock.json',
1487+
'-m',
1488+
'chore(release): 1.0.1',
1489+
],
1490+
['tag', '-a', 'v1.0.1', '-m', 'chore(release): 1.0.1'],
1491+
['rev-parse', '--abbrev-ref', 'HEAD'],
1492+
];
1493+
1494+
runExecFile.mockImplementation((_args, cmd, cmdArgs) => {
1495+
expect(cmd).toEqual('git');
1496+
1497+
const expected = gitArgs.shift();
1498+
expect(cmdArgs).toEqual(expected);
1499+
1500+
if (expected[0] === 'rev-parse') return Promise.resolve('master');
1501+
1502+
return Promise.resolve('');
1503+
});
1504+
1505+
mock({
1506+
bump: 'patch',
1507+
changelog: 'foo\n',
1508+
});
1509+
1510+
await exec('--signoff', true);
1511+
expect(gitArgs).toHaveLength(0);
1512+
});
1513+
14781514
it('--tag-force forces tag replacement', async function () {
14791515
const gitArgs = [
14801516
['add', 'CHANGELOG.md', 'package.json', 'package-lock.json'],

0 commit comments

Comments
 (0)