Skip to content

Commit

Permalink
Add --hide-empty-releases
Browse files Browse the repository at this point in the history
Fixes #189
  • Loading branch information
cookpete committed May 23, 2021
1 parent a7fba3c commit 2f7c3ab
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Options:
--sort-commits [property] # sort commits by property [relevance, date, date-desc, subject, subject-desc], default: relevance
--release-summary # display tagged commit message body as release summary
--unreleased-only # only output unreleased changes
--hide-empty-releases # hide empty releases
--hide-credit # hide auto-changelog credit
--handlebars-setup [file] # handlebars setup file
--append-git-log [string] # string to append to git log command
Expand Down
10 changes: 9 additions & 1 deletion src/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const MERGE_COMMIT_PATTERN = /^Merge (remote-tracking )?branch '.+'/
const COMMIT_MESSAGE_PATTERN = /\n+([\S\s]+)/

const parseReleases = async (tags, options, onParsed) => {
return Promise.all(tags.map(async tag => {
const releases = await Promise.all(tags.map(async tag => {
const commits = await fetchCommits(tag.diff, options)
const merges = commits.filter(commit => commit.merge).map(commit => commit.merge)
const fixes = commits.filter(commit => commit.fixes).map(commit => ({ fixes: commit.fixes, commit }))
Expand All @@ -27,6 +27,7 @@ const parseReleases = async (tags, options, onParsed) => {
fixes
}
}))
return releases.filter(filterReleases(options))
}

const filterCommits = merges => commit => {
Expand Down Expand Up @@ -80,6 +81,13 @@ const getSummary = (message, { releaseSummary }) => {
return null
}

const filterReleases = options => ({ merges, fixes, commits }) => {
if (options.hideEmptyReleases && (merges.length + fixes.length + commits.length) === 0) {
return false
}
return true
}

module.exports = {
parseReleases
}
1 change: 1 addition & 0 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const getOptions = async argv => {
.option('--sort-commits <property>', `sort commits by property [relevance, date, date-desc], default: ${DEFAULT_OPTIONS.sortCommits}`)
.option('--release-summary', 'use tagged commit message body as release summary')
.option('--unreleased-only', 'only output unreleased changes')
.option('--hide-empty-releases', 'hide empty releases')
.option('--hide-credit', 'hide auto-changelog credit')
.option('--handlebars-setup <file>', 'handlebars setup file')
.option('--append-git-log <string>', 'string to append to git log command')
Expand Down
11 changes: 11 additions & 0 deletions test/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,15 @@ describe('parseReleases', () => {
expect(releases[0].commits).to.have.lengthOf(1)
expect(releases[0].commits[0]).to.include({ subject: 'First commit' })
})

it('hides empty releases', async () => {
const map = {
'v1.0.0': []
}
mock('fetchCommits', diff => Promise.resolve(map[diff]))
const options = { hideEmptyReleases: true }
const tags = [{ tag: 'v1.0.0', date: '2000-01-01', diff: 'v1.0.0' }]
const releases = await parseReleases(tags, options)
expect(releases).to.have.lengthOf(0)
})
})

0 comments on commit 2f7c3ab

Please sign in to comment.