Skip to content

Commit

Permalink
fix: ignore empty commit messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Oct 30, 2019
1 parent 6d9c9d0 commit 595c81f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 20 deletions.
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ async function analyzeCommits(pluginConfig, context) {
let releaseType = null;

filter(
commits.map(({message, ...commitProps}) => ({rawMsg: message, message, ...commitProps, ...parser(message, config)}))
commits
.filter(({message, hash}) => {
if (!message.trim()) {
debug('Skip commit %s with empty message', hash);
return false;
}

return true;
})
.map(({message, ...commitProps}) => ({rawMsg: message, message, ...commitProps, ...parser(message, config)}))
).every(({rawMsg, ...commit}) => {
logger.log(`Analyzing commit: %s`, rawMsg);
let commitReleaseType;
Expand Down
69 changes: 50 additions & 19 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ test.beforeEach(t => {
});

test('Parse with "conventional-changelog-angular" by default', async t => {
const commits = [{message: 'fix(scope1): First fix'}, {message: 'feat(scope2): Second feature'}];
const commits = [
{hash: '123', message: 'fix(scope1): First fix'},
{hash: '456', message: 'feat(scope2): Second feature'},
];
const releaseType = await analyzeCommits({}, {cwd, commits, logger: t.context.logger});

t.is(releaseType, 'minor');
Expand All @@ -23,7 +26,10 @@ test('Parse with "conventional-changelog-angular" by default', async t => {
});

test('Accept "preset" option', async t => {
const commits = [{message: 'Fix: First fix (fixes #123)'}, {message: 'Update: Second feature (fixes #456)'}];
const commits = [
{hash: '123', message: 'Fix: First fix (fixes #123)'},
{hash: '456', message: 'Update: Second feature (fixes #456)'},
];
const releaseType = await analyzeCommits({preset: 'eslint'}, {cwd, commits, logger: t.context.logger});

t.is(releaseType, 'minor');
Expand All @@ -35,7 +41,10 @@ test('Accept "preset" option', async t => {
});

test('Accept "config" option', async t => {
const commits = [{message: 'Fix: First fix (fixes #123)'}, {message: 'Update: Second feature (fixes #456)'}];
const commits = [
{hash: '123', message: 'Fix: First fix (fixes #123)'},
{hash: '456', message: 'Update: Second feature (fixes #456)'},
];
const releaseType = await analyzeCommits(
{config: 'conventional-changelog-eslint'},
{cwd, commits, logger: t.context.logger}
Expand All @@ -51,8 +60,8 @@ test('Accept "config" option', async t => {

test('Accept a "parseOpts" object as option', async t => {
const commits = [
{message: '%%BUGFIX%% First fix (fixes #123)'},
{message: '%%FEATURE%% Second feature (fixes #456)'},
{hash: '123', message: '%%BUGFIX%% First fix (fixes #123)'},
{hash: '456', message: '%%FEATURE%% Second feature (fixes #456)'},
];
const releaseType = await analyzeCommits(
{parserOpts: {headerPattern: /^%%(.*?)%% (.*)$/, headerCorrespondence: ['tag', 'shortDesc']}},
Expand All @@ -68,7 +77,10 @@ test('Accept a "parseOpts" object as option', async t => {
});

test('Accept a partial "parseOpts" object as option', async t => {
const commits = [{message: '%%fix%% First fix (fixes #123)'}, {message: '%%Update%% Second feature (fixes #456)'}];
const commits = [
{hash: '123', message: '%%fix%% First fix (fixes #123)'},
{hash: '456', message: '%%Update%% Second feature (fixes #456)'},
];
const releaseType = await analyzeCommits(
{
config: 'conventional-changelog-eslint',
Expand Down Expand Up @@ -100,7 +112,10 @@ test('Exclude commits if they have a matching revert commits', async t => {
});

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 commits = [
{hash: '123', message: 'fix(scope1): First fix'},
{hash: '456', message: 'feat(scope2): Second feature'},
];
const releaseType = await analyzeCommits(
{releaseRules: './test/fixtures/release-rules'},
{cwd, commits, logger: t.context.logger}
Expand All @@ -116,8 +131,8 @@ test('Accept a "releaseRules" option that reference a requierable module', async

test('Return "major" if there is a breaking change, using default releaseRules', async t => {
const commits = [
{message: 'Fix: First fix (fixes #123)'},
{message: 'Update: Second feature (fixes #456) \n\n BREAKING CHANGE: break something'},
{hash: '123', message: 'Fix: First fix (fixes #123)'},
{hash: '456', message: 'Update: Second feature (fixes #456) \n\n BREAKING CHANGE: break something'},
];
const releaseType = await analyzeCommits({preset: 'eslint'}, {cwd, commits, logger: t.context.logger});

Expand All @@ -130,7 +145,10 @@ test('Return "major" if there is a breaking change, using default releaseRules',
});

test('Return "patch" if there is only types set to "patch", using default releaseRules', async t => {
const commits = [{message: 'fix: First fix (fixes #123)'}, {message: 'perf: perf improvement'}];
const commits = [
{hash: '123', message: 'fix: First fix (fixes #123)'},
{hash: '456', message: 'perf: perf improvement'},
];
const releaseType = await analyzeCommits({}, {cwd, commits, logger: t.context.logger});

t.is(releaseType, 'patch');
Expand All @@ -142,7 +160,10 @@ test('Return "patch" if there is only types set to "patch", using default releas
});

test('Allow to use regex in "releaseRules" configuration', async t => {
const commits = [{message: 'Chore: First chore (fixes #123)'}, {message: 'Docs: update README (fixes #456)'}];
const commits = [
{hash: '123', message: 'Chore: First chore (fixes #123)'},
{hash: '456', message: 'Docs: update README (fixes #456)'},
];
const releaseType = await analyzeCommits(
{preset: 'eslint', releaseRules: [{tag: 'Chore', release: 'patch'}, {message: '/README/', release: 'minor'}]},
{cwd, commits, logger: t.context.logger}
Expand All @@ -157,7 +178,7 @@ test('Allow to use regex in "releaseRules" configuration', async t => {
});

test('Return "null" if no rule match', async t => {
const commits = [{message: 'doc: doc update'}, {message: 'chore: Chore'}];
const commits = [{hash: '123', message: 'doc: doc update'}, {hash: '456', message: 'chore: Chore'}];
const releaseType = await analyzeCommits({}, {cwd, commits, logger: t.context.logger});

t.is(releaseType, null);
Expand All @@ -169,7 +190,10 @@ test('Return "null" if no rule match', async t => {
});

test('Process rules in order and apply highest match', async t => {
const commits = [{message: 'Chore: First chore (fixes #123)'}, {message: 'Docs: update README (fixes #456)'}];
const commits = [
{hash: '123', message: 'Chore: First chore (fixes #123)'},
{hash: '456', message: 'Docs: update README (fixes #456)'},
];
const releaseType = await analyzeCommits(
{preset: 'eslint', releaseRules: [{tag: 'Chore', release: 'minor'}, {tag: 'Chore', release: 'patch'}]},
{cwd, commits, logger: t.context.logger}
Expand All @@ -185,8 +209,8 @@ test('Process rules in order and apply highest match', async t => {

test('Process rules in order and apply highest match from config even if default has an higher match', async t => {
const commits = [
{message: 'Chore: First chore (fixes #123)'},
{message: 'Docs: update README (fixes #456) \n\n BREAKING CHANGE: break something'},
{hash: '123', message: 'Chore: First chore (fixes #123)'},
{hash: '456', message: 'Docs: update README (fixes #456) \n\n BREAKING CHANGE: break something'},
];
const releaseType = await analyzeCommits(
{preset: 'eslint', releaseRules: [{tag: 'Chore', release: 'patch'}, {breaking: true, release: 'minor'}]},
Expand All @@ -202,7 +226,7 @@ test('Process rules in order and apply highest match from config even if default
});

test('Allow to overwrite default "releaseRules" with "false"', async t => {
const commits = [{message: 'chore: First chore'}, {message: 'feat: new feature'}];
const commits = [{hash: '123', message: 'chore: First chore'}, {hash: '456', message: 'feat: new feature'}];
const releaseType = await analyzeCommits(
{preset: 'angular', releaseRules: [{type: 'feat', release: false}]},
{cwd, commits, logger: t.context.logger}
Expand All @@ -217,7 +241,7 @@ test('Allow to overwrite default "releaseRules" with "false"', async t => {
});

test('Commits with an associated custom release type have higher priority than commits with release "false"', async t => {
const commits = [{message: 'feat: Feature to skip'}, {message: 'docs: update README'}];
const commits = [{hash: '123', message: 'feat: Feature to skip'}, {hash: '456', message: 'docs: update README'}];
const releaseType = await analyzeCommits(
{preset: 'angular', releaseRules: [{type: 'feat', release: false}, {type: 'docs', release: 'patch'}]},
{cwd, commits, logger: t.context.logger}
Expand All @@ -232,7 +256,7 @@ test('Commits with an associated custom release type have higher priority than c
});

test('Commits with an associated default release type have higher priority than commits with release "false"', async t => {
const commits = [{message: 'feat: new feature'}, {message: 'fix: new Fix'}];
const commits = [{hash: '123', message: 'feat: new feature'}, {hash: '456', message: 'fix: new Fix'}];
const releaseType = await analyzeCommits(
{preset: 'angular', releaseRules: [{type: 'feat', release: false}]},
{cwd, commits, logger: t.context.logger}
Expand All @@ -247,7 +271,7 @@ test('Commits with an associated default release type have higher priority than
});

test('Use default "releaseRules" if none of provided match', async t => {
const commits = [{message: 'Chore: First chore'}, {message: 'Update: new feature'}];
const commits = [{hash: '123', message: 'Chore: First chore'}, {hash: '456', message: 'Update: new feature'}];
const releaseType = await analyzeCommits(
{preset: 'eslint', releaseRules: [{tag: 'Chore', release: 'patch'}]},
{cwd, commits, logger: t.context.logger}
Expand All @@ -261,6 +285,13 @@ test('Use default "releaseRules" if none of provided match', async t => {
t.true(t.context.log.calledWith('Analysis of %s commits complete: %s release', 2, 'minor'));
});

test('Filter out empty commits', async t => {
const commits = [{hash: '123', message: ''}, {hash: '456', message: 'fix(scope1): First fix'}];
const releaseType = await analyzeCommits({}, {cwd, commits, logger: t.context.logger});

t.is(releaseType, 'patch');
});

test('Throw error if "preset" doesn`t exist', async t => {
await t.throwsAsync(analyzeCommits({preset: 'unknown-preset'}, {cwd}), {code: 'MODULE_NOT_FOUND'});
});
Expand Down

0 comments on commit 595c81f

Please sign in to comment.