Skip to content

Commit

Permalink
Add --starting-date
Browse files Browse the repository at this point in the history
Fixes #181
  • Loading branch information
cookpete committed May 21, 2021
1 parent 6592ef2 commit a7fba3c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Options:
--tag-pattern [regex] # override regex pattern for version tags
--tag-prefix [prefix] # prefix used in version tags, default: v
--starting-version [tag] # specify earliest version to include in changelog
--starting-date [yyyy-mm-dd] # specify earliest date to include in changelog
--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
Expand Down
1 change: 1 addition & 0 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const getOptions = async argv => {
.option('--tag-pattern <regex>', 'override regex pattern for version tags')
.option('--tag-prefix <prefix>', 'prefix used in version tags')
.option('--starting-version <tag>', 'specify earliest version to include in changelog')
.option('--starting-date <yyyy-mm-dd>', 'specify earliest date to include in changelog')
.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')
Expand Down
10 changes: 6 additions & 4 deletions src/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ const fetchTags = async (options, remote) => {
})
}

return tags
.map(enrichTag(options))
.slice(0, getLimit(tags, options))
const enriched = tags.map(enrichTag(options))
return enriched.slice(0, getLimit(enriched, options))
}

const getLimit = (tags, { unreleasedOnly, startingVersion }) => {
const getLimit = (tags, { unreleasedOnly, startingVersion, startingDate }) => {
if (unreleasedOnly) {
return 1
}
Expand All @@ -42,6 +41,9 @@ const getLimit = (tags, { unreleasedOnly, startingVersion }) => {
return index + 1
}
}
if (startingDate) {
return tags.filter(t => t.isoDate >= startingDate).length
}
return tags.length
}

Expand Down
6 changes: 6 additions & 0 deletions test/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ describe('fetchTags', () => {
expect(await fetchTags({ ...options, startingVersion: 'v0.2.2' })).to.have.lengthOf(3)
})

it('supports --starting-date', async () => {
expect(await fetchTags({ ...options, startingDate: '2000-03-01' })).to.have.lengthOf(5)
expect(await fetchTags({ ...options, startingDate: '2000-03-02' })).to.have.lengthOf(4)
expect(await fetchTags({ ...options, startingDate: '2000-05-01' })).to.have.lengthOf(1)
})

it('supports partial semver tags', async () => {
mock('cmd', () => Promise.resolve([
'v0.1---2000-02-01',
Expand Down

0 comments on commit a7fba3c

Please sign in to comment.