Skip to content

Commit e8c5604

Browse files
committed
feat: add release rule for revert commits
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.
1 parent b0d294b commit e8c5604

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

lib/analyze-commit.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ module.exports = (releaseRules, commit) => {
1515

1616
releaseRules
1717
.filter(
18-
({breaking, release, ...rule}) =>
18+
({breaking, revert, release, ...rule}) =>
1919
// If the rule is not `breaking` or the commit doesn't have a breaking change note
2020
(!breaking || (commit.notes && commit.notes.length > 0)) &&
21+
// If the rule is not `revert` or the commit is not a revert
22+
(!revert || commit.revert) &&
2123
// Otherwise match the regular rules
2224
isMatchWith(
2325
commit,

lib/default-release-rules.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
module.exports = [
77
{breaking: true, release: 'major'},
8+
{revert: true, release: 'patch'},
89
// Angular
910
{type: 'feat', release: 'minor'},
1011
{type: 'fix', release: 'patch'},

test/analyze-commit.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ test('Match breaking change', t => {
99
t.is(analyzeCommit([{breaking: true, release: 'major'}], commit), 'major');
1010
});
1111

12+
test('Match revert commit', t => {
13+
const commit = {
14+
revert: {header: 'Update: First feature', hash: '123'},
15+
};
16+
17+
t.is(analyzeCommit([{revert: true, release: 'patch'}], commit), 'patch');
18+
});
19+
1220
test('Match multiple criteria with breaking change', t => {
1321
const commit = {
1422
type: 'feat',
@@ -18,6 +26,15 @@ test('Match multiple criteria with breaking change', t => {
1826
t.is(analyzeCommit([{type: 'feat', breaking: true, release: 'major'}], commit), 'major');
1927
});
2028

29+
test('Match multiple criteria with revert', t => {
30+
const commit = {
31+
type: 'feat',
32+
revert: {header: 'Update: First feature', hash: '123'},
33+
};
34+
35+
t.is(analyzeCommit([{type: 'feat', revert: true, release: 'major'}], commit), 'major');
36+
});
37+
2138
test('Match multiple criteria', t => {
2239
const commit = {type: 'feat', scope: 'test'};
2340

0 commit comments

Comments
 (0)