Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions lib/helper/parse-commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ function matchEmoji (emoji) {
return (spec) => spec.emoji === emoji || spec.emoji === emoji + IMAGE_STYLE_SELECTOR
}

function parseGitmoji ({ subject = '', message = '', body = '' } = {}, issues = []) {
function parseGitmoji ({
subject = '',
message = '',
body = ''
} = {}, issues = []) {
subject = emojify(subject.trim())
if (issues.length > 0) {
subject = issues.reduce((acc, curr) => acc.replace(curr.text, ''), subject).trim()
Expand All @@ -48,9 +52,24 @@ function parseGitmoji ({ subject = '', message = '', body = '' } = {}, issues =

const gitmoji = matched[0]
const semver = gitmojis.find(matchEmoji(gitmoji))?.semver || 'other'
subject = subject.replace(new RegExp('^' + gitmoji), '')

return { subject, message: subject + '\n\n' + body, gitmoji, semver }
try {
subject = subject.replace(new RegExp('^' + gitmoji), '')
} catch (SyntaxError) {
/**
* The emojiRegex is not bugproof, it may return a regex character
* (like * or .). The best option is to ignore this error
* If there is an error, there is no emoji
*
* @see https://github.com/momocow/semantic-release-gitmoji/issues/76
*/
return null
}
return {
subject,
message: subject + '\n\n' + body,
gitmoji,
semver
}
}

module.exports = function parseCommits (commits = [], mixins = {}, options = {}) {
Expand Down
8 changes: 8 additions & 0 deletions test/integration/analyze-commits.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ const CASES = [
},
context: getContext('common', { commits: { boring: 2, patch: 4, minor: 2, major: 1 } }),
expectedRelease: 'major'
},
{
name: 'default config + common context w/ star in commit subject',
pluginConfig: {
semver: true
},
context: getContext('common', { commits: { star: 1 } }),
expectedRelease: undefined
}
]

Expand Down
8 changes: 8 additions & 0 deletions test/integration/fixtures/contexts/commit-star.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"commit": {
"short": "commit_short"
},
"message": "*Commit starting with star",
"subject": "*Commit starting with star",
"body": ""
}