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
39
40function getPullRequestNumbers(startDate, endDate) {
41  const sinceDate = startDate.toISOString();
42  const untilDate = endDate.toISOString();
43
44  const pullRequestNumbers = execFileSync(
45    "git",
46    [
47      "log",
48      `--since=${sinceDate}`,
49      `--until=${untilDate}`,
50      "--oneline"
51    ],
52    { encoding: "utf8" }
53  )
54    .split("\n")
55    .filter(line => line.length > 0)
56    .map(line => {
57      const match = line.match(/#(\d+)/);
58      return match ? match[1] : null;
59    })
60    .filter(line => line);
61
62  return pullRequestNumbers;
63}