-
-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/fix/il2cpp-boot-time' into fix/i…
…l2cpp-boot-time
- Loading branch information
Showing
1 changed file
with
75 additions
and
54 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 |
---|---|---|
@@ -1,76 +1,97 @@ | ||
async function checkDocs() { | ||
if (danger.github.pr.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.' | ||
); | ||
} | ||
} | ||
const PR_LINK = `([#${danger.github.pr.number}](${danger.github.pr.html_url}))`; | ||
|
||
async function checkChangelog() { | ||
const changelogFile = "CHANGELOG.md"; | ||
const CHANGELOG_SUMMARY_TITLE = `Instructions and example for changelog`; | ||
const CHANGELOG_BODY = `Please add an entry to \`CHANGELOG.md\` to the "Unreleased" section. Make sure the entry includes this PR's number. | ||
// Check if skipped | ||
const skipChangelog = danger.github && (danger.github.pr.body + "").includes("#skip-changelog"); | ||
if (skipChangelog) { | ||
return; | ||
} | ||
Example:`; | ||
|
||
// Check if current PR has an entry in changelog | ||
const changelogContents = await danger.github.utils.fileContents(changelogFile); | ||
const CHANGELOG_END_BODY = `If none of the above apply, you can opt out of this check by adding \`#skip-changelog\` to the PR description.`; | ||
|
||
const hasChangelogEntry = RegExp(`#${danger.github.pr.number}\\b`).test(changelogContents); | ||
if (hasChangelogEntry) { | ||
return; | ||
} | ||
function getCleanTitleWithPrLink() { | ||
const title = danger.github.pr.title; | ||
return title.split(": ").slice(-1)[0].trim().replace(/\.+$/, "") + PR_LINK; | ||
} | ||
|
||
// Short-circuit if lacking permissions | ||
const hasCommentPermission = danger.github.pr.head.repo.git_url == danger.github.pr.base.repo.git_url; | ||
if (!hasCommentPermission) { | ||
console.log("Please consider adding a changelog entry for the next release."); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
function getChangelogDetailsHtml() { | ||
return ` | ||
### ${CHANGELOG_SUMMARY_TITLE} | ||
// Report missing changelog entry | ||
fail( | ||
"Please consider adding a changelog entry for the next release.", | ||
changelogFile | ||
); | ||
${CHANGELOG_BODY} | ||
const prTitleFormatted = danger.github.pr.title | ||
.split(": ") | ||
.slice(-1)[0] | ||
.trim() | ||
.replace(/\.+$/, ""); | ||
\`\`\`markdown | ||
- ${getCleanTitleWithPrLink()} | ||
\`\`\` | ||
markdown( | ||
` | ||
### Instructions and example for changelog | ||
${CHANGELOG_END_BODY} | ||
`; | ||
} | ||
|
||
Please add an entry to \`CHANGELOG.md\` to the "Unreleased" section. Make sure the entry includes this PR's number. | ||
function getChangelogDetailsTxt() { | ||
return ( | ||
CHANGELOG_SUMMARY_TITLE + | ||
"\n" + | ||
CHANGELOG_BODY + | ||
"\n" + | ||
getCleanTitleWithPrLink() + | ||
"\n" + | ||
CHANGELOG_END_BODY | ||
); | ||
} | ||
|
||
Example: | ||
function HasPermissionToComment() { | ||
return ( | ||
danger.github.pr.head.repo.git_url == danger.github.pr.base.repo.git_url | ||
); | ||
} | ||
|
||
\`\`\`markdown | ||
## Unreleased | ||
async function containsChangelog(path) { | ||
const contents = await danger.github.utils.fileContents(path); | ||
return contents.includes(PR_LINK); | ||
} | ||
|
||
- ${prTitleFormatted} ([#${danger.github.pr.number}](${danger.github.pr.html_url})) | ||
\`\`\` | ||
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; | ||
} | ||
} | ||
} | ||
|
||
If none of the above apply, you can opt out of this check by adding \`#skip-changelog\` to the PR description.`.trim() | ||
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"; | ||
// 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; | ||
} | ||
if (isDraft) { | ||
return; | ||
} | ||
|
||
await checkDocs(); | ||
await checkChangelog(); | ||
await checkIfFeature(); | ||
await checkChangelog(); | ||
} | ||
|
||
schedule(checkAll); |