forked from boostxyz/boost-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.ts
52 lines (46 loc) · 1.53 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
import { danger, fail, warn } from 'danger';
// API reference: https://danger.systems/js/reference.html
const pr = danger.github.pr;
const issueKeywords = [
'close ',
'closes ',
'closed ',
'fix ',
'fixes ',
'fixed ',
'resolve ',
'resolves ',
'resolved ',
];
// Rules
try {
if (pr.title.startsWith('[ADHOC]')) {
warn(
'By using the `[ADHOC]` title prefix, you are bypassing best practice protections.',
);
} else {
// Remind people to add some details to the description, 200 accounts for roughly a sentence more than the standard template headers.
if (pr.body.length < 200) {
fail('Please add some non-placeholder details to the PR description.');
}
// Ensure [BOOST-XXXX] is somewhere in PR title
const linearRegex = /\[BOOST-\d+\]/;
if (
!linearRegex.test(pr.title) &&
!issueKeywords.some((keyword) => pr.body.includes(keyword))
) {
fail(
'Your PR body must reference a Github issue using a valid keyword, or your PR title must include the internal Boost ticket number, ie: `[BOOST-1234] Innovate like nuts`',
);
}
}
// Warn if not including changeset
const changesets = danger.git.fileMatch('.changeset/*.md');
if (!changesets.edited) {
warn(
`Are you sure you want to be submitting a change without including a changeset? Please see [the publishing section of the README](https://github.com/rabbitholegg/boost-protocol?tab=readme-ov-file#changesets--publishing)`,
);
}
} catch (e) {
console.error('Danger failed', e);
}