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