feat: added rankings

This commit is contained in:
anuraghazra
2020-07-13 19:41:47 +05:30
parent 8e8d7dd64d
commit db49ca7b71
8 changed files with 182 additions and 5 deletions
+16
View File
@@ -1,4 +1,5 @@
const { request } = require("./utils");
const calculateRank = require("./calculateRank");
require("dotenv").config();
async function fetchStats(username) {
@@ -22,7 +23,11 @@ async function fetchStats(username) {
issues(first: 100) {
totalCount
}
followers {
totalCount
}
repositories(first: 100, orderBy: { direction: DESC, field: STARGAZERS }) {
totalCount
nodes {
stargazers {
totalCount
@@ -42,6 +47,7 @@ async function fetchStats(username) {
totalIssues: 0,
totalStars: 0,
contributedTo: 0,
rank: "C",
};
if (res.data.errors) {
@@ -61,6 +67,16 @@ async function fetchStats(username) {
return prev + curr.stargazers.totalCount;
}, 0);
stats.rank = calculateRank({
totalCommits: stats.totalCommits,
totalRepos: user.repositories.totalCount,
followers: user.followers.totalCount,
contributions: stats.contributedTo,
stargazers: stats.totalStars,
prs: stats.totalPRs,
issues: stats.totalIssues,
});
return stats;
}