mirror of
https://github.com/Aviortheking/codestats-readme.git
synced 2025-04-22 10:42:08 +00:00
update request util
This commit is contained in:
parent
001062db21
commit
208076e7f4
@ -5,35 +5,38 @@ async function fetchRepo(username, reponame) {
|
|||||||
throw new Error("Invalid username or reponame");
|
throw new Error("Invalid username or reponame");
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await request(`
|
const res = await request({
|
||||||
fragment RepoInfo on Repository {
|
query: `
|
||||||
name
|
fragment RepoInfo on Repository {
|
||||||
stargazers {
|
|
||||||
totalCount
|
|
||||||
}
|
|
||||||
description
|
|
||||||
primaryLanguage {
|
|
||||||
color
|
|
||||||
id
|
|
||||||
name
|
name
|
||||||
|
stargazers {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
description
|
||||||
|
primaryLanguage {
|
||||||
|
color
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
forkCount
|
||||||
}
|
}
|
||||||
forkCount
|
query getRepo($login: String!, $repo: String!) {
|
||||||
}
|
user(login: $login) {
|
||||||
query getRepo($login: String!, $repo: String!) {
|
repository(name: $repo) {
|
||||||
user(login: $login) {
|
...RepoInfo
|
||||||
repository(name: $repo) {
|
}
|
||||||
...RepoInfo
|
}
|
||||||
|
organization(login: $login) {
|
||||||
|
repository(name: $repo) {
|
||||||
|
...RepoInfo
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
organization(login: $login) {
|
`,
|
||||||
repository(name: $repo) {
|
variables: {
|
||||||
...RepoInfo
|
login: username,
|
||||||
}
|
repo: reponame,
|
||||||
}
|
},
|
||||||
}
|
|
||||||
`, {
|
|
||||||
login: username,
|
|
||||||
repo: reponame,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = res.data.data;
|
const data = res.data.data;
|
||||||
|
@ -4,32 +4,35 @@ require("dotenv").config();
|
|||||||
async function fetchStats(username) {
|
async function fetchStats(username) {
|
||||||
if (!username) throw Error("Invalid username");
|
if (!username) throw Error("Invalid username");
|
||||||
|
|
||||||
const res = await request(`
|
const res = await request({
|
||||||
query userInfo($login: String!) {
|
query: `
|
||||||
user(login: $login) {
|
query userInfo($login: String!) {
|
||||||
name
|
user(login: $login) {
|
||||||
repositoriesContributedTo(first: 100, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY]) {
|
name
|
||||||
totalCount
|
repositoriesContributedTo(first: 100, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY]) {
|
||||||
}
|
totalCount
|
||||||
contributionsCollection {
|
}
|
||||||
totalCommitContributions
|
contributionsCollection {
|
||||||
}
|
totalCommitContributions
|
||||||
pullRequests(first: 100) {
|
}
|
||||||
totalCount
|
pullRequests(first: 100) {
|
||||||
}
|
totalCount
|
||||||
issues(first: 100) {
|
}
|
||||||
totalCount
|
issues(first: 100) {
|
||||||
}
|
totalCount
|
||||||
repositories(first: 100) {
|
}
|
||||||
nodes {
|
repositories(first: 100) {
|
||||||
stargazers {
|
nodes {
|
||||||
totalCount
|
stargazers {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
`,
|
||||||
`, { login: username });
|
variables: { login: username }
|
||||||
|
});
|
||||||
|
|
||||||
const stats = {
|
const stats = {
|
||||||
name: "",
|
name: "",
|
||||||
|
@ -27,7 +27,7 @@ function kFormatter(num) {
|
|||||||
: Math.sign(num) * Math.abs(num);
|
: Math.sign(num) * Math.abs(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
function request(query, variables) {
|
function request(data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios({
|
axios({
|
||||||
url: "https://api.github.com/graphql",
|
url: "https://api.github.com/graphql",
|
||||||
@ -35,10 +35,7 @@ function request(query, variables) {
|
|||||||
headers: {
|
headers: {
|
||||||
Authorization: `bearer ${process.env.GITHUB_TOKEN}`,
|
Authorization: `bearer ${process.env.GITHUB_TOKEN}`,
|
||||||
},
|
},
|
||||||
data: {
|
data,
|
||||||
query,
|
|
||||||
variables,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.then((response) => resolve(response))
|
.then((response) => resolve(response))
|
||||||
.catch((error) => reject(error));
|
.catch((error) => reject(error));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user