Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #221: logical handling of --starting-version #227

Merged
merged 2 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,20 @@ const getStartIndex = (tags, { endingVersion }) => {
return 0
}

const getEndIndex = (tags, { unreleasedOnly, startingVersion, startingDate }) => {
const getEndIndex = (tags, { unreleasedOnly, startingVersion, startingDate, tagPrefix }) => {
if (unreleasedOnly) {
return 1
}
if (startingVersion) {
const index = tags.findIndex(({ tag }) => tag === startingVersion)
const semverStartingVersion = inferSemver(startingVersion.replace(tagPrefix, ''))
const index = tags.findIndex(({ tag }) => {
return tag === startingVersion || tag === semverStartingVersion
})
if (index !== -1) {
return index + 1
}
// Fall back to nearest version lower than startingVersion
return tags.findIndex(({ version }) => semver.lt(version, semverStartingVersion))
}
if (startingDate) {
return tags.filter(t => t.isoDate >= startingDate).length
Expand Down
5 changes: 4 additions & 1 deletion test/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ describe('fetchTags', () => {
})

it('supports --starting-version', async () => {
expect(await fetchTags({ ...options, startingVersion: 'v0.2.2' })).to.have.lengthOf(3)
expect(await fetchTags({ ...options, startingVersion: 'v0.3' })).to.have.lengthOf(2)
expect(await fetchTags({ ...options, startingVersion: 'v1' })).to.have.lengthOf(1) // Inferred semver
expect(await fetchTags({ ...options, startingVersion: 'v0.2.8' })).to.have.lengthOf(2) // Non-existent tag from the past
expect(await fetchTags({ ...options, startingVersion: 'v2.0.0' })).to.have.lengthOf(0) // Non-existent tag from the future
})

it('supports --ending-version', async () => {
Expand Down