get-changes-since

 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  // Use form of: YYYY-MM-DD - 2023-01-09
12  const startDate = new Date(process.argv[2]);
13  const today = new Date();
14
15  console.log(`Changes from ${startDate} to ${today}\n`);
16
17  let pullRequestNumbers = getPullRequestNumbers(startDate, today);
18
19  // Fetch the pull requests from the GitHub API.
20  console.log("Merged Pull requests:");
21  for (const pullRequestNumber of pullRequestNumbers) {
22    const webURL = `https://github.com/zed-industries/zed/pull/${pullRequestNumber}`;
23    const apiURL = `https://api.github.com/repos/zed-industries/zed/pulls/${pullRequestNumber}`;
24
25    const response = await fetch(apiURL, {
26      headers: {
27        Authorization: `token ${GITHUB_ACCESS_TOKEN}`,
28      },
29    });
30
31    const pullRequest = await response.json();
32    console.log("*", pullRequest.title);
33    console.log("  PR URL:    ", webURL);
34    console.log("  Merged:    ", pullRequest.merged_at);
35    console.log();
36  }
37}
38
39function getPullRequestNumbers(startDate, endDate) {
40  const sinceDate = startDate.toISOString();
41  const untilDate = endDate.toISOString();
42
43  const pullRequestNumbers = execFileSync(
44    "git",
45    ["log", `--since=${sinceDate}`, `--until=${untilDate}`, "--oneline"],
46    { encoding: "utf8" },
47  )
48    .split("\n")
49    .filter((line) => line.length > 0)
50    .map((line) => {
51      const match = line.match(/#(\d+)/);
52      return match ? match[1] : null;
53    })
54    .filter((line) => line);
55
56  return pullRequestNumbers;
57}