Skip to content

Commit d22699b

Browse files
authored
🐛 Handle pre-release as latest version in markdown (#126)
1 parent 7580ff9 commit d22699b

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

packages/gitmoji-changelog-cli/src/cli.e2e.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,23 @@ describe('generate changelog', () => {
146146
expect(getChangelog()).includes(['1.0.0', '2.0.0'])
147147
})
148148

149+
it('should get two versions 1.0.0-alpha.1 and 1.0.0-alpha.2 while updating changelog after tagging a version 1.0.0-alpha.2', async () => {
150+
await makeChanges('file1')
151+
await commit(':sparkles: Add some file')
152+
await bumpVersion('1.0.0-alpha.1')
153+
gitmojiChangelog()
154+
await commit(':bookmark: Version 1.0.0-alpha.1')
155+
await tag('1.0.0-alpha.1')
156+
157+
await makeChanges('file2')
158+
await commit(':sparkles: Add another file')
159+
await bumpVersion('1.0.0-alpha.2')
160+
await tag('1.0.0-alpha.2')
161+
gitmojiChangelog()
162+
163+
expect(getChangelog()).includes(['1.0.0-alpha.1', '1.0.0-alpha.2'])
164+
})
165+
149166
it("should get two versions 1.0.0 and 2.0.0 while updating changelog by calling cli with 2.0.0 and having package.json's version set to 1.0.0", async () => {
150167
await makeChanges('file1')
151168
await commit(':sparkles: Add some file')

packages/gitmoji-changelog-markdown/src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,18 @@ async function getLatestVersion(markdownFile) {
116116
return null
117117
}
118118

119-
const versions = markdownContent.match(/<a name="([\w.]+?)"><\/a>/g)
119+
const versions = markdownContent.match(/<a name="([\w.-]+?)"><\/a>/g)
120120

121121
if (!versions) return null
122122

123123
const [lastVersion, previousVersion] = versions
124124

125125
const tags = await gitSemverTagsAsync()
126-
const result = lastVersion.match(/<a name="([\w.]+?)"><\/a>/)
126+
const result = lastVersion.match(/<a name="([\w.-]+?)"><\/a>/)
127127
const isNext = result[1] === 'next' || !tags.some(tag => semver.eq(tag, result[1]))
128128
if (!isNext) return result[1]
129129

130-
const previousResult = previousVersion.match(/<a name="([\w.]+?)"><\/a>/)
130+
const previousResult = previousVersion.match(/<a name="([\w.-]+?)"><\/a>/)
131131
return previousResult[1]
132132
}
133133

0 commit comments

Comments
 (0)