1import { danger, message, warn } from "danger";
2const { prHygiene } = require("danger-plugin-pr-hygiene");
3
4prHygiene({
5 rules: {
6 // Don't enable this rule just yet, as it can have false positives.
7 useImperativeMood: "off",
8 },
9});
10
11const RELEASE_NOTES_PATTERN = new RegExp("Release Notes:\\r?\\n\\s+-", "gm");
12const body = danger.github.pr.body;
13
14const hasReleaseNotes = RELEASE_NOTES_PATTERN.test(body);
15
16if (!hasReleaseNotes) {
17 warn(
18 [
19 "This PR is missing release notes.",
20 "",
21 'Please add a "Release Notes" section that describes the change:',
22 "",
23 "```",
24 "Release Notes:",
25 "",
26 "- Added/Fixed/Improved ...",
27 "```",
28 "",
29 'If your change is not user-facing, you can use "N/A" for the entry:',
30 "```",
31 "Release Notes:",
32 "",
33 "- N/A",
34 "```",
35 ].join("\n"),
36 );
37}
38
39const ISSUE_LINK_PATTERN = new RegExp(
40 "(?<!(?:Close[sd]?|Fixe[sd]|Resolve[sd]|Implement[sed])\\s+)https://github\\.com/[\\w-]+/[\\w-]+/issues/\\d+",
41 "gi"
42);
43
44
45const includesIssueUrl = ISSUE_LINK_PATTERN.test(body);
46
47if (includesIssueUrl) {
48 const matches = body.match(ISSUE_LINK_PATTERN) ?? [];
49 const issues = matches
50 .map((match) =>
51 match
52 .replace(/^#/, "")
53 .replace(/https:\/\/github\.com\/zed-industries\/zed\/issues\//, ""),
54 )
55 .filter((issue, index, self) => self.indexOf(issue) === index);
56
57 message(
58 [
59 "This PR includes links to the following GitHub Issues: " +
60 issues.map((issue) => `#${issue}`).join(", "),
61 "If this PR aims to close an issue, please include a `Closes #ISSUE` line at the top of the PR body.",
62 ].join("\n"),
63 );
64}