forked from getsentry/sentry-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.js
51 lines (39 loc) · 1.37 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
const PR_NUMBER = danger.github.pr.number;
const PR_URL = danger.github.pr.html_url;
const PR_LINK = `[#${PR_NUMBER}](${PR_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 with
a link to this PR (consider a more descriptive message than the suggestion):
\`\`\`md
- ${getCleanTitle()}. (${PR_LINK})
\`\`\`
If an "Unreleased" section doesn't exist, please add one in above the section for the latest
release.
If creating a changelog entry is not applicable to your change, 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_LINK);
}
async function checkChangelog() {
const skipChangelog =
danger.github && (danger.github.pr.body + "").includes("#skip-changelog");
if (skipChangelog) {
return;
}
const hasChangelog = await containsChangelog("CHANGELOG.md");
if (!hasChangelog) {
fail("Please consider adding a changelog entry for the next release.");
markdown(getChangelogDetails());
}
}