dangerfile.ts

 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  "https://github\\.com/[\\w-]+/[\\w-]+/issues/\\d+",
41  "g",
42);
43
44const includesIssueUrl = ISSUE_LINK_PATTERN.test(body);
45
46if (includesIssueUrl) {
47  const matches = body.match(ISSUE_LINK_PATTERN) ?? [];
48  const issues = matches
49    .map((match) =>
50      match
51        .replace(/^#/, "")
52        .replace(/https:\/\/github\.com\/zed-industries\/zed\/issues\//, ""),
53    )
54    .filter((issue, index, self) => self.indexOf(issue) === index);
55
56  message(
57    [
58      "This PR includes links to the following GitHub Issues: " +
59        issues.map((issue) => `#${issue}`).join(", "),
60      "If this PR aims to close an issue, please include a `Closes #ISSUE` line at the top of the PR body.",
61    ].join("\n"),
62  );
63}