forked from zed-industries/zed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-pull-requests-since
More file actions
executable file
·67 lines (55 loc) · 1.97 KB
/
get-pull-requests-since
File metadata and controls
executable file
·67 lines (55 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node --redirect-warnings=/dev/null
const { execFileSync } = require("child_process");
let { GITHUB_ACCESS_TOKEN } = process.env;
const PR_REGEX = /#\d+/; // Ex: matches on #4241
const FIXES_REGEX = /(fixes|closes|completes) (.+[/#]\d+.*)$/im;
main();
async function main() {
if (!GITHUB_ACCESS_TOKEN) {
try {
GITHUB_ACCESS_TOKEN = execFileSync("gh", ["auth", "token"]).toString();
} catch (error) {
console.log(error);
console.log("No GITHUB_ACCESS_TOKEN, and no `gh auth token`");
process.exit(1);
}
}
// Use form of: YYYY-MM-DD - 2023-01-09
const startDate = new Date(process.argv[2]);
const today = new Date();
console.log(`Pull requests from ${startDate} to ${today}\n`);
let pullRequestNumbers = getPullRequestNumbers(startDate, today);
// Fetch the pull requests from the GitHub API.
console.log("Merged pull requests:");
for (const pullRequestNumber of pullRequestNumbers) {
const webURL = `https://github.com/zed-industries/zed/pull/${pullRequestNumber}`;
const apiURL = `https://api.github.com/repos/zed-industries/zed/pulls/${pullRequestNumber}`;
const response = await fetch(apiURL, {
headers: {
Authorization: `token ${GITHUB_ACCESS_TOKEN}`,
},
});
const pullRequest = await response.json();
console.log("*", pullRequest.title);
console.log(" PR URL: ", webURL);
console.log(" Merged: ", pullRequest.merged_at);
console.log();
}
}
function getPullRequestNumbers(startDate, endDate) {
const sinceDate = startDate.toISOString();
const untilDate = endDate.toISOString();
const pullRequestNumbers = execFileSync(
"git",
["log", `--since=${sinceDate}`, `--until=${untilDate}`, "--oneline"],
{ encoding: "utf8" },
)
.split("\n")
.filter((line) => line.length > 0)
.map((line) => {
const match = line.match(/#(\d+)/);
return match ? match[1] : null;
})
.filter((line) => line);
return pullRequestNumbers;
}