Sorted the release changelog by emoji

no issue
This commit is contained in:
Daniel Lockyer 2020-02-10 13:31:52 +00:00
parent 3bd4d736d8
commit 45bd9ec37f
2 changed files with 19 additions and 1 deletions

View File

@ -22,6 +22,7 @@ function getFinalChangelog(options) {
if (filterEmojiCommits) {
changelog = localUtils.filterEmojiCommits(changelog);
changelog.sortByEmoji();
}
finalChangelog = finalChangelog.concat(changelog);

View File

@ -12,6 +12,8 @@ const getCommitMessageFromLine = line => line
.replace(hash, '')
.replace(url, '');
const emojiOrder = ['💡', '🐛', '🎨', '💄', '✨'];
module.exports.filterEmojiCommits = (content) => {
if (!_.isArray(content)) {
throw new Error('Expected array of strings.');
@ -19,7 +21,6 @@ module.exports.filterEmojiCommits = (content) => {
return content.reduce((emojiLines, currentLine) => {
const commitMessage = getCommitMessageFromLine(currentLine);
const match = emojiRegex().exec(commitMessage);
if (match && match.index === 0) {
@ -30,6 +31,22 @@ module.exports.filterEmojiCommits = (content) => {
}, []);
};
module.exports.sortByEmoji = (content) => {
if (!_.isArray(content)) {
throw new Error('Expected array of strings.');
}
content.sort((a, b) => {
let firstEmoji = [...a][2];
let secondEmoji = [...b][2];
let firstEmojiIndex = _.indexOf(emojiOrder, firstEmoji);
let secondEmojiIndex = _.indexOf(emojiOrder, secondEmoji);
return secondEmojiIndex - firstEmojiIndex;
});
};
module.exports.checkMissingOptions = (options = {}, ...requiredFields) => {
const missing = requiredFields.filter((requiredField) => {
return !_.get(options, requiredField);