Skip to content

Commit 2b5027b

Browse files
authored
Add Danger changelog checker (#34)
1 parent 6dd28f0 commit 2b5027b

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

.github/workflows/danger.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: "Danger"
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened, edited, ready_for_review]
5+
6+
jobs:
7+
build:
8+
name: Changelog
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
14+
- run: npx danger ci
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

dangerfile.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
async function checkChangelog() {
2+
const changelogFile = "CHANGELOG.md";
3+
4+
// Check if skipped
5+
const skipChangelog =
6+
danger.github && (danger.github.pr.body + "").includes("#skip-changelog");
7+
8+
if (skipChangelog) {
9+
return;
10+
}
11+
12+
// Check if current PR has an entry in changelog
13+
const changelogContents = await danger.github.utils.fileContents(
14+
changelogFile
15+
);
16+
17+
const hasChangelogEntry = RegExp(`#${danger.github.pr.number}\\b`).test(
18+
changelogContents
19+
);
20+
21+
if (hasChangelogEntry) {
22+
return;
23+
}
24+
25+
// Report missing changelog entry
26+
fail(
27+
"Please consider adding a changelog entry for the next release.",
28+
changelogFile
29+
);
30+
31+
const prTitleFormatted = danger.github.pr.title
32+
.split(": ")
33+
.slice(-1)[0]
34+
.trim()
35+
.replace(/\.+$/, "");
36+
37+
markdown(
38+
`
39+
### Instructions and example for changelog
40+
Please add an entry to \`CHANGELOG.md\` to the "Next" section. Make sure the entry includes this PR's number.
41+
Example:
42+
\`\`\`markdown
43+
## Next
44+
- ${prTitleFormatted} ([#${danger.github.pr.number}](${danger.github.pr.html_url}))
45+
\`\`\`
46+
If none of the above apply, you can opt out of this check by adding \`#skip-changelog\` to the PR description.`.trim()
47+
);
48+
}
49+
50+
async function checkAll() {
51+
const isDraft = danger.github.pr.mergeable_state === "draft";
52+
53+
if (isDraft) {
54+
return;
55+
}
56+
57+
await checkChangelog();
58+
}
59+
60+
schedule(checkAll);

0 commit comments

Comments
 (0)