zed/script/danger/dangerfile.ts
Marshall Bowers df20bae80e
danger: Don't look for #NNNN, as it's not specific enough (#16313)
This PR updates the regex we use to search for issues to not search for
`#NNNN`, as it's not specific enough.

It currently catches issue numbers from other repos, which are then
linked to random Zed issues/PRs that happen to have the same number:

<img width="935" alt="Screenshot 2024-08-15 at 3 50 29 PM"
src="https://github.com/user-attachments/assets/b779e503-3027-43e2-b355-e81d8d094694">

As well as catching PRs:

<img width="924" alt="Screenshot 2024-08-15 at 3 48 59 PM"
src="https://github.com/user-attachments/assets/6c2f7594-9234-4454-97da-5a33a1844892">

Given that:

1. We can't distinguish any given `#NNNN` as an issue _and_ can't ensure
it belongs to the Zed repo
2. Any issue/PR referenced as `#NNNN` will already create a backlink

It seems that looking for these is causing more noise than signal.

Release Notes:

- N/A
2024-08-15 15:57:42 -04:00

64 lines
1.6 KiB
TypeScript

import { danger, message, warn } from "danger";
const { prHygiene } = require("danger-plugin-pr-hygiene");
prHygiene({
rules: {
// Don't enable this rule just yet, as it can have false positives.
useImperativeMood: "off",
},
});
const RELEASE_NOTES_PATTERN = new RegExp("Release Notes:\\r?\\n\\s+-", "gm");
const body = danger.github.pr.body;
const hasReleaseNotes = RELEASE_NOTES_PATTERN.test(body);
if (!hasReleaseNotes) {
warn(
[
"This PR is missing release notes.",
"",
'Please add a "Release Notes" section that describes the change:',
"",
"```",
"Release Notes:",
"",
"- Added/Fixed/Improved ...",
"```",
"",
'If your change is not user-facing, you can use "N/A" for the entry:',
"```",
"Release Notes:",
"",
"- N/A",
"```",
].join("\n"),
);
}
const ISSUE_LINK_PATTERN = new RegExp(
"https://github\\.com/[\\w-]+/[\\w-]+/issues/\\d+",
"g",
);
const includesIssueUrl = ISSUE_LINK_PATTERN.test(body);
if (includesIssueUrl) {
const matches = body.match(ISSUE_LINK_PATTERN) ?? [];
const issues = matches
.map((match) =>
match
.replace(/^#/, "")
.replace(/https:\/\/github\.com\/zed-industries\/zed\/issues\//, ""),
)
.filter((issue, index, self) => self.indexOf(issue) === index);
message(
[
"This PR includes links to the following GitHub Issues: " +
issues.map((issue) => `#${issue}`).join(", "),
"If this PR aims to close an issue, please include a `Closes #ISSUE` line at the top of the PR body.",
].join("\n"),
);
}