forked from jest-community/eslint-plugin-jest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.ts
57 lines (48 loc) · 1.48 KB
/
dangerfile.ts
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
49
50
51
52
53
54
55
56
57
import { parse } from 'path';
import { danger, warn } from 'danger';
// Ensure that people include a description on their PRs
if (danger.github.pr.body.length === 0) {
fail('Please include a body for your PR');
}
const createOrAddLabelSafely = async (name: string, color: string) => {
try {
await danger.github.utils.createOrAddLabel({
name,
color: color.replace('#', ''),
description: '',
});
} catch (error) {
console.warn(error);
warn(`Was unable to create or add label "${name}"`);
}
};
const labelBasedOnRules = async () => {
const affectedRules = [
...danger.git.created_files,
...danger.git.modified_files,
...danger.git.deleted_files,
]
.filter(filename => {
const { dir, ext } = parse(filename);
return dir === 'src/rules' && ext === '.ts';
})
.map(filename => parse(filename).name);
await Promise.all(
affectedRules.map(rule =>
createOrAddLabelSafely(`rule: ${rule}`, '#7d3abc'),
),
);
};
const labelBasedOnCommits = async () => {
const commits = danger.github.commits.map(commits => commits.commit.message);
if (commits.some(commit => commit.startsWith('fix'))) {
await createOrAddLabelSafely('bug', '#ee0701');
}
if (commits.some(commit => commit.startsWith('feat'))) {
await createOrAddLabelSafely('enhancement', '#84b6eb');
}
};
Promise.all([labelBasedOnRules(), labelBasedOnCommits()]).catch(error => {
console.error(error);
fail(`Something went very wrong: ${error}`);
});