|
| 1 | +// e.g. "feat" if PR title is "Feat : add more useful stuff" |
| 2 | +// or "ci" if PR branch is "ci/update-danger" |
| 3 | +function getPrFlavor() { |
| 4 | + if (danger.github && danger.github.pr) { |
| 5 | + var separator = undefined; |
| 6 | + if (danger.github.pr.title) { |
| 7 | + const parts = danger.github.pr.title.split(":"); |
| 8 | + if (parts.length > 1) { |
| 9 | + return parts[0].toLowerCase().trim(); |
| 10 | + } |
| 11 | + } |
| 12 | + if (danger.github.pr.head && danger.github.pr.head.ref) { |
| 13 | + const parts = danger.github.pr.head.ref.split("/"); |
| 14 | + if (parts.length > 1) { |
| 15 | + return parts[0].toLowerCase(); |
| 16 | + } |
| 17 | + } |
| 18 | + } |
| 19 | + return ""; |
| 20 | +} |
| 21 | + |
| 22 | +async function checkDocs() { |
| 23 | + if (getPrFlavor().startsWith("feat")) { |
| 24 | + message( |
| 25 | + '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.' |
| 26 | + ); |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +async function checkChangelog() { |
| 31 | + const changelogFile = "CHANGELOG.md"; |
| 32 | + |
| 33 | + // Check if skipped |
| 34 | + if (danger.github && danger.github.pr) { |
| 35 | + if ( |
| 36 | + ["ci", "chore(deps)"].includes(getPrFlavor()) || |
| 37 | + (danger.github.pr.body + "").includes("#skip-changelog") |
| 38 | + ) { |
| 39 | + return; |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + // Check if current PR has an entry in changelog |
| 44 | + const changelogContents = await danger.github.utils.fileContents( |
| 45 | + changelogFile |
| 46 | + ); |
| 47 | + |
| 48 | + const hasChangelogEntry = RegExp(`#${danger.github.pr.number}\\b`).test( |
| 49 | + changelogContents |
| 50 | + ); |
| 51 | + |
| 52 | + if (hasChangelogEntry) { |
| 53 | + return; |
| 54 | + } |
| 55 | + |
| 56 | + // Report missing changelog entry |
| 57 | + fail( |
| 58 | + "Please consider adding a changelog entry for the next release.", |
| 59 | + changelogFile |
| 60 | + ); |
| 61 | + |
| 62 | + const prTitleFormatted = danger.github.pr.title |
| 63 | + .split(": ") |
| 64 | + .slice(-1)[0] |
| 65 | + .trim() |
| 66 | + .replace(/\.+$/, ""); |
| 67 | + |
| 68 | + markdown( |
| 69 | + ` |
| 70 | +### Instructions and example for changelog |
| 71 | +
|
| 72 | +Please add an entry to \`CHANGELOG.md\` to the "Unreleased" section. Make sure the entry includes this PR's number. |
| 73 | +
|
| 74 | +Example: |
| 75 | +
|
| 76 | +\`\`\`markdown |
| 77 | +## Unreleased |
| 78 | +
|
| 79 | +- ${prTitleFormatted} ([#${danger.github.pr.number}](${danger.github.pr.html_url})) |
| 80 | +\`\`\` |
| 81 | +
|
| 82 | +If none of the above apply, you can opt out of this check by adding \`#skip-changelog\` to the PR description.`.trim() |
| 83 | + ); |
| 84 | +} |
| 85 | + |
| 86 | +async function checkAll() { |
| 87 | + await checkDocs(); |
| 88 | + await checkChangelog(); |
| 89 | +} |
| 90 | + |
| 91 | +schedule(checkAll); |
0 commit comments