Skip to content

Commit

Permalink
Add --backfill-limit option
Browse files Browse the repository at this point in the history
Previously, releases without any merges or fixes were listed in the changelog as an empty release
This will backfill empty releases with a list of commits up to a certain limit (3 by default)
  • Loading branch information
cookpete committed Nov 8, 2018
1 parent 7f8f945 commit 5240b1e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Options:
-v, --latest-version [version] # use specified version as latest release
-u, --unreleased # include section for unreleased changes
-l, --commit-limit [count] # number of commits to display per release, default: 3
-b, --backfill-limit [count] # number of commits to backfill empty releases with, default: 3
-i, --issue-url [url] # override url for issues, use {id} for issue id
--issue-pattern [regex] # override regex pattern for issues in commit messages
--breaking-pattern [regex] # regex pattern for breaking change commits
Expand Down
16 changes: 11 additions & 5 deletions src/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function parseReleases (commits, remote, latestVersion, options) {
release.tag ? `${options.tagPrefix}${release.tag}` : 'HEAD',
remote
),
commits: release.commits.sort(sortCommits),
commits: sliceCommits(release.commits.sort(sortCommits), options, release),
major: !options.tagPattern && commit.tag && release.tag && semver.diff(commit.tag, release.tag) === 'major'
})
}
Expand Down Expand Up @@ -76,10 +76,7 @@ function filterCommit (commit, release, limit) {
// Filter out commits with the same message as an existing merge
return false
}
if (limit === false) {
return true
}
return release.commits.length < limit
return true
}

function getCompareLink (from, to, remote) {
Expand Down Expand Up @@ -110,3 +107,12 @@ function sortCommits (a, b) {
if (a.breaking && !b.breaking) return 1
return (b.insertions + b.deletions) - (a.insertions + a.deletions)
}

function sliceCommits (commits, options, release) {
if (options.commitLimit === false) {
return commits
}
const emptyRelease = release.fixes.length === 0 && release.merges.length === 0
const limit = emptyRelease ? options.backfillLimit : options.commitLimit
return commits.slice(0, limit)
}
2 changes: 2 additions & 0 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const DEFAULT_OPTIONS = {
template: 'compact',
remote: 'origin',
commitLimit: 3,
backfillLimit: 3,
tagPrefix: ''
}

Expand All @@ -29,6 +30,7 @@ function getOptions (argv, pkg, dotOptions) {
.option('-v, --latest-version [version]', 'use specified version as latest release')
.option('-u, --unreleased', 'include section for unreleased changes')
.option('-l, --commit-limit [count]', `number of commits to display per release, default: ${DEFAULT_OPTIONS.commitLimit}`, parseLimit)
.option('-b, --backfill-limit [count]', `number of commits to backfill empty releases with, default: ${DEFAULT_OPTIONS.backfillLimit}`, parseLimit)
.option('-i, --issue-url [url]', 'override url for issues, use {id} for issue id')
.option('--issue-pattern [regex]', 'override regex pattern for issues in commit messages')
.option('--breaking-pattern [regex]', 'regex pattern for breaking change commits')
Expand Down
14 changes: 14 additions & 0 deletions test/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { parseReleases, sortReleases } from '../src/releases'
const options = {
unreleased: false,
commitLimit: 3,
backfillLimit: 3,
tagPrefix: ''
}

Expand All @@ -20,6 +21,19 @@ describe('parseReleases', () => {
expect(parseReleases(commits, remotes.github, null, { ...options, commitLimit: false })).to.deep.equal(releases)
})

it('parses releases with backfill limit', () => {
const releases = parseReleases(commits, remotes.github, null, {
...options,
commitLimit: 0,
backfillLimit: 1
})
for (const release of releases) {
if (release.fixes.length === 0 && release.merges.length === 0) {
expect(release.commits.length).to.equal(1)
}
}
})

it('parses releases with summary', () => {
const releases = parseReleases(commits, remotes.bitbucket, null, { ...options, releaseSummary: true })
expect(releases[0].summary).to.equal('This is my major release description.\n\n- And a bullet point')
Expand Down

0 comments on commit 5240b1e

Please sign in to comment.