feat: Add count_private flag to count private contributions (#148)

* Add private contributions count

* Remove unused var and add tests

* Update readme

* fix: tests & minor code formating

* docs: updated docs

Co-authored-by: anuraghazra <hazru.anurag@gmail.com>
This commit is contained in:
Fábio Rosado
2020-07-24 15:04:38 +01:00
committed by GitHub
parent 3a9ded0a09
commit 4c0518616f
5 changed files with 104 additions and 21 deletions

View File

@ -13,6 +13,7 @@ const fetcher = (variables, token) => {
login
contributionsCollection {
totalCommitContributions
restrictedContributionsCount
}
repositoriesContributedTo(first: 1, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY]) {
totalCount
@ -45,7 +46,7 @@ const fetcher = (variables, token) => {
);
};
async function fetchStats(username) {
async function fetchStats(username, count_private = false) {
if (!username) throw Error("Invalid username");
const stats = {
@ -66,10 +67,18 @@ async function fetchStats(username) {
}
const user = res.data.data.user;
const contributionCount = user.contributionsCollection;
stats.name = user.name || user.login;
stats.totalIssues = user.issues.totalCount;
stats.totalCommits = user.contributionsCollection.totalCommitContributions;
stats.totalCommits = contributionCount.totalCommitContributions;
if (count_private) {
stats.totalCommits =
contributionCount.totalCommitContributions +
contributionCount.restrictedContributionsCount;
}
stats.totalPRs = user.pullRequests.totalCount;
stats.contributedTo = user.repositoriesContributedTo.totalCount;