forked from getsentry/sentry-cocoa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.js
93 lines (74 loc) · 2.48 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const PR_NUMBER = danger.github.pr.number;
const PR_LINK = `(#${PR_NUMBER})`;
const CHANGELOG_SUMMARY_TITLE = `Instructions and example for changelog`;
const CHANGELOG_BODY = `Please add an entry to \`CHANGELOG.md\` to the "Unreleased" section under the following heading:
To the changelog entry, please add a link to this PR (consider a more descriptive message):`;
const CHANGELOG_END_BODY = `If none of the above apply, you can opt out by adding _#skip-changelog_ to the PR description.`;
function getCleanTitleWithPrLink() {
const title = danger.github.pr.title;
return title.split(": ").slice(-1)[0].trim().replace(/\.+$/, "") + PR_LINK;
}
function getChangelogDetailsHtml() {
return `
<details>
<summary><b>\`${CHANGELOG_SUMMARY_TITLE}\`$</b></summary>
\`${CHANGELOG_BODY}\`
\`\`\`md
- ${getCleanTitleWithPrLink()}
\`\`\`
\`${CHANGELOG_END_BODY}\`
</details>
`;
}
function getChangelogDetailsTxt() {
return CHANGELOG_SUMMARY_TITLE + '\n' +
CHANGELOG_BODY + '\n' +
getCleanTitleWithPrLink() + '\n' +
CHANGELOG_END_BODY;
}
function HasPermissionToComment(){
return danger.github.pr.head.repo.git_url == danger.github.pr.base.repo.git_url;
}
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)
{
if (HasPermissionToComment())
{
fail("Please consider adding a changelog entry for the next release.");
markdown(getChangelogDetailsHtml());
}
else
{
//Fallback
console.log("Please consider adding a changelog entry for the next release.");
console.log(getChangelogDetailsTxt());
process.exitCode = 1;
}
}
}
async function checkIfFeature() {
const title = danger.github.pr.title;
if (title.startsWith('feat:') && HasPermissionToComment()){
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);