1import { danger, message, warn, fail } from "danger";
2const { prHygiene } = require("danger-plugin-pr-hygiene");
3
4prHygiene({
5 prefixPattern: /^([a-z\d\(\)_\s]+):(.*)/g,
6 rules: {
7 // Don't enable this rule just yet, as it can have false positives.
8 useImperativeMood: "off",
9 },
10});
11
12const RELEASE_NOTES_PATTERN = /Release Notes:\r?\n\s+-/gm;
13const body = danger.github.pr.body;
14
15const hasReleaseNotes = RELEASE_NOTES_PATTERN.test(body);
16
17if (!hasReleaseNotes) {
18 warn(
19 [
20 "This PR is missing release notes.",
21 "",
22 'Please add a "Release Notes" section that describes the change:',
23 "",
24 "```",
25 "Release Notes:",
26 "",
27 "- Added/Fixed/Improved ...",
28 "```",
29 "",
30 'If your change is not user-facing, you can use "N/A" for the entry:',
31 "```",
32 "Release Notes:",
33 "",
34 "- N/A",
35 "```",
36 ].join("\n"),
37 );
38}
39
40const ISSUE_LINK_PATTERN =
41 /(?<!(?:Close[sd]?|Fixe[sd]|Resolve[sd]|Implement[sed]|Follow-up of|Part of)\s+)https:\/\/github\.com\/[\w-]+\/[\w-]+\/issues\/\d+/gi;
42
43const bodyWithoutReleaseNotes = hasReleaseNotes ? body.split(/Release Notes:/)[0] : body;
44const includesIssueUrl = ISSUE_LINK_PATTERN.test(bodyWithoutReleaseNotes);
45
46if (includesIssueUrl) {
47 const matches = bodyWithoutReleaseNotes.match(ISSUE_LINK_PATTERN) ?? [];
48 const issues = matches
49 .map((match) => match.replace(/^#/, "").replace(/https:\/\/github\.com\/zed-industries\/zed\/issues\//, ""))
50 .filter((issue, index, self) => self.indexOf(issue) === index);
51
52 const issuesToReport = issues.map((issue) => `#${issue}`).join(", ");
53 message(
54 [
55 `This PR includes links to the following GitHub Issues: ${issuesToReport}`,
56 "If this PR aims to close an issue, please include a `Closes #ISSUE` line at the top of the PR body.",
57 ].join("\n"),
58 );
59}
60
61const PROMPT_PATHS = [
62 "assets/prompts/content_prompt.hbs",
63 "assets/prompts/terminal_assistant_prompt.hbs",
64 "crates/agent/src/prompts/stale_files_prompt_header.txt",
65 "crates/agent/src/prompts/summarize_thread_detailed_prompt.txt",
66 "crates/agent/src/prompts/summarize_thread_prompt.txt",
67 "crates/assistant_tools/src/templates/create_file_prompt.hbs",
68 "crates/assistant_tools/src/templates/edit_file_prompt.hbs",
69 "crates/git_ui/src/commit_message_prompt.txt",
70];
71
72const PROMPT_CHANGE_ATTESTATION = "I have ensured the LLM Worker works with these prompt changes.";
73
74const modifiedPrompts = danger.git.modified_files.filter((file) =>
75 PROMPT_PATHS.some((promptPath) => file.includes(promptPath)),
76);
77
78for (const promptPath of modifiedPrompts) {
79 if (body.includes(PROMPT_CHANGE_ATTESTATION)) {
80 message(
81 [
82 `This PR contains changes to "${promptPath}".`,
83 "The author has attested the LLM Worker works with the changes to this prompt.",
84 ].join("\n"),
85 );
86 } else {
87 fail(
88 [
89 `Modifying the "${promptPath}" prompt may require corresponding changes in the LLM Worker.`,
90 "If you are ensure what this entails, talk to @maxdeviant or another AI team member.",
91 `Once you have made the changes—or determined that none are necessary—add "${PROMPT_CHANGE_ATTESTATION}" to the PR description.`,
92 ].join("\n"),
93 );
94 }
95}