2017-06-13 13:39:33 +12:00
|
|
|
import { fail, danger } from 'danger';
|
2017-06-12 02:26:55 +12:00
|
|
|
import { flatten, intersection, isEmpty, includes } from 'lodash';
|
2017-06-12 00:50:57 +12:00
|
|
|
|
2017-06-12 02:26:55 +12:00
|
|
|
const pkg = require('./package.json'); // eslint-disable-line import/newline-after-import
|
|
|
|
const prLogConfig = pkg['pr-log'];
|
|
|
|
|
|
|
|
const checkRequiredLabels = labels => {
|
|
|
|
const requiredLabels = flatten([
|
|
|
|
prLogConfig.skipLabels || [],
|
|
|
|
Object.keys(prLogConfig.validLabels || {}),
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (includes(labels, 'do not merge')) {
|
2017-06-13 13:39:33 +12:00
|
|
|
fail('PR is marked with "do not merge" label.');
|
2017-06-12 02:26:55 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
const foundLabels = intersection(requiredLabels, labels);
|
|
|
|
if (isEmpty(foundLabels)) {
|
2017-06-13 13:39:33 +12:00
|
|
|
fail(`PR is not labeled with one of: ${JSON.stringify(requiredLabels)}`);
|
2017-06-12 02:26:55 +12:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (prLogConfig) {
|
|
|
|
const { labels } = danger.github.issue;
|
|
|
|
checkRequiredLabels(labels.map(l => l.name));
|
|
|
|
}
|