diff --git a/ghost/release-utils/lib/utils.js b/ghost/release-utils/lib/utils.js index bef0f51c5a..f31a33745d 100644 --- a/ghost/release-utils/lib/utils.js +++ b/ghost/release-utils/lib/utils.js @@ -1,26 +1,32 @@ const emojiRegex = require('emoji-regex'); const _ = require('lodash'); +const timestamp = /^[0-9]{10} /; +const separator = /^\* /; +const hash = /^\[[0-9a-f]{9}\]/; +const url = /^\(https?:\/\/[^)]+\) /; + +const getCommitMessageFromLine = line => line + .replace(timestamp, '') + .replace(separator, '') + .replace(hash, '') + .replace(url, ''); + module.exports.filterEmojiCommits = (content) => { if (!_.isArray(content)) { throw new Error('Expected array of strings.'); } - const timestamp = /^[0-9]{10} /; - const separator = /^\* /; - const hash = /^\[[0-9a-f]{9}\]/; - const url = /^\(https?:\/\/[^)]+\) /; + return content.reduce((emojiLines, currentLine) => { + const commitMessage = getCommitMessageFromLine(currentLine); - return content.map((line) => { - return '* ' + line - .replace(timestamp, '') - .replace(separator, '') - .replace(hash, '') - .replace(url, ''); - }).filter((line) => { - const match = emojiRegex().exec(line); - return match && match.index === 2; - }); + const match = emojiRegex().exec(commitMessage); + if (match && match.index === 0) { + return emojiLines.concat(`* ${commitMessage}`); + } + + return emojiLines; + }, []); }; module.exports.checkMissingOptions = (options = {}, ...requiredFields) => {