Skip to content

Commit dbd36d5

Browse files
committedFeb 3, 2022
--ending-version fixes
1 parent c2bb8c5 commit dbd36d5

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed
 

‎src/tags.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,20 @@ const fetchTags = async (options, remote) => {
2828
}
2929

3030
const enriched = tags.map(enrichTag(options))
31-
return enriched.slice(getUpperLimit(enriched, options), getLimit(enriched, options))
31+
return enriched.slice(getStartIndex(enriched, options), getEndIndex(enriched, options))
3232
}
3333

34-
const getLimit = (tags, { unreleasedOnly, startingVersion, startingDate }) => {
34+
const getStartIndex = (tags, { endingVersion }) => {
35+
if (endingVersion) {
36+
const index = tags.findIndex(({ tag }) => tag === endingVersion)
37+
if (index !== -1) {
38+
return index
39+
}
40+
}
41+
return 0
42+
}
43+
44+
const getEndIndex = (tags, { unreleasedOnly, startingVersion, startingDate }) => {
3545
if (unreleasedOnly) {
3646
return 1
3747
}
@@ -47,16 +57,6 @@ const getLimit = (tags, { unreleasedOnly, startingVersion, startingDate }) => {
4757
return tags.length
4858
}
4959

50-
const getUpperLimit = (tags, { endingVersion }) => {
51-
if (endingVersion) {
52-
const index = tags.findIndex(({ tag }) => tag === endingVersion)
53-
if (index !== -1) {
54-
return index
55-
}
56-
}
57-
return 0
58-
}
59-
6060
const parseTag = ({ tagPrefix }) => string => {
6161
const [tag, date] = string.split(DIVIDER)
6262
return {

‎test/tags.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ describe('fetchTags', () => {
107107
expect(await fetchTags({ ...options, startingVersion: 'v0.2.2' })).to.have.lengthOf(3)
108108
})
109109

110+
it('supports --ending-version', async () => {
111+
expect(await fetchTags({ ...options, endingVersion: 'v0.2.2' })).to.have.lengthOf(4)
112+
})
113+
114+
it('supports --starting-version and --ending-version', async () => {
115+
expect(await fetchTags({ ...options, startingVersion: 'v0.2.1', endingVersion: 'v0.2.2' })).to.have.lengthOf(2)
116+
})
117+
110118
it('supports --starting-date', async () => {
111119
expect(await fetchTags({ ...options, startingDate: '2000-03-01' })).to.have.lengthOf(5)
112120
expect(await fetchTags({ ...options, startingDate: '2000-03-02' })).to.have.lengthOf(4)
@@ -153,10 +161,6 @@ describe('fetchTags', () => {
153161
])
154162
})
155163

156-
it('supports --ending-version', async () => {
157-
expect(await fetchTags({ ...options, endingVersion: 'v0.2.2' })).to.have.lengthOf(3)
158-
})
159-
160164
it('supports partial semver tags', async () => {
161165
mock('cmd', () => Promise.resolve([
162166
'v0.1---2000-02-01',

0 commit comments

Comments
 (0)
Please sign in to comment.