Compare commits
3
Commits
tests
...
commit-counts
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e9b0a0fc5 | ||
|
|
fe1ce9d693 | ||
|
|
6cee3e67ed |
+55
-2
@@ -17,7 +17,7 @@ async function fetchStats(username) {
|
||||
totalCount
|
||||
}
|
||||
contributionsCollection {
|
||||
totalCommitContributions
|
||||
contributionYears
|
||||
}
|
||||
pullRequests(first: 100) {
|
||||
totalCount
|
||||
@@ -53,9 +53,61 @@ async function fetchStats(username) {
|
||||
|
||||
const user = res.data.data.user;
|
||||
|
||||
// FETCH ALL COMMITS
|
||||
let commitPromises = user.contributionsCollection.contributionYears.map(
|
||||
async (year) => {
|
||||
// Don't fetch contributions older than 2008 (Perf optimization)
|
||||
if (year < 2008) {
|
||||
return {
|
||||
user: { contributionsCollection: { totalCommitContributions: 0 } },
|
||||
};
|
||||
}
|
||||
|
||||
const currentDate = new Date();
|
||||
currentDate.setFullYear(year, 0, 0);
|
||||
|
||||
const res = await axios({
|
||||
url: "https://api.github.com/graphql",
|
||||
method: "post",
|
||||
headers: {
|
||||
Authorization: `bearer ${process.env.GITHUB_TOKEN}`,
|
||||
},
|
||||
data: {
|
||||
query: `
|
||||
query userInfo($login: String!, $from: DateTime!) {
|
||||
user(login: $login) {
|
||||
contributionsCollection(from: $from) {
|
||||
totalCommitContributions
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
login: username,
|
||||
from: currentDate.toISOString(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
console.log(
|
||||
currentDate.toDateString(),
|
||||
res.data.data.user.contributionsCollection.totalCommitContributions
|
||||
);
|
||||
return res.data.data;
|
||||
}
|
||||
);
|
||||
|
||||
const allCommits = await Promise.all(commitPromises);
|
||||
|
||||
const totalCommits = allCommits.reduce((preYear, currYear) => {
|
||||
return (
|
||||
preYear + currYear.user.contributionsCollection.totalCommitContributions
|
||||
);
|
||||
}, 0);
|
||||
|
||||
stats.name = user.name;
|
||||
stats.totalIssues = user.issues.totalCount;
|
||||
stats.totalCommits = user.contributionsCollection.totalCommitContributions;
|
||||
stats.totalCommits = totalCommits;
|
||||
stats.totalPRs = user.pullRequests.totalCount;
|
||||
stats.contributedTo = user.repositoriesContributedTo.totalCount;
|
||||
|
||||
@@ -137,6 +189,7 @@ module.exports = async (req, res) => {
|
||||
|
||||
const stats = await fetchStats(username);
|
||||
|
||||
res.setHeader('Cache-Control', 'public, max-age=300');
|
||||
res.setHeader("Content-Type", "image/svg+xml");
|
||||
res.send(
|
||||
renderSVG(stats, {
|
||||
|
||||
@@ -120,6 +120,7 @@ module.exports = async (req, res) => {
|
||||
|
||||
const repoData = await fetchRepo(username, repo);
|
||||
|
||||
res.setHeader('Cache-Control', 'public, max-age=300');
|
||||
res.setHeader("Content-Type", "image/svg+xml");
|
||||
res.send(renderRepoCard(repoData));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user