forked from storybookjs/storybook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.js
46 lines (38 loc) · 1.23 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
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.MAJOR;
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 || [],
Object.keys(prLogConfig.validLabels || {}),
]);
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)}`);
}
};
if (prLogConfig) {
const { labels } = danger.github.issue;
checkRequiredLabels(labels.map(l => l.name));
}