forked from ryo-ma/github-profile-trophy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub_api_client.ts
61 lines (60 loc) · 1.72 KB
/
github_api_client.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
57
58
59
60
61
import { soxa } from "../deps.ts";
import { UserInfo } from "./user_info.ts"
import type { GitHubUserData } from "./user_info.ts";
export class GithubAPIClient {
constructor() {
}
async requestUserInfo(username: string): Promise<UserInfo | null> {
const token = Deno.env.get("GITHUB_TOKEN");
const variables = { username: username };
const query = `
query userInfo($username: String!) {
user(login: $username) {
createdAt
contributionsCollection {
totalCommitContributions
restrictedContributionsCount
}
pullRequests(first: 1) {
totalCount
}
issues(first: 1) {
totalCount
}
organizations(first: 1) {
totalCount
}
followers(first: 1) {
totalCount
}
repositories(first: 100, ownerAffiliations: OWNER, isFork: false, orderBy: {direction: DESC, field: STARGAZERS}) {
totalCount
nodes {
languages(first: 3, orderBy: {direction:DESC, field: SIZE}) {
nodes {
name
}
}
stargazers {
totalCount
}
}
}
}
}
`;
const response = await soxa.post(
"https://api.github.com/graphql",
{},
{
data: { query: query, variables },
headers: { Authorization: `bearer ${token}` },
},
);
if (response.status != 200) {
throw new Error(response)
}
const userData: GitHubUserData = response.data.data.user;
return new UserInfo(userData);
}
}