changes-since-last-release

 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 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"));
19
20  // Print the previous release
21  console.log(`Changes from ${oldTag} to ${newTag}\n`);
22
23  const hasProtocolChanges =
24    execFileSync("git", ["diff", oldTag, newTag, "--", "crates/rpc"]).status != 0;
25
26  if (hasProtocolChanges) {
27    console.log("No RPC protocol changes\n");
28  } else {
29    console.warn("RPC protocol changes\n");
30  }
31
32  // Get the PRs merged between those two tags.
33  const pullRequestNumbers = execFileSync(
34    "git",
35    [
36      "log",
37      `${oldTag}..${newTag}`,
38      "--oneline",
39      "--grep",
40      "Merge pull request",
41    ],
42    { encoding: "utf8" }
43  )
44    .split("\n")
45    .filter((line) => line.length > 0)
46    .map((line) => line.match(PR_REGEX)[1]);
47
48  // Fetch the pull requests from the GitHub API.
49  console.log("Merged Pull requests:")
50  for (const pullRequestNumber of pullRequestNumbers) {
51    const webURL = `https://github.com/zed-industries/zed/pull/${pullRequestNumber}`;
52    const apiURL = `https://api.github.com/repos/zed-industries/zed/pulls/${pullRequestNumber}`;
53
54    const response = await fetch(apiURL, {
55      headers: {
56        Authorization: `token ${GITHUB_ACCESS_TOKEN}`,
57      },
58    });
59
60    // Print the pull request title and URL.
61    const pullRequest = await response.json();
62    console.log("*", pullRequest.title);
63    console.log("  URL:    ", webURL);
64
65    // If the pull request contains a 'closes' line, print the closed issue.
66    const fixesMatch = pullRequest.body.match(FIXES_REGEX);
67    if (fixesMatch) {
68      const fixedIssueURL = fixesMatch[2];
69      console.log("  Issue: ", fixedIssueURL);
70    }
71  }
72}