Skip to content

Commit

Permalink
--ending-version fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Feb 3, 2022
1 parent c2bb8c5 commit dbd36d5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
24 changes: 12 additions & 12 deletions src/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,20 @@ const fetchTags = async (options, remote) => {
}

const enriched = tags.map(enrichTag(options))
return enriched.slice(getUpperLimit(enriched, options), getLimit(enriched, options))
return enriched.slice(getStartIndex(enriched, options), getEndIndex(enriched, options))
}

const getLimit = (tags, { unreleasedOnly, startingVersion, startingDate }) => {
const getStartIndex = (tags, { endingVersion }) => {
if (endingVersion) {
const index = tags.findIndex(({ tag }) => tag === endingVersion)
if (index !== -1) {
return index
}
}
return 0
}

const getEndIndex = (tags, { unreleasedOnly, startingVersion, startingDate }) => {
if (unreleasedOnly) {
return 1
}
Expand All @@ -47,16 +57,6 @@ const getLimit = (tags, { unreleasedOnly, startingVersion, startingDate }) => {
return tags.length
}

const getUpperLimit = (tags, { endingVersion }) => {
if (endingVersion) {
const index = tags.findIndex(({ tag }) => tag === endingVersion)
if (index !== -1) {
return index
}
}
return 0
}

const parseTag = ({ tagPrefix }) => string => {
const [tag, date] = string.split(DIVIDER)
return {
Expand Down
12 changes: 8 additions & 4 deletions test/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ describe('fetchTags', () => {
expect(await fetchTags({ ...options, startingVersion: 'v0.2.2' })).to.have.lengthOf(3)
})

it('supports --ending-version', async () => {
expect(await fetchTags({ ...options, endingVersion: 'v0.2.2' })).to.have.lengthOf(4)
})

it('supports --starting-version and --ending-version', async () => {
expect(await fetchTags({ ...options, startingVersion: 'v0.2.1', endingVersion: 'v0.2.2' })).to.have.lengthOf(2)
})

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)
Expand Down Expand Up @@ -153,10 +161,6 @@ describe('fetchTags', () => {
])
})

it('supports --ending-version', async () => {
expect(await fetchTags({ ...options, endingVersion: 'v0.2.2' })).to.have.lengthOf(3)
})

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

0 comments on commit dbd36d5

Please sign in to comment.