Skip to content

Commit ba8e98e

Browse files
feat: add Danger-JS (#625)
* Add DANGER! Co-authored-by: Bruno Garcia <[email protected]>
1 parent fdf2454 commit ba8e98e

File tree

3 files changed

+88
-31
lines changed

3 files changed

+88
-31
lines changed

.github/workflows/changelog.yaml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/danger.yml

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

dangerfile.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const PR_NUMBER = danger.github.pr.number;
2+
const PR_URL = danger.github.pr.html_url;
3+
const PR_LINK = `[#${PR_NUMBER}](${PR_URL})`;
4+
5+
function getCleanTitle() {
6+
const title = danger.github.pr.title;
7+
return title.split(": ").slice(-1)[0].trim().replace(/\.+$/, "");
8+
}
9+
10+
function getChangelogDetails() {
11+
return `
12+
<details>
13+
<summary><b>Instructions and example for changelog</b></summary>
14+
15+
Please add an entry to \`CHANGELOG.md\` to the "Unreleased" section under the following heading:
16+
1. **Feat**: For new user-visible functionality.
17+
2. **Fix**: For user-visible bug fixes.
18+
3. **Ref**: For features, refactory and bug fixes in internal operation.
19+
20+
To the changelog entry, please add a link to this PR (consider a more descriptive message):
21+
22+
\`\`\`md
23+
- ${getCleanTitle()}. (${PR_LINK})
24+
\`\`\`
25+
26+
If none of the above apply, you can opt out by adding _#skip-changelog_ to the PR description.
27+
28+
</details>
29+
`;
30+
}
31+
32+
async function containsChangelog(path) {
33+
const contents = await danger.github.utils.fileContents(path);
34+
return contents.includes(PR_LINK);
35+
}
36+
37+
async function checkChangelog() {
38+
const skipChangelog =
39+
danger.github && (danger.github.pr.body + "").includes("#skip-changelog");
40+
41+
if (skipChangelog) {
42+
return;
43+
}
44+
45+
const hasChangelog = await containsChangelog("CHANGELOG.md");
46+
47+
if (!hasChangelog) {
48+
fail("Please consider adding a changelog entry for the next release.");
49+
markdown(getChangelogDetails());
50+
}
51+
}
52+
53+
async function checkIfFeature() {
54+
const title = danger.github.pr.title;
55+
if(title.startsWith('feat:')){
56+
message('Do not forget to update <a href="https://github.com/getsentry/sentry-docs">Sentry-docs</a> with your feature once the pull request gets approved.');
57+
}
58+
59+
}
60+
61+
async function checkAll() {
62+
// See: https://spectrum.chat/danger/javascript/support-for-github-draft-prs~82948576-ce84-40e7-a043-7675e5bf5690
63+
const isDraft = danger.github.pr.mergeable_state === "draft";
64+
65+
if (isDraft) {
66+
return;
67+
}
68+
69+
await checkIfFeature();
70+
await checkChangelog();
71+
}
72+
73+
schedule(checkAll);

0 commit comments

Comments
 (0)