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-11-05 21:05:36 +04:00
|
|
|
const branchVersion = Versions.MINOR;
|
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 || [],
|
2018-11-16 17:19:02 +08:00
|
|
|
(prLogConfig.validLabels || []).map(keyVal => keyVal[0]),
|
2017-06-12 02:26:55 +12:00
|
|
|
]);
|
|
|
|
|
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)}`);
|
2018-11-21 18:18:51 +08:00
|
|
|
} else if (foundLabels.length > 1) {
|
|
|
|
fail(`Please choose only one of these labels: ${JSON.stringify(foundLabels)}`);
|
2017-06-12 02:26:55 +12:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (prLogConfig) {
|
|
|
|
const { labels } = danger.github.issue;
|
|
|
|
checkRequiredLabels(labels.map(l => l.name));
|
|
|
|
}
|