update request util

This commit is contained in:
Omid Nikrah 2020-07-12 12:12:06 +04:30
parent 001062db21
commit 208076e7f4
3 changed files with 55 additions and 52 deletions

View File

@ -5,35 +5,38 @@ async function fetchRepo(username, reponame) {
throw new Error("Invalid username or reponame");
}
const res = await request(`
fragment RepoInfo on Repository {
name
stargazers {
totalCount
}
description
primaryLanguage {
color
id
const res = await request({
query: `
fragment RepoInfo on Repository {
name
stargazers {
totalCount
}
description
primaryLanguage {
color
id
name
}
forkCount
}
forkCount
}
query getRepo($login: String!, $repo: String!) {
user(login: $login) {
repository(name: $repo) {
...RepoInfo
query getRepo($login: String!, $repo: String!) {
user(login: $login) {
repository(name: $repo) {
...RepoInfo
}
}
organization(login: $login) {
repository(name: $repo) {
...RepoInfo
}
}
}
organization(login: $login) {
repository(name: $repo) {
...RepoInfo
}
}
}
`, {
login: username,
repo: reponame,
`,
variables: {
login: username,
repo: reponame,
},
});
const data = res.data.data;

View File

@ -4,32 +4,35 @@ require("dotenv").config();
async function fetchStats(username) {
if (!username) throw Error("Invalid username");
const res = await request(`
query userInfo($login: String!) {
user(login: $login) {
name
repositoriesContributedTo(first: 100, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY]) {
totalCount
}
contributionsCollection {
totalCommitContributions
}
pullRequests(first: 100) {
totalCount
}
issues(first: 100) {
totalCount
}
repositories(first: 100) {
nodes {
stargazers {
totalCount
const res = await request({
query: `
query userInfo($login: String!) {
user(login: $login) {
name
repositoriesContributedTo(first: 100, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY]) {
totalCount
}
contributionsCollection {
totalCommitContributions
}
pullRequests(first: 100) {
totalCount
}
issues(first: 100) {
totalCount
}
repositories(first: 100) {
nodes {
stargazers {
totalCount
}
}
}
}
}
}
`, { login: username });
`,
variables: { login: username }
});
const stats = {
name: "",

View File

@ -27,7 +27,7 @@ function kFormatter(num) {
: Math.sign(num) * Math.abs(num);
}
function request(query, variables) {
function request(data) {
return new Promise((resolve, reject) => {
axios({
url: "https://api.github.com/graphql",
@ -35,10 +35,7 @@ function request(query, variables) {
headers: {
Authorization: `bearer ${process.env.GITHUB_TOKEN}`,
},
data: {
query,
variables,
},
data,
})
.then((response) => resolve(response))
.catch((error) => reject(error));