-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4074d93
commit 11fefd0
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |