-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdangerfile.ts
80 lines (71 loc) · 1.99 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { danger, fail, markdown, warn } from 'danger';
const checkPRTitle = () => {
const title = danger.github.pr.title;
// These must be consistent with those in the changelog config
const typeAllowList = [
'test',
'feat',
'fix',
'chore',
'docs',
'refactor',
'revert',
'style',
'ci',
'perf',
];
const scopeAllowList = [
'api',
'cms',
'config',
'content',
'db',
'dev',
'deps',
'lang',
'others',
'some',
'ui',
'utils',
];
const typePattern = typeAllowList.join('|');
const scopePattern = scopeAllowList.join('|');
const titleRegex = new RegExp(`^(${typePattern})\\((${scopePattern})\\): .+`);
if (!titleRegex.test(title)) {
fail(`**:x: Invalid PR title: ${title}**\n`);
markdown(
`Use either of the following type & scope instead.\n
**Allowed type list:**\n
- ${typeAllowList.join(',')}\n
**Allowed scope list:**\n
- ${scopeAllowList.join(',')}\n
e.g., feat(ui): 🆕 add a likes button\n`,
);
}
};
const warnLargePR = () => {
const changedFiles = danger.github.pr.changed_files;
const changedLinesTotal =
danger.github.pr.additions + danger.github.pr.deletions;
if (changedLinesTotal > 500 || changedFiles > 30) {
warn('**:warning: PR size appears relatively large.**\n');
markdown(
`Preferably, break changes into separate PRs for faster and easier code review.\n
- Changed files: ${changedFiles}\n
- Changed lines: ${changedLinesTotal}\n`,
);
}
};
const preventInconsistentDeps = () => {
const hasPackageChanges = danger.git.modified_files.includes('packge.json');
const hasLockfileChanges = danger.git.modified_files.includes('bun.lockb');
if (hasPackageChanges && !hasLockfileChanges) {
fail(
'**:x: Inconsistent deps changes detected.**\n' +
'Make changes in package.json consistent with those in your lockfile.\n',
);
}
};
checkPRTitle();
warnLargePR();
preventInconsistentDeps();