2018-03-13 15:39:07 +03:00
|
|
|
import { fail, danger } from 'danger';
|
2018-03-05 02:27:02 +03:00
|
|
|
import { flatten, intersection, isEmpty } 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'];
|
|
|
|
|
2018-03-05 02:27:02 +03:00
|
|
|
const Versions = {
|
|
|
|
PATCH: 'PATCH',
|
|
|
|
MINOR: 'MINOR',
|
|
|
|
MAJOR: 'MAJOR',
|
|
|
|
};
|
|
|
|
|
2018-03-20 02:25:44 +03:00
|
|
|
const branchVersion = Versions.MAJOR;
|
2018-03-05 02:27:02 +03:00
|
|
|
|
2017-06-12 02:26:55 +12:00
|
|
|
const checkRequiredLabels = labels => {
|
2018-03-05 02:27:02 +03:00
|
|
|
const forbiddenLabels = flatten([
|
|
|
|
'do not merge',
|
|
|
|
'in progress',
|
|
|
|
branchVersion !== Versions.MAJOR ? 'BREAKING CHANGE' : [],
|
|
|
|
branchVersion === Versions.PATCH ? 'feature request' : [],
|
|
|
|
]);
|
|
|
|
|
2017-06-12 02:26:55 +12:00
|
|
|
const requiredLabels = flatten([
|
|
|
|
prLogConfig.skipLabels || [],
|
|
|
|
Object.keys(prLogConfig.validLabels || {}),
|
|
|
|
]);
|
|
|
|
|
2018-03-05 02:27:02 +03:00
|
|
|
const blockingLabels = intersection(forbiddenLabels, labels);
|
|
|
|
if (!isEmpty(blockingLabels)) {
|
|
|
|
fail(
|
|
|
|
`PR is marked with ${blockingLabels.map(label => `"${label}"`).join(', ')} label${
|
|
|
|
blockingLabels.length > 1 ? 's' : ''
|
|
|
|
}.`
|
|
|
|
);
|
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));
|
|
|
|
}
|