1#!/usr/bin/env node --redirect-warnings=/dev/null
2
3const { execFileSync } = require("child_process");
4const { GITHUB_ACCESS_TOKEN } = process.env;
5const PR_REGEX = /#\d+/; // Ex: matches on #4241
6const FIXES_REGEX = /(fixes|closes|completes) (.+[/#]\d+.*)$/im;
7
8main();
9
10async function main() {
11 // Get the last two preview tags
12 const [newTag, oldTag] = execFileSync(
13 "git",
14 ["tag", "--sort", "-committerdate"],
15 { encoding: "utf8" },
16 )
17 .split("\n")
18 .filter((t) => t.startsWith("v") && t.endsWith("-pre"));
19
20 // Print the previous release
21 console.log(`Changes from ${oldTag} to ${newTag}\n`);
22
23 let hasProtocolChanges = false;
24 try {
25 execFileSync("git", [
26 "diff",
27 oldTag,
28 newTag,
29 "--exit-code",
30 "--",
31 "crates/rpc",
32 ]).status != 0;
33 } catch (error) {
34 hasProtocolChanges = true;
35 }
36
37 if (hasProtocolChanges) {
38 console.warn(
39 "\033[31;1;4mRPC protocol changes, server should be re-deployed\033[0m\n",
40 );
41 } else {
42 console.log("No RPC protocol changes\n");
43 }
44
45 // Get the PRs merged between those two tags.
46 const pullRequestNumbers = getPullRequestNumbers(oldTag, newTag);
47
48 // Get the PRs that were cherry-picked between main and the old tag.
49 const existingPullRequestNumbers = new Set(
50 getPullRequestNumbers("main", oldTag),
51 );
52
53 // Filter out those existing PRs from the set of new PRs.
54 const newPullRequestNumbers = pullRequestNumbers.filter(
55 (number) => !existingPullRequestNumbers.has(number),
56 );
57
58 // Fetch the pull requests from the GitHub API.
59 console.log("Merged Pull requests:");
60 for (const pullRequestNumber of newPullRequestNumbers) {
61 const webURL = `https://github.com/zed-industries/zed/pull/${pullRequestNumber}`;
62 const apiURL = `https://api.github.com/repos/zed-industries/zed/pulls/${pullRequestNumber}`;
63
64 const response = await fetch(apiURL, {
65 headers: {
66 Authorization: `token ${GITHUB_ACCESS_TOKEN}`,
67 },
68 });
69
70 // Print the pull request title and URL.
71 const pullRequest = await response.json();
72 const releaseNotesHeader = /^\s*(?:Release )?Notes\s*:(.+)/ims;
73
74 let releaseNotes = pullRequest.body || "";
75 const captures = releaseNotesHeader.exec(releaseNotes);
76 const notes = captures ? captures[1] : "MISSING";
77 const skippableNoteRegex = /^\s*-?\s*n\/?a\s*/ims;
78
79 if (skippableNoteRegex.exec(notes) != null) {
80 continue;
81 }
82 console.log("*", pullRequest.title);
83 console.log(" PR URL: ", webURL);
84
85 // If the pull request contains a 'closes' line, print the closed issue.
86 const fixesMatch = (pullRequest.body || "").match(FIXES_REGEX);
87 if (fixesMatch) {
88 const fixedIssueURL = fixesMatch[2];
89 console.log(" Issue URL: ", fixedIssueURL);
90 }
91
92 releaseNotes = notes.trim().split("\n");
93 console.log(" Release Notes:");
94
95 for (const line of releaseNotes) {
96 console.log(` ${line}`);
97 }
98
99 console.log();
100 }
101}
102
103function getPullRequestNumbers(oldTag, newTag) {
104 const pullRequestNumbers = execFileSync(
105 "git",
106 ["log", `${oldTag}..${newTag}`, "--oneline"],
107 { encoding: "utf8" },
108 )
109 .split("\n")
110 .filter((line) => line.length > 0)
111 .map((line) => {
112 const match = line.match(/#(\d+)/);
113 return match ? match[1] : null;
114 })
115 .filter((line) => line);
116
117 return pullRequestNumbers;
118}