Skip to content

Commit

Permalink
Add danger (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Nov 2, 2023
1 parent 4074d93 commit 11fefd0
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
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);

0 comments on commit 11fefd0

Please sign in to comment.