diff --git a/src/template.js b/src/template.js index 0980a467..81265c45 100644 --- a/src/template.js +++ b/src/template.js @@ -19,7 +19,8 @@ Handlebars.registerHelper('commit-list', function (context, options) { } const list = context - .filter(commit => { + .filter(item => { + const commit = item.commit || item if (options.hash.exclude) { const pattern = new RegExp(options.hash.exclude, 'm') if (pattern.test(commit.message)) { diff --git a/test/commit-list-helper.js b/test/commit-list-helper.js index 0c2ffb47..7e1ee708 100644 --- a/test/commit-list-helper.js +++ b/test/commit-list-helper.js @@ -9,6 +9,12 @@ describe('commit-list helper', () => { { subject: 'feat: Commit 3', message: 'feat: Commit 3\n\nThis commit adds a feature' } ] + const merges = [ + { commit: { subject: 'Commit 1', message: 'Commit 1\n\nThis is commit 1, nothing special' } }, + { commit: { subject: 'Commit 2', message: 'Commit 2\n\nBREAKING CHANGE: This commit breaks something' } }, + { commit: { subject: 'feat: Commit 3', message: 'feat: Commit 3\n\nThis commit adds a feature' } } + ] + it('returns nothing with no commits', () => { const compile = Handlebars.compile( '{{#commit-list commits heading="# Heading"}}\n' + @@ -45,6 +51,18 @@ describe('commit-list helper', () => { expect(compile({ commits })).to.equal(expected) }) + it('supports merge subject pattern matching', () => { + const compile = Handlebars.compile( + '{{#commit-list merges heading="# Heading" subject="^feat: "}}\n' + + '- {{commit.subject}}\n' + + '{{/commit-list}}' + ) + const expected = + '# Heading\n\n' + + '- feat: Commit 3\n' + expect(compile({ merges })).to.equal(expected) + }) + it('supports message pattern matching', () => { const compile = Handlebars.compile( '{{#commit-list commits heading="# Breaking Changes" message="^BREAKING CHANGE: "}}\n' +