zed/script/danger/dangerfile.ts

64 lines
1.6 KiB
TypeScript
Raw Normal View History

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:",
"",
Link to pull requests in changelog notes (#15996) This PR changes how we ask users to draft up PRs and how release note generation happens. We no longer force the user to create the markdown URL link, but we do ask them to use the `closes` [GitHub magic word](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) to link the PR to an issue, so that the issue is closed automatically when closing the PR. As for the changelog release notes, we are no longer linking to the issues, but the PR itself, which should contain the issue if a reader wants to dive further back. This makes our output more consistent, as every line will have a link, even if there is no issue associated, and it removes the need for us to try to parse the issue url in the body to try to correct mistakes in how they were forming Markdown urls - the PR url is always returned in the request, which makes it easy. **Lastly, it's just a lot less annoying to make the release notes.** The new PR format will be: ``` Closes #ISSUE Release Notes: - Added/Fixed/Improved ... ``` The new script output format will be: ``` PR Title: theme: Use a non-transparent color for the fallback `title_bar.inactive_background` Credit: ([#15709](https://github.com/zed-industries/zed/pull/15709); thanks [maxdeviant](https://github.com/maxdeviant)) Release Notes: - linux: Changed the fallback color of `title_bar.inactive_background` to a non-transparent value. -------------------------------------------------------------------------------- PR Title: Skip over folded regions when iterating over multibuffer chunks Credit: ([#15646](https://github.com/zed-industries/zed/pull/15646); thanks [osiewicz](https://github.com/osiewicz)) Release Notes: - Fixed poor performance when editing in the assistant panel after inserting large files using slash commands -------------------------------------------------------------------------------- ``` This still requires us to manually apply the credit line, but the line is already fully formed, so this should still be faster than having to manually create that line / fix any line where someone messed it up (which was all the time). I would just automatically apply it to the release notes, but sometimes we have multiple bullet points in a single PR and no real structure is enforced, so I foresee doing anything automatic breaking and needing manual adjustment. Release Notes: - N/A
2024-08-08 19:26:17 +00:00
"- 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(
2024-08-11 18:40:27 +00:00
"(?:https://github\\.com/[\\w-]+/[\\w-]+/issues/\\d+|#\\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: " +
2024-08-11 18:45:46 +00:00
issues.map((issue) => `#${issue}`).join(", "),
2024-08-11 18:48:58 +00:00
"If this PR aims to close an issue, please include a `Closes #ISSUE` line at the top of the PR body.",
].join("\n"),
);
}