1import { danger, 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");
12
13const hasReleaseNotes = RELEASE_NOTES_PATTERN.test(danger.github.pr.body);
14if (!hasReleaseNotes) {
15 warn(
16 [
17 "This PR is missing release notes.",
18 "",
19 'Please add a "Release Notes" section that describes the change:',
20 "",
21 "```",
22 "Release Notes:",
23 "",
24 "- (Added|Fixed|Improved) ... ([#<public_issue_number_if_exists>](https://github.com/zed-industries/zed/issues/<public_issue_number_if_exists>)).",
25 "```",
26 "",
27 'If your change is not user-facing, you can use "N/A" for the entry:',
28 "```",
29 "Release Notes:",
30 "",
31 "- N/A",
32 "```",
33 ].join("\n"),
34 );
35}
36
37const INCORRECT_ISSUE_LINK_PATTERN = new RegExp("-.*\\(#\\d+\\)", "g");
38
39const hasIncorrectIssueLinks = INCORRECT_ISSUE_LINK_PATTERN.test(
40 danger.github.pr.body,
41);
42if (hasIncorrectIssueLinks) {
43 warn(
44 [
45 "This PR has incorrectly formatted GitHub issue links in the release notes.",
46 "",
47 "GitHub issue links must be formatted as plain Markdown links:",
48 "",
49 "```",
50 "- Improved something ([#ISSUE](https://github.com/zed-industries/zed/issues/ISSUE)).",
51 "```",
52 ].join("\n"),
53 );
54}