feat: add 'exclude_repo' option to stats card (#1450)

This commit allows users to exclude repositories for the stats card
using the `exclude_repo` option.
This commit is contained in:
Rick Staa
2022-09-16 13:09:19 +02:00
committed by GitHub
parent dc8852dd6b
commit c1324b31bf
4 changed files with 65 additions and 13 deletions
+19 -3
View File
@@ -47,6 +47,7 @@ const fetcher = (variables, token) => {
repositories(first: 100, ownerAffiliations: OWNER, orderBy: {direction: DESC, field: STARGAZERS}) {
totalCount
nodes {
name
stargazers {
totalCount
}
@@ -108,6 +109,7 @@ async function fetchStats(
username,
count_private = false,
include_all_commits = false,
exclude_repo = [],
) {
if (!username) throw new MissingParamError(["username"]);
@@ -133,6 +135,15 @@ async function fetchStats(
const user = res.data.data.user;
// populate repoToHide map for quick lookup
// while filtering out
let repoToHide = {};
if (exclude_repo) {
exclude_repo.forEach((repoName) => {
repoToHide[repoName] = true;
});
}
stats.name = user.name || user.login;
stats.totalIssues = user.openIssues.totalCount + user.closedIssues.totalCount;
@@ -154,9 +165,14 @@ async function fetchStats(
stats.totalPRs = user.pullRequests.totalCount;
stats.contributedTo = user.repositoriesContributedTo.totalCount;
stats.totalStars = user.repositories.nodes.reduce((prev, curr) => {
return prev + curr.stargazers.totalCount;
}, 0);
// Retrieve stars while filtering out repositories to be hidden
stats.totalStars = user.repositories.nodes
.filter((data) => {
return !repoToHide[data.name];
})
.reduce((prev, curr) => {
return prev + curr.stargazers.totalCount;
}, 0);
stats.rank = calculateRank({
totalCommits: stats.totalCommits,