2019-03-12 23:53:32 +03:00
|
|
|
const emojiRegex = require('emoji-regex');
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
|
|
module.exports.filterEmojiCommits = (content) => {
|
|
|
|
if (!_.isArray(content)) {
|
|
|
|
throw new Error('Expected array of strings.');
|
|
|
|
}
|
|
|
|
|
2019-03-13 17:27:55 +03:00
|
|
|
const timestamp = /^[0-9]{10} /;
|
|
|
|
const separator = /^\* /;
|
|
|
|
const hash = /^\[[0-9a-f]{9}\]/;
|
|
|
|
const url = /^\(https?:\/\/[^)]+\) /;
|
2019-03-12 23:53:32 +03:00
|
|
|
|
2019-03-13 17:27:55 +03:00
|
|
|
return content.map((line) => {
|
|
|
|
return '* ' + line
|
|
|
|
.replace(timestamp, '')
|
|
|
|
.replace(separator, '')
|
|
|
|
.replace(hash, '')
|
|
|
|
.replace(url, '');
|
|
|
|
}).filter((line) => {
|
2019-03-12 23:53:32 +03:00
|
|
|
const match = emojiRegex().exec(line);
|
2019-03-13 17:26:10 +03:00
|
|
|
return match && match.index === 2;
|
2019-03-12 23:53:32 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.checkMissingOptions = (options = {}, ...requiredFields) => {
|
|
|
|
const missing = requiredFields.filter((requiredField) => {
|
|
|
|
return !_.get(options, requiredField);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (missing.length) {
|
|
|
|
throw new Error(`Missing options: ${missing.join(', ')}`);
|
|
|
|
}
|
|
|
|
};
|