Skip to content

Commit

Permalink
fix: handle edge case with non conventional commits
Browse files Browse the repository at this point in the history
  • Loading branch information
lekterable committed Apr 28, 2020
1 parent c3561dc commit 8be681f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

## Misc

- setup travis [c3561dc0](https://github.com/lekterable/perfekt/commit/c3561dc0c18151fc38a0415556211ffe7cff83bf)
- add main modules tests [8990fd64](https://github.com/lekterable/perfekt/commit/8990fd64de5ababc39eba8e8c9b2d7b2509216ef)
- include commit links in the changelog [8f622021](https://github.com/lekterable/perfekt/commit/8f622021665bc6076d00fde6527800980eba836a)

Expand Down
2 changes: 1 addition & 1 deletion src/utils/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const getCommitDetails = commit => {
/(?<type>[\w ]*)(?:\((?<scope>[\w ]*)\))?(?<breaking>!)?: (?<message>.*)/
)

if (!commitDetails) return title
if (!commitDetails) return { hash, message: title }

const {
groups: { type, scope, message, breaking }
Expand Down
20 changes: 18 additions & 2 deletions src/utils/git.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,26 @@ describe('git', () => {
expect(commitDetails).toEqual(mockedOutput)
})

it('should return title for non conventional commits', () => {
it('should return title and hash for commits using other convention', () => {
const mockedInput =
'f2191200bf7b6e5eec3d61fcef9eb756e0129cfb Add some old feature'
const mockedOutput = 'Add some old feature'
const mockedOutput = {
hash: 'f2191200bf7b6e5eec3d61fcef9eb756e0129cfb',
message: 'Add some old feature'
}

const commitDetails = getCommitDetails(mockedInput)

expect(commitDetails).toEqual(mockedOutput)
})

it('should return title for non conventional commits', () => {
const mockedInput =
'c31c0ae217dde31fa858070916fbed4931d3c50b init :seedling:'
const mockedOutput = {
hash: 'c31c0ae217dde31fa858070916fbed4931d3c50b',
message: 'init :seedling:'
}

const commitDetails = getCommitDetails(mockedInput)

Expand Down

0 comments on commit 8be681f

Please sign in to comment.