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
This commit is contained in:
Joseph T. Lyons 2024-08-08 15:26:17 -04:00 committed by GitHub
parent a39f1f5133
commit b28507d2e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 46 deletions

View File

@ -1,13 +1,15 @@
Closes #ISSUE
Release Notes:
- Added/Fixed/Improved ... ([#NNNNN](https://github.com/zed-industries/zed/issues/NNNNN)).
- Added/Fixed/Improved ...
Optionally, include screenshots / media showcasing your addition that can be included in the release notes.
### Or...
Closes #ISSUE
Release Notes:
- N/A

View File

@ -21,7 +21,7 @@ if (!hasReleaseNotes) {
"```",
"Release Notes:",
"",
"- (Added|Fixed|Improved) ... ([#<public_issue_number_if_exists>](https://github.com/zed-industries/zed/issues/<public_issue_number_if_exists>)).",
"- Added/Fixed/Improved ...",
"```",
"",
'If your change is not user-facing, you can use "N/A" for the entry:',
@ -33,22 +33,3 @@ if (!hasReleaseNotes) {
].join("\n"),
);
}
const INCORRECT_ISSUE_LINK_PATTERN = new RegExp("-.*\\(#\\d+\\)", "g");
const hasIncorrectIssueLinks = INCORRECT_ISSUE_LINK_PATTERN.test(
danger.github.pr.body,
);
if (hasIncorrectIssueLinks) {
warn(
[
"This PR has incorrectly formatted GitHub issue links in the release notes.",
"",
"GitHub issue links must be formatted as plain Markdown links:",
"",
"```",
"- Improved something ([#ISSUE](https://github.com/zed-industries/zed/issues/ISSUE)).",
"```",
].join("\n"),
);
}

View File

@ -2,7 +2,12 @@
const { execFileSync } = require("child_process");
let { GITHUB_ACCESS_TOKEN } = process.env;
const FIXES_REGEX = /(fixes|closes|completes) (.+[/#]\d+.*)$/im;
const GITHUB_URL = "https://github.com";
const SKIPPABLE_NOTE_REGEX = /^\s*-?\s*n\/?a\s*/ims;
const PULL_REQUEST_WEB_URL = "https://github.com/zed-industries/zed/pull";
const PULL_REQUEST_API_URL =
"https://api.github.com/repos/zed-industries/zed/pulls";
const DIVIDER = "-".repeat(80);
main();
@ -44,51 +49,59 @@ async function main() {
// Fetch the pull requests from the GitHub API.
console.log("Merged Pull requests:");
console.log(DIVIDER);
for (const pullRequestNumber of newPullRequestNumbers) {
const webURL = `https://github.com/zed-industries/zed/pull/${pullRequestNumber}`;
const apiURL = `https://api.github.com/repos/zed-industries/zed/pulls/${pullRequestNumber}`;
const pullRequestApiURL = `${PULL_REQUEST_API_URL}/${pullRequestNumber}`;
const response = await fetch(apiURL, {
const response = await fetch(pullRequestApiURL, {
headers: {
Authorization: `token ${GITHUB_ACCESS_TOKEN}`,
},
});
// Print the pull request title and URL.
const pullRequest = await response.json();
const releaseNotesHeader = /^\s*Release Notes:(.+)/ims;
let releaseNotes = pullRequest.body || "";
let contributor = pullRequest.user?.login ?? "Unable to identify";
let contributor =
pullRequest.user?.login ?? "Unable to identify contributor";
const captures = releaseNotesHeader.exec(releaseNotes);
const notes = captures ? captures[1] : "MISSING";
const skippableNoteRegex = /^\s*-?\s*n\/?a\s*/ims;
let notes = captures ? captures[1] : "MISSING";
notes = notes.trim();
if (skippableNoteRegex.exec(notes) != null) {
if (SKIPPABLE_NOTE_REGEX.exec(notes) != null) {
continue;
}
console.log("*", pullRequest.title);
console.log(" PR URL: ", webURL);
console.log(" Author: ", contributor);
// If the pull request contains a 'closes' line, print the closed issue.
const fixesMatch = (pullRequest.body || "").match(FIXES_REGEX);
if (fixesMatch) {
const fixedIssueURL = fixesMatch[2];
console.log(" Issue URL: ", fixedIssueURL);
}
let credit = getCreditString(pullRequestNumber, contributor);
releaseNotes = notes.trim().split("\n");
console.log(" Release Notes:");
for (const line of releaseNotes) {
console.log(` ${line}`);
}
console.log(`PR Title: ${pullRequest.title}`);
console.log(`Credit: (${credit})`);
console.log("Release Notes:");
console.log();
console.log(notes);
console.log(DIVIDER);
}
}
function getCreditString(pullRequestNumber, contributor) {
let credit = "";
if (pullRequestNumber) {
let pullRequestMarkdownLink = `[#${pullRequestNumber}](${PULL_REQUEST_WEB_URL}/${pullRequestNumber})`;
credit += pullRequestMarkdownLink;
}
if (contributor) {
const contributorMarkdownLink = `[${contributor}](${GITHUB_URL}/${contributor})`;
credit += `; thanks ${contributorMarkdownLink}`;
}
return credit;
}
function getPullRequestNumbers(oldTag, newTag) {
const pullRequestNumbers = execFileSync(
"git",