Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
feat(index): Auto add closing keyword to commit
Browse files Browse the repository at this point in the history
This commit allows users to correctly place and invoke the appropriate
keywords in the commit body so that it will autoclose intended issue(s).

The plugin can handle both no issues given and any delimited list of
issue numbers.

This commit also makes a small update to make body commit messages
optional.
  • Loading branch information
erictleung committed Jun 25, 2017
1 parent 81bf29d commit cf69aa7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = {
type: 'input',
name: 'body',
message: dedent`
Give description of what changed and/or why:
Give description of what changed and/or why (optional):
`
}, {
type: 'input',
Expand All @@ -77,7 +77,7 @@ module.exports = {
type: 'input',
name: 'issues',
message: dedent`
List any issues closed by this change:
List any issue(s) closed by this change (e.g. 123, 124):
`
}
]).then(answers => {
Expand All @@ -100,6 +100,15 @@ module.exports = {
// Wrap these lines at 72 characters
const body = wrap(answers.body, wrapOptions);

// Auto-add closing keyword to commit message body
const issueNums = answers.issues.match(/(\d+)/g);
const issues = issueNums == null ?
null :
issueNums.map(function(x) { return "Closes #" + x; })
.reduce(function(acc, val) {
return acc + "\n" + val;
}, "");

// Apply breaking change prefix, removing it if already present
let breaking = answers.breaking.trim();
breaking = breaking ?
Expand All @@ -108,8 +117,6 @@ module.exports = {

breaking = wrap(breaking, wrapOptions);

const issues = wrap(answers.issues, wrapOptions);

// if no breaking or issues filter them out
const footer = [ breaking, issues ].filter(Boolean).join(divider);
commit([ head, body, footer ].join(divider));
Expand Down

0 comments on commit cf69aa7

Please sign in to comment.