forked from getsentry/sentry-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.js
73 lines (55 loc) · 2.03 KB
/
dangerfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const PR_NUMBER = danger.github.pr.number;
const PR_URL = danger.github.pr.html_url;
function getCleanTitle() {
const title = danger.github.pr.title;
return title.split(": ").slice(-1)[0].trim().replace(/\.+$/, "");
}
function getChangelogDetails() {
return `
<details>
<summary><b>Instructions and example for changelog</b></summary>
Please add an entry to \`CHANGELOG.md\` to the "Unreleased" section under the following heading:
1. **feat**: For new user-visible functionality.
2. **fix**: For user-visible bug fixes.
3. **ref**: For features, refactors and bug fixes in internal operations.
To the changelog entry, please add a link to this PR (consider a more descriptive message):
\`\`\`md
- ${getCleanTitle()}. (${PR_NUMBER})
\`\`\`
If none of the above apply, you can opt out by adding _#skip-changelog_ to the PR description.
</details>
`;
}
async function containsChangelog(path) {
const contents = await danger.github.utils.fileContents(path);
return contents.includes(PR_NUMBER);
}
async function checkChangelog() {
const skipChangelog =
danger.github && (danger.github.pr.body + "").includes("#skip-changelog");
const isBot = danger.github && danger.github.pr.user.type === "Bot";
if (skipChangelog || isBot) {
return;
}
const hasChangelog = await containsChangelog("CHANGELOG.md");
if (!hasChangelog) {
fail("Please consider adding a changelog entry for the next release.");
markdown(getChangelogDetails());
}
}
async function checkIfFeature() {
const title = danger.github.pr.title;
if(title.startsWith('feat:')){
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.');
}
}
async function checkAll() {
// See: https://spectrum.chat/danger/javascript/support-for-github-draft-prs~82948576-ce84-40e7-a043-7675e5bf5690
const isDraft = danger.github.pr.mergeable_state === "draft";
if (isDraft) {
return;
}
await checkIfFeature();
await checkChangelog();
}
schedule(checkAll);