-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdangerfile.ts
39 lines (29 loc) · 1.62 KB
/
dangerfile.ts
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
import { danger, markdown } from "danger";
const userIsAdmin = danger.github.pr.user.login === "sidiousvic";
const baseBranch = danger.github.pr.base.ref;
const PRAgainstProd = baseBranch === "production";
const PRAgainstDev = baseBranch === "dev";
const hasModifiedPhantom = danger.git.modified_files.join("").includes("src/");
const includesChangelog = danger.git.modified_files.includes("CHANGELOG.md");
console.table({
userIsAdmin,
baseBranch,
PRAgainstProd,
PRAgainstDev,
hasModifiedPhantom,
includesChangelog,
});
// MESSAGES
const YouForgotAChangelogFile = `<h3>📑 You forgot to update the <code>CHANGELOG</code>!</h3>You've modified <b>Phantom</b>. Please record your changes to <a href="https://github.com/sidiousvic/phantom/blob/production/README.md"><code>CHANGELOG.md</code></a>.<br></br>`;
const YouOpenedAPRAgainstProd = `<h3>💥 Sick human, you have opened a pull request against <code>${baseBranch}</code>!</h3>Hop outta here before I destroy you with my alien frog lasers!<br></br>`;
const YouOpenedAPRAgainstDev = `<h3>🐸 Thanks for your pull request, ribbit!</h3>Go fix yourself a piña colada while the checks pass and someone reviews your code. 🍍<br></br>`;
let message = "";
// BRANCH PROTECTION
if (PRAgainstProd && !userIsAdmin) message += YouOpenedAPRAgainstProd;
else if (PRAgainstDev) message += YouOpenedAPRAgainstDev;
// CHANGELOG WAS NOT INCLUDED WHEN UPDATING PROD AFTER CHANGING SOURCE CODE
if (PRAgainstProd && hasModifiedPhantom && !includesChangelog) {
message += YouForgotAChangelogFile;
}
if (!message) message += "<h3>🐸</h3>";
markdown(message + "<!--");