Skip to content

Commit a357a61

Browse files
committed
feat: make no-commits error more specific
1 parent 17feea4 commit a357a61

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Features
44

5+
- add release version bumping [17feea4a](https://github.com/lekterable/perfekt/commit/17feea4af5e339532d680a6ef6e9ec331f8abd2e)
56
- make changelog ignored scopes configurable [d34a9f12](https://github.com/lekterable/perfekt/commit/d34a9f12500df6ea21a17b85b783a41b1fca5347)
67
- make changelog groups configurable [a2ec46eb](https://github.com/lekterable/perfekt/commit/a2ec46eb9e962a79a9153300adc2229af182d4a6)
78

src/changelog.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ export const changelog = async (version, options, config) => {
1212
const latestTag = hasChangelog && !options.root && (await getLatestTag())
1313
const commits = await getCommits(latestTag)
1414

15-
if (!commits.length) throw new Error('No commits found since the last tag')
15+
if (!commits.length) {
16+
const message = latestTag
17+
? `No commits found since the latest tag '${latestTag}'`
18+
: 'No commits found'
19+
throw new Error(message)
20+
}
1621

1722
const grouped = groupCommits(commits, config)
1823
const changelog = generateChangelog(version, grouped, config)

src/changelog.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ describe('changelog', () => {
2727
beforeEach(() => jest.resetAllMocks())
2828

2929
it('should throw if no commits found', async () => {
30+
const mockedCommits = []
31+
32+
existsSync.mockImplementation(() => true)
33+
getCommits.mockImplementation(() => mockedCommits)
34+
35+
expect(changelog(null, defaultOptions, defaultConfig)).rejects.toThrow(
36+
'No commits found'
37+
)
38+
})
39+
40+
it('should throw if no commits found with tag', async () => {
3041
const mockedTag = '2.2.3'
3142
const mockedCommits = []
3243

@@ -35,7 +46,7 @@ describe('changelog', () => {
3546
getCommits.mockImplementation(() => mockedCommits)
3647

3748
expect(changelog(null, defaultOptions, defaultConfig)).rejects.toThrow(
38-
'No commits found since the last tag'
49+
"No commits found since the latest tag '2.2.3'"
3950
)
4051
})
4152

0 commit comments

Comments
 (0)