Skip to content

Commit 763f0b2

Browse files
committed
fix: filter out commits with empty message
1 parent 99e861e commit 763f0b2

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,19 @@ async function generateNotes(pluginConfig, context) {
4242
const {issue, commit, referenceActions, issuePrefixes} =
4343
find(HOSTS_CONFIG, conf => conf.hostname === hostname) || HOSTS_CONFIG.default;
4444
const parsedCommits = filter(
45-
commits.map(rawCommit => ({
46-
...rawCommit,
47-
...parser(rawCommit.message, {referenceActions, issuePrefixes, ...parserOpts}),
48-
}))
45+
commits
46+
.filter(({message, hash}) => {
47+
if (!message.trim()) {
48+
debug('Skip commit %s with empty message', hash);
49+
return false;
50+
}
51+
52+
return true;
53+
})
54+
.map(rawCommit => ({
55+
...rawCommit,
56+
...parser(rawCommit.message, {referenceActions, issuePrefixes, ...parserOpts}),
57+
}))
4958
);
5059
const previousTag = lastRelease.gitTag || lastRelease.gitHead;
5160
const currentTag = nextRelease.gitTag || nextRelease.gitHead;

test/integration.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,21 @@ test('Exclude commits if they have a matching revert commits', async t => {
582582
t.notRegex(changelog, /Second feature/);
583583
});
584584

585+
test('Exclude commits with empty message', async t => {
586+
const commits = [
587+
{hash: '111', message: 'fix(scope1): First fix'},
588+
{hash: '222', message: ''},
589+
{hash: '333', message: ' '},
590+
];
591+
const changelog = await generateNotes({}, {cwd, options: {repositoryUrl}, lastRelease, nextRelease, commits});
592+
593+
t.regex(changelog, new RegExp(escape('(https://github.com/owner/repo/compare/v1.0.0...v2.0.0)')));
594+
t.regex(changelog, /### Bug Fixes/);
595+
t.regex(changelog, new RegExp(escape('* **scope1:** First fix ([111](https://github.com/owner/repo/commit/111))')));
596+
t.notRegex(changelog, /222/);
597+
t.notRegex(changelog, /333/);
598+
});
599+
585600
test('Throw error if "preset" doesn`t exist', async t => {
586601
const commits = [
587602
{hash: '111', message: 'Fix: First fix (fixes #123)'},

0 commit comments

Comments
 (0)