mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
first commit
This commit is contained in:
commit
5a9cbef00b
6 changed files with 88 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
.vscode
|
||||||
|
.env
|
||||||
8
api/index.ts
Normal file
8
api/index.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { serve } from "./../deps.ts";
|
||||||
|
import { GithubAPIClient } from './../src/github_api_client.ts';
|
||||||
|
const client = new GithubAPIClient();
|
||||||
|
await client.requestUserData("ryo-ma");
|
||||||
|
const server = serve({ port: 8080 });
|
||||||
|
for await (const req of server) {
|
||||||
|
req.respond({ body: "<h1> TEST </h1>"});
|
||||||
|
}
|
||||||
1
deps.ts
Normal file
1
deps.ts
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
export { serve } from "https://deno.land/std@0.65.0/http/server.ts";
|
||||||
77
src/github_api_client.ts
Normal file
77
src/github_api_client.ts
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
import ky from "https://deno.land/x/ky/index.js";
|
||||||
|
import "https://deno.land/x/dotenv@v0.5.0/load.ts";
|
||||||
|
|
||||||
|
class UserInfo {
|
||||||
|
constructor(
|
||||||
|
public totalCommits: Number,
|
||||||
|
public totalFollowers: Number,
|
||||||
|
public totalIssues: Number,
|
||||||
|
public totalPullRequests: Number,
|
||||||
|
public totalStargazers: Number,
|
||||||
|
public totalRepositories: Number,
|
||||||
|
public totalContributed: Number,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GithubAPIClient {
|
||||||
|
constructor() {
|
||||||
|
}
|
||||||
|
async requestUserData(username: string): Promise<UserInfo> {
|
||||||
|
const token = Deno.env.get('GITHUB_TOKEN');
|
||||||
|
const variables = { username: username };
|
||||||
|
const query = `
|
||||||
|
query userInfo($username: String!) {
|
||||||
|
user(login: $username) {
|
||||||
|
name
|
||||||
|
login
|
||||||
|
contributionsCollection {
|
||||||
|
totalCommitContributions
|
||||||
|
restrictedContributionsCount
|
||||||
|
}
|
||||||
|
repositoriesContributedTo(first: 1, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY]) {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
pullRequests(first: 1) {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
issues(first: 1) {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
followers {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
repositories(first: 100, ownerAffiliations: OWNER, isFork: false, orderBy: {direction: DESC, field: STARGAZERS}) {
|
||||||
|
totalCount
|
||||||
|
nodes {
|
||||||
|
stargazers {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const response = await ky.post(
|
||||||
|
"https://api.github.com/graphql",
|
||||||
|
{
|
||||||
|
json: { query: query, variables },
|
||||||
|
headers: { Authorization: `bearer ${token}` },
|
||||||
|
},
|
||||||
|
).json();
|
||||||
|
const totalCommits = response.data.user.contributionsCollection.restrictedContributionsCount + response.data.user.contributionsCollection.totalCommitContributions;
|
||||||
|
const totalStargazers = response.data.user.repositories.nodes.reduce((prev: Number, node: any) => {
|
||||||
|
return prev + node.stargazers.totalCount;
|
||||||
|
}, 0);
|
||||||
|
const userInfo = new UserInfo(
|
||||||
|
totalCommits,
|
||||||
|
response.data.user.followers.totalCount,
|
||||||
|
response.data.user.issues.totalCount,
|
||||||
|
response.data.user.pullRequests.totalCount,
|
||||||
|
totalStargazers,
|
||||||
|
response.data.user.repositories.totalCount,
|
||||||
|
response.data.user.repositoriesContributedTo.totalCount,
|
||||||
|
)
|
||||||
|
return userInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
0
src/icons.ts
Normal file
0
src/icons.ts
Normal file
0
src/utils.ts
Normal file
0
src/utils.ts
Normal file
Loading…
Add table
Reference in a new issue