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
import { isDateInLastNumberOfDays } from "https://esm.town/v/onemanwenttomow/isDateInLastNumberOfDays";
import process from "node:process";
export const getGithubTeamCommitHistories = async (members) => {
const { Octokit } = await import("npm:@octokit/core");
const octokit = new Octokit({
auth: process.env.githubToken,
});
const memberEvents = await Promise.all(
members.map((member) => octokit.request(`GET /users/${member}/events`)),
);
const memberCommits = memberEvents.map(({ url, data }) => {
const commits = data.filter((event) => event.type === "PushEvent")
.map((event) => ({
repo: event.repo.name,
created_at: event.created_at,
}));
return {
url,
username: url
.replace("https://api.github.com/users/", "")
.replace("/events", ""),
commitsLast7Days: commits.filter((commit) =>
isDateInLastNumberOfDays(
7,
new Date(commit.created_at),
)
).length,
commitsLast3Days: commits.filter((commit) =>
isDateInLastNumberOfDays(
3,
new Date(commit.created_at),
)
).length,
};
});
return memberCommits;
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023