-
Notifications
You must be signed in to change notification settings - Fork 3
/
dangerfile.ts
64 lines (57 loc) · 2 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
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
function rules() {
// if pr is changeset, exit early
if (pr.head.ref.includes('changeset-release')) return;
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 ||
(pr.body.includes('Thank you!') && pr.body.length < 200)
) {
fail('Please add some non-placeholder details to the PR description.');
} else if (pr.body.length < 80) {
// if not using the template
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? If you're just changing docs or tests, you probably don't need to. See [the publishing section of the README](https://github.com/boostxyz/boost-protocol?tab=readme-ov-file#changesets--publishing) for more info.`,
);
}
} catch (e) {
console.error('Danger failed', e);
}
}
rules();