Skip to content

Commit

Permalink
feat: exclude commit from analysis if they have a matching revert commit
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pvdlg committed Jul 10, 2018
1 parent a6d0538 commit b0d294b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const parser = require('conventional-commits-parser').sync;
const filter = require('conventional-commits-filter');
const debug = require('debug')('semantic-release:commit-analyzer');
const loadParserConfig = require('./lib/load-parser-config');
const loadReleaseRules = require('./lib/load-release-rules');
Expand All @@ -25,9 +26,10 @@ async function commitAnalyzer(pluginConfig, {commits, logger}) {
const config = await loadParserConfig(pluginConfig);
let releaseType = null;

commits.every(rawCommit => {
const commit = parser(rawCommit.message, config);
logger.log(`Analyzing commit: %s`, rawCommit.message);
filter(
commits.map(({message, ...commitProps}) => ({rawMsg: message, message, ...commitProps, ...parser(message, config)}))
).every(({rawMsg, ...commit}) => {
logger.log(`Analyzing commit: %s`, rawMsg);
let commitReleaseType;

// Determine release type based on custom releaseRules
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"dependencies": {
"conventional-changelog-angular": "^5.0.0",
"conventional-commits-filter": "^2.0.0",
"conventional-commits-parser": "^3.0.0",
"debug": "^3.1.0",
"import-from": "^2.1.0",
Expand Down
14 changes: 14 additions & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ test('Accept a partial "parseOpts" object as option', async t => {
t.true(t.context.log.calledWith('Analysis of %s commits complete: %s release', 2, 'patch'));
});

test('Exclude commits if they have a matching revert commits', async t => {
const commits = [
{hash: '123', message: 'feat(scope): First feature'},
{hash: '456', message: 'revert: feat(scope): First feature\n\nThis reverts commit 123.\n'},
{message: 'fix(scope): First fix'},
];
const releaseType = await commitAnalyzer({}, {commits, logger: t.context.logger});

t.is(releaseType, 'patch');
t.true(t.context.log.calledWith('Analyzing commit: %s', commits[2].message));
t.true(t.context.log.calledWith('The release type for the commit is %s', 'patch'));
t.true(t.context.log.calledWith('Analysis of %s commits complete: %s release', 3, 'patch'));
});

test('Accept a "releaseRules" option that reference a requierable module', async t => {
const commits = [{message: 'fix(scope1): First fix'}, {message: 'feat(scope2): Second feature'}];
const releaseType = await commitAnalyzer(
Expand Down

0 comments on commit b0d294b

Please sign in to comment.