Skip to content

Commit b0d294b

Browse files
committed
feat: exclude commit from analysis if they have a matching revert commit
If multiple commits are analyzed at the same time, and one revert another, they will be both ignored. As those commits do not change code within the group of analyzed commits they shouldn't trigger a release.
1 parent a6d0538 commit b0d294b

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const parser = require('conventional-commits-parser').sync;
2+
const filter = require('conventional-commits-filter');
23
const debug = require('debug')('semantic-release:commit-analyzer');
34
const loadParserConfig = require('./lib/load-parser-config');
45
const loadReleaseRules = require('./lib/load-release-rules');
@@ -25,9 +26,10 @@ async function commitAnalyzer(pluginConfig, {commits, logger}) {
2526
const config = await loadParserConfig(pluginConfig);
2627
let releaseType = null;
2728

28-
commits.every(rawCommit => {
29-
const commit = parser(rawCommit.message, config);
30-
logger.log(`Analyzing commit: %s`, rawCommit.message);
29+
filter(
30+
commits.map(({message, ...commitProps}) => ({rawMsg: message, message, ...commitProps, ...parser(message, config)}))
31+
).every(({rawMsg, ...commit}) => {
32+
logger.log(`Analyzing commit: %s`, rawMsg);
3133
let commitReleaseType;
3234

3335
// Determine release type based on custom releaseRules

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"dependencies": {
1919
"conventional-changelog-angular": "^5.0.0",
20+
"conventional-commits-filter": "^2.0.0",
2021
"conventional-commits-parser": "^3.0.0",
2122
"debug": "^3.1.0",
2223
"import-from": "^2.1.0",

test/integration.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ test('Accept a partial "parseOpts" object as option', async t => {
8383
t.true(t.context.log.calledWith('Analysis of %s commits complete: %s release', 2, 'patch'));
8484
});
8585

86+
test('Exclude commits if they have a matching revert commits', async t => {
87+
const commits = [
88+
{hash: '123', message: 'feat(scope): First feature'},
89+
{hash: '456', message: 'revert: feat(scope): First feature\n\nThis reverts commit 123.\n'},
90+
{message: 'fix(scope): First fix'},
91+
];
92+
const releaseType = await commitAnalyzer({}, {commits, logger: t.context.logger});
93+
94+
t.is(releaseType, 'patch');
95+
t.true(t.context.log.calledWith('Analyzing commit: %s', commits[2].message));
96+
t.true(t.context.log.calledWith('The release type for the commit is %s', 'patch'));
97+
t.true(t.context.log.calledWith('Analysis of %s commits complete: %s release', 3, 'patch'));
98+
});
99+
86100
test('Accept a "releaseRules" option that reference a requierable module', async t => {
87101
const commits = [{message: 'fix(scope1): First fix'}, {message: 'feat(scope2): Second feature'}];
88102
const releaseType = await commitAnalyzer(

0 commit comments

Comments
 (0)