mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
df57b8c944
Small perf improvment, also easier to read now because we can use 0 index which is more obvious as to what we're doing
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
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.');
|
|
}
|
|
|
|
return content.reduce((emojiLines, currentLine) => {
|
|
const commitMessage = getCommitMessageFromLine(currentLine);
|
|
|
|
const match = emojiRegex().exec(commitMessage);
|
|
if (match && match.index === 0) {
|
|
return emojiLines.concat(`* ${commitMessage}`);
|
|
}
|
|
|
|
return emojiLines;
|
|
}, []);
|
|
};
|
|
|
|
module.exports.checkMissingOptions = (options = {}, ...requiredFields) => {
|
|
const missing = requiredFields.filter((requiredField) => {
|
|
return !_.get(options, requiredField);
|
|
});
|
|
|
|
if (missing.length) {
|
|
throw new Error(`Missing options: ${missing.join(', ')}`);
|
|
}
|
|
};
|