-
Notifications
You must be signed in to change notification settings - Fork 25
/
dangerfile.js
60 lines (48 loc) · 1.36 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
async function checkChangelog() {
const changelogFile = "CHANGELOG.md";
// Check if skipped
const skipChangelog =
danger.github && (danger.github.pr.body + "").includes("#skip-changelog");
if (skipChangelog) {
return;
}
// Check if current PR has an entry in changelog
const changelogContents = await danger.github.utils.fileContents(
changelogFile
);
const hasChangelogEntry = RegExp(`#${danger.github.pr.number}\\b`).test(
changelogContents
);
if (hasChangelogEntry) {
return;
}
// Report missing changelog entry
fail(
"Please consider adding a changelog entry for the next release.",
changelogFile
);
const prTitleFormatted = danger.github.pr.title
.split(": ")
.slice(-1)[0]
.trim()
.replace(/\.+$/, "");
markdown(
`
### Instructions and example for changelog
Please add an entry to \`CHANGELOG.md\` to the "Next" section. Make sure the entry includes this PR's number.
Example:
\`\`\`markdown
## Next
- ${prTitleFormatted} ([#${danger.github.pr.number}](${danger.github.pr.html_url}))
\`\`\`
If none of the above apply, you can opt out of this check by adding \`#skip-changelog\` to the PR description.`.trim()
);
}
async function checkAll() {
const isDraft = danger.github.pr.mergeable_state === "draft";
if (isDraft) {
return;
}
await checkChangelog();
}
schedule(checkAll);