|
| 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