Skip to content

Commit

Permalink
feat: add release rule for revert commits
Browse files Browse the repository at this point in the history
If a revert commit is analyzed (without the reverted commit being part of the commit group) it will now trigger a `patch` release by default.
  • Loading branch information
pvdlg committed Jul 10, 2018
1 parent b0d294b commit e8c5604
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/analyze-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ module.exports = (releaseRules, commit) => {

releaseRules
.filter(
({breaking, release, ...rule}) =>
({breaking, revert, release, ...rule}) =>
// If the rule is not `breaking` or the commit doesn't have a breaking change note
(!breaking || (commit.notes && commit.notes.length > 0)) &&
// If the rule is not `revert` or the commit is not a revert
(!revert || commit.revert) &&
// Otherwise match the regular rules
isMatchWith(
commit,
Expand Down
1 change: 1 addition & 0 deletions lib/default-release-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
module.exports = [
{breaking: true, release: 'major'},
{revert: true, release: 'patch'},
// Angular
{type: 'feat', release: 'minor'},
{type: 'fix', release: 'patch'},
Expand Down
17 changes: 17 additions & 0 deletions test/analyze-commit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ test('Match breaking change', t => {
t.is(analyzeCommit([{breaking: true, release: 'major'}], commit), 'major');
});

test('Match revert commit', t => {
const commit = {
revert: {header: 'Update: First feature', hash: '123'},
};

t.is(analyzeCommit([{revert: true, release: 'patch'}], commit), 'patch');
});

test('Match multiple criteria with breaking change', t => {
const commit = {
type: 'feat',
Expand All @@ -18,6 +26,15 @@ test('Match multiple criteria with breaking change', t => {
t.is(analyzeCommit([{type: 'feat', breaking: true, release: 'major'}], commit), 'major');
});

test('Match multiple criteria with revert', t => {
const commit = {
type: 'feat',
revert: {header: 'Update: First feature', hash: '123'},
};

t.is(analyzeCommit([{type: 'feat', revert: true, release: 'major'}], commit), 'major');
});

test('Match multiple criteria', t => {
const commit = {type: 'feat', scope: 'test'};

Expand Down

0 comments on commit e8c5604

Please sign in to comment.