Skip to content

Commit

Permalink
Add merge and fix support to commit-list helper
Browse files Browse the repository at this point in the history
Fixes #146
  • Loading branch information
cookpete committed Jun 13, 2020
1 parent d4977ce commit 7b8c1a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
18 changes: 18 additions & 0 deletions test/commit-list-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
Expand Down Expand Up @@ -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' +
Expand Down

0 comments on commit 7b8c1a2

Please sign in to comment.