-
Notifications
You must be signed in to change notification settings - Fork 0
/
contributions.ts
56 lines (49 loc) · 1.32 KB
/
contributions.ts
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
interface ContributionDay {
color: string;
contributionCount: number;
contributionLevel: string;
date: string;
}
interface Week {
contributionDays: ContributionDay[];
}
interface ContributionCalendar {
totalContributions: number;
colors: string[];
weeks: Week[];
}
const API_URL = Deno.env.get("CI") ? "http://localhost:8000" : "https://api.github.com/graphql";
const getContributions = async (user: string, to?: string) => {
const token = Deno.env.get("GH_READ_USER_TOKEN");
const query = `
query($user:String!) {
user(login: $user){
contributionsCollection${to ? `(to:"${to}T00:00:00")` : ""} {
contributionCalendar {
totalContributions
colors
isHalloween
weeks {
contributionDays {
color
contributionCount
contributionLevel
date
}
}
}
}
}
}
`;
const variables = { user };
const json = { query, variables };
const res = await fetch(API_URL, {
method: "POST",
headers: { Authorization: `Bearer ${token}`, "Content-type": "application/json" },
body: JSON.stringify(json),
});
return res.json();
};
export { getContributions };
export type { ContributionCalendar, ContributionDay, Week };