From 851bb7b4b8837110d931f271d34be8e3d384c6f0 Mon Sep 17 00:00:00 2001 From: Boris K Date: Thu, 24 Sep 2020 09:03:32 +0200 Subject: [PATCH] fix(stats-card): commits count when include_all_commits is true (#391) --- src/fetchers/stats-fetcher.js | 15 ++++++--------- tests/fetchStats.test.js | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js index 27a97f2c..d1cc06dd 100644 --- a/src/fetchers/stats-fetcher.js +++ b/src/fetchers/stats-fetcher.js @@ -102,11 +102,6 @@ async function fetchStats( let res = await retryer(fetcher, { login: username }); - let experimental_totalCommits = 0; - if (include_all_commits) { - experimental_totalCommits = await totalCommitsFetcher(username); - } - if (res.data.errors) { logger.error(res.data.errors); throw new CustomError( @@ -116,16 +111,18 @@ async function fetchStats( } const user = res.data.data.user; - const contributionCount = user.contributionsCollection; stats.name = user.name || user.login; stats.totalIssues = user.issues.totalCount; - stats.totalCommits = - contributionCount.totalCommitContributions + experimental_totalCommits; + stats.totalCommits = user.contributionsCollection.totalCommitContributions; if (count_private) { - stats.totalCommits += contributionCount.restrictedContributionsCount; + stats.totalCommits += user.contributionsCollection.restrictedContributionsCount; + } + + if (include_all_commits) { + stats.totalCommits = await totalCommitsFetcher(username); } stats.totalPRs = user.pullRequests.totalCount; diff --git a/tests/fetchStats.test.js b/tests/fetchStats.test.js index 07145786..558b8828 100644 --- a/tests/fetchStats.test.js +++ b/tests/fetchStats.test.js @@ -114,7 +114,7 @@ describe("Test fetchStats", () => { let stats = await fetchStats("anuraghazra", true, true); const rank = calculateRank({ - totalCommits: 1000 + 150, + totalCommits: 1000, totalRepos: 5, followers: 100, contributions: 61, @@ -126,7 +126,7 @@ describe("Test fetchStats", () => { expect(stats).toStrictEqual({ contributedTo: 61, name: "Anurag Hazra", - totalCommits: 1000 + 150, + totalCommits: 1000, totalIssues: 200, totalPRs: 300, totalStars: 400,