Skip to content

Commit 5240b1e

Browse files
committed
Add --backfill-limit option
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)
1 parent 7f8f945 commit 5240b1e

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Options:
2929
-v, --latest-version [version] # use specified version as latest release
3030
-u, --unreleased # include section for unreleased changes
3131
-l, --commit-limit [count] # number of commits to display per release, default: 3
32+
-b, --backfill-limit [count] # number of commits to backfill empty releases with, default: 3
3233
-i, --issue-url [url] # override url for issues, use {id} for issue id
3334
--issue-pattern [regex] # override regex pattern for issues in commit messages
3435
--breaking-pattern [regex] # regex pattern for breaking change commits

src/releases.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function parseReleases (commits, remote, latestVersion, options) {
1717
release.tag ? `${options.tagPrefix}${release.tag}` : 'HEAD',
1818
remote
1919
),
20-
commits: release.commits.sort(sortCommits),
20+
commits: sliceCommits(release.commits.sort(sortCommits), options, release),
2121
major: !options.tagPattern && commit.tag && release.tag && semver.diff(commit.tag, release.tag) === 'major'
2222
})
2323
}
@@ -76,10 +76,7 @@ function filterCommit (commit, release, limit) {
7676
// Filter out commits with the same message as an existing merge
7777
return false
7878
}
79-
if (limit === false) {
80-
return true
81-
}
82-
return release.commits.length < limit
79+
return true
8380
}
8481

8582
function getCompareLink (from, to, remote) {
@@ -110,3 +107,12 @@ function sortCommits (a, b) {
110107
if (a.breaking && !b.breaking) return 1
111108
return (b.insertions + b.deletions) - (a.insertions + a.deletions)
112109
}
110+
111+
function sliceCommits (commits, options, release) {
112+
if (options.commitLimit === false) {
113+
return commits
114+
}
115+
const emptyRelease = release.fixes.length === 0 && release.merges.length === 0
116+
const limit = emptyRelease ? options.backfillLimit : options.commitLimit
117+
return commits.slice(0, limit)
118+
}

src/run.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const DEFAULT_OPTIONS = {
1313
template: 'compact',
1414
remote: 'origin',
1515
commitLimit: 3,
16+
backfillLimit: 3,
1617
tagPrefix: ''
1718
}
1819

@@ -29,6 +30,7 @@ function getOptions (argv, pkg, dotOptions) {
2930
.option('-v, --latest-version [version]', 'use specified version as latest release')
3031
.option('-u, --unreleased', 'include section for unreleased changes')
3132
.option('-l, --commit-limit [count]', `number of commits to display per release, default: ${DEFAULT_OPTIONS.commitLimit}`, parseLimit)
33+
.option('-b, --backfill-limit [count]', `number of commits to backfill empty releases with, default: ${DEFAULT_OPTIONS.backfillLimit}`, parseLimit)
3234
.option('-i, --issue-url [url]', 'override url for issues, use {id} for issue id')
3335
.option('--issue-pattern [regex]', 'override regex pattern for issues in commit messages')
3436
.option('--breaking-pattern [regex]', 'regex pattern for breaking change commits')

test/releases.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { parseReleases, sortReleases } from '../src/releases'
88
const options = {
99
unreleased: false,
1010
commitLimit: 3,
11+
backfillLimit: 3,
1112
tagPrefix: ''
1213
}
1314

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

24+
it('parses releases with backfill limit', () => {
25+
const releases = parseReleases(commits, remotes.github, null, {
26+
...options,
27+
commitLimit: 0,
28+
backfillLimit: 1
29+
})
30+
for (const release of releases) {
31+
if (release.fixes.length === 0 && release.merges.length === 0) {
32+
expect(release.commits.length).to.equal(1)
33+
}
34+
}
35+
})
36+
2337
it('parses releases with summary', () => {
2438
const releases = parseReleases(commits, remotes.bitbucket, null, { ...options, releaseSummary: true })
2539
expect(releases[0].summary).to.equal('This is my major release description.\n\n- And a bullet point')

0 commit comments

Comments
 (0)