Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Danger changelog checker #34

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/danger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Danger"
on:
pull_request:
types: [opened, synchronize, reopened, edited, ready_for_review]

jobs:
build:
name: Changelog
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: npx danger ci
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60 changes: 60 additions & 0 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);