Update the dangerfile to check for issue links

This commit is contained in:
Joseph T Lyons 2024-08-11 14:18:19 -04:00
parent 6f104fecad
commit 36a560dcd0

View file

@ -9,8 +9,10 @@ prHygiene({
}); });
const RELEASE_NOTES_PATTERN = new RegExp("Release Notes:\\r?\\n\\s+-", "gm"); 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);
const hasReleaseNotes = RELEASE_NOTES_PATTERN.test(danger.github.pr.body);
if (!hasReleaseNotes) { if (!hasReleaseNotes) {
warn( warn(
[ [
@ -33,3 +35,29 @@ if (!hasReleaseNotes) {
].join("\n"), ].join("\n"),
); );
} }
const ISSUE_LINK_PATTERN = new RegExp(
"(?:^|\\s)(?:#(\\d+)|https:\\/\\/github\\.com\\/zed-industries\\/zed\\/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);
warn(
[
"This PR includes links to the following GitHub Issues: " +
issues.join(", "),
"If this pull requests aims to close an issue, please include a `Closes #ISSUE` line at the top of the PR body.",
].join("\n"),
);
}