fix: wrong total commits (#490)

This commit is contained in:
Anurag Hazra 2020-09-24 21:24:16 +05:30 committed by GitHub
parent 278d6a1739
commit 3c6c142c75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View file

@ -115,16 +115,21 @@ async function fetchStats(
stats.name = user.name || user.login; stats.name = user.name || user.login;
stats.totalIssues = user.issues.totalCount; stats.totalIssues = user.issues.totalCount;
// normal commits
stats.totalCommits = user.contributionsCollection.totalCommitContributions; stats.totalCommits = user.contributionsCollection.totalCommitContributions;
if (count_private) { // if include_all_commits then just get that,
stats.totalCommits += user.contributionsCollection.restrictedContributionsCount; // since totalCommitsFetcher already sends totalCommits no need to +=
}
if (include_all_commits) { if (include_all_commits) {
stats.totalCommits = await totalCommitsFetcher(username); stats.totalCommits = await totalCommitsFetcher(username);
} }
// if count_private then add private commits to totalCommits so far.
if (count_private) {
stats.totalCommits +=
user.contributionsCollection.restrictedContributionsCount;
}
stats.totalPRs = user.pullRequests.totalCount; stats.totalPRs = user.pullRequests.totalCount;
stats.contributedTo = user.repositoriesContributedTo.totalCount; stats.contributedTo = user.repositoriesContributedTo.totalCount;

View file

@ -114,7 +114,7 @@ describe("Test fetchStats", () => {
let stats = await fetchStats("anuraghazra", true, true); let stats = await fetchStats("anuraghazra", true, true);
const rank = calculateRank({ const rank = calculateRank({
totalCommits: 1000, totalCommits: 1050,
totalRepos: 5, totalRepos: 5,
followers: 100, followers: 100,
contributions: 61, contributions: 61,
@ -126,7 +126,7 @@ describe("Test fetchStats", () => {
expect(stats).toStrictEqual({ expect(stats).toStrictEqual({
contributedTo: 61, contributedTo: 61,
name: "Anurag Hazra", name: "Anurag Hazra",
totalCommits: 1000, totalCommits: 1050,
totalIssues: 200, totalIssues: 200,
totalPRs: 300, totalPRs: 300,
totalStars: 400, totalStars: 400,