Skip to content

Commit

Permalink
Add support for minimumChangeCount in templates
Browse files Browse the repository at this point in the history
Backfill release notes with commits up to the given threshold
Prevents releases that list only a single merge or fix, even if larger changes may have been commited as well
  • Loading branch information
cookpete committed Jan 11, 2016
1 parent a6b828f commit 612d80b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/templates/Compact.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class Compact extends Default {
fixesTitle = null
commitsTitle = null

minimumChangeCount = 3
listSpacing = '\n'

renderReleaseHeading = (release, previousRelease) => {
Expand Down
11 changes: 7 additions & 4 deletions src/templates/Default.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class Default {

commitListLimit = 3
commitHashLength = 7
minimumChangeCount = 1 // Minimum number of merges/fixes/commits to show per release

sectionSpacing = '\n\n\n'
listSpacing = '\n\n'
Expand All @@ -32,8 +33,9 @@ export default class Default {
const merges = this.renderMerges(release.merges)
const fixes = this.renderFixes(release.fixes)
log = log.concat(merges).concat(fixes)
if (merges.length + fixes.length === 0) {
log = log.concat(this.renderCommits(release.commits))
const backfillCount = this.minimumChangeCount - (release.merges.length + release.fixes.length)
if (backfillCount > 0) {
log = log.concat(this.renderCommits(release.commits, backfillCount))
}
return log.join(this.listSpacing)
}
Expand Down Expand Up @@ -94,11 +96,12 @@ export default class Default {
return `[\`${number}\`](${href})`
}

renderCommits = (commits) => {
renderCommits = (commits, limit) => {
if (commits.length === 0) return []
limit = Math.min(limit, this.commitListLimit)
const list = commits
.sort(this.sortCommits)
.slice(0, this.commitListLimit)
.slice(0, limit)
.map(commit => this.renderCommit({
subject: commit.subject,
link: this.renderCommitLink(commit)
Expand Down
1 change: 1 addition & 0 deletions test/data/changelog-compact.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ Generated by [auto-changelog](https://github.com/CookPete/auto-changelog)
* Pull request title [\`#3\`](https://github.com/user/repo/pull/3)
* Second commit [\`#1\`](https://github.com/user/repo/issues/1), [\`#2\`](https://github.com/user/repo/issues/2)
* First commit [\`158fdde\`](https://github.com/user/repo/commit/158fdde54b6188c9f9ca3034e9cb5bcc3fe3ff69)
`

0 comments on commit 612d80b

Please sign in to comment.