forked from storybookjs/storybook
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dangerfile.js
48 lines (40 loc) · 1.37 KB
/
dangerfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { fail, danger } from 'danger';
import { flatten, intersection, isEmpty } from 'lodash';
const pkg = require('./package.json'); // eslint-disable-line import/newline-after-import
const prLogConfig = pkg['pr-log'];
const Versions = {
PATCH: 'PATCH',
MINOR: 'MINOR',
MAJOR: 'MAJOR',
};
const branchVersion = Versions.MINOR;
const checkRequiredLabels = labels => {
const forbiddenLabels = flatten([
'do not merge',
'in progress',
branchVersion !== Versions.MAJOR ? 'BREAKING CHANGE' : [],
branchVersion === Versions.PATCH ? 'feature request' : [],
]);
const requiredLabels = flatten([
prLogConfig.skipLabels || [],
(prLogConfig.validLabels || []).map(keyVal => keyVal[0]),
]);
const blockingLabels = intersection(forbiddenLabels, labels);
if (!isEmpty(blockingLabels)) {
fail(
`PR is marked with ${blockingLabels.map(label => `"${label}"`).join(', ')} label${
blockingLabels.length > 1 ? 's' : ''
}.`
);
}
const foundLabels = intersection(requiredLabels, labels);
if (isEmpty(foundLabels)) {
fail(`PR is not labeled with one of: ${JSON.stringify(requiredLabels)}`);
} else if (foundLabels.length > 1) {
fail(`Please choose only one of these labels: ${JSON.stringify(foundLabels)}`);
}
};
if (prLogConfig) {
const { labels } = danger.github.issue;
checkRequiredLabels(labels.map(l => l.name));
}