From 36a560dcd0dc1efe73a35cf581c9610cbf3edf2b Mon Sep 17 00:00:00 2001 From: Joseph T Lyons Date: Sun, 11 Aug 2024 14:18:19 -0400 Subject: [PATCH] Update the dangerfile to check for issue links --- script/danger/dangerfile.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/script/danger/dangerfile.ts b/script/danger/dangerfile.ts index 110a630d1f..8ff691774d 100644 --- a/script/danger/dangerfile.ts +++ b/script/danger/dangerfile.ts @@ -9,8 +9,10 @@ prHygiene({ }); 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) { warn( [ @@ -33,3 +35,29 @@ if (!hasReleaseNotes) { ].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"), + ); +}