1#!/usr/bin/env node --redirect-warnings=/dev/null
2
3const { execFileSync } = require("child_process");
4const { GITHUB_ACCESS_TOKEN } = process.env;
5const PR_REGEX = /pull request #(\d+)/;
6const FIXES_REGEX = /(fixes|closes) (.+[/#]\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", ["diff", oldTag, newTag, "--exit-code", "--", "crates/rpc"]).status != 0;
26 } catch (error) {
27 hasProtocolChanges = true;
28 }
29
30 if (hasProtocolChanges) {
31 console.warn("\033[31;1;4mRPC protocol changes, server should be re-deployed\033[0m\n");
32 } else {
33 console.log("No RPC protocol changes\n");
34 }
35
36 // Get the PRs merged between those two tags.
37 const pullRequestNumbers = execFileSync(
38 "git",
39 [
40 "log",
41 `${oldTag}..${newTag}`,
42 "--oneline",
43 "--grep",
44 "Merge pull request",
45 ],
46 { encoding: "utf8" }
47 )
48 .split("\n")
49 .filter((line) => line.length > 0)
50 .map((line) => line.match(PR_REGEX)[1]);
51
52 // Get the PRs that were cherry-picked between main and the old tag.
53 const existingPullRequestNumbers = new Set(execFileSync(
54 "git",
55 [
56 "log",
57 `main..${oldTag}`,
58 "--oneline",
59 "--grep",
60 "Merge pull request",
61 ],
62 { encoding: "utf8" }
63 )
64 .split("\n")
65 .filter((line) => line.length > 0)
66 .map((line) => line.match(PR_REGEX)[1]));
67
68 // Filter out those existing PRs from the set of new PRs.
69 const newPullRequestNumbers = pullRequestNumbers.filter(number => !existingPullRequestNumbers.has(number));
70
71 // Fetch the pull requests from the GitHub API.
72 console.log("Merged Pull requests:")
73 for (const pullRequestNumber of newPullRequestNumbers) {
74 const webURL = `https://github.com/zed-industries/zed/pull/${pullRequestNumber}`;
75 const apiURL = `https://api.github.com/repos/zed-industries/zed/pulls/${pullRequestNumber}`;
76
77 const response = await fetch(apiURL, {
78 headers: {
79 Authorization: `token ${GITHUB_ACCESS_TOKEN}`,
80 },
81 });
82
83 // Print the pull request title and URL.
84 const pullRequest = await response.json();
85 console.log("*", pullRequest.title);
86 console.log(" URL: ", webURL);
87
88 // If the pull request contains a 'closes' line, print the closed issue.
89 const fixesMatch = (pullRequest.body || '').match(FIXES_REGEX);
90 if (fixesMatch) {
91 const fixedIssueURL = fixesMatch[2];
92 console.log(" Issue: ", fixedIssueURL);
93 }
94 }
95}