mirror of
https://github.com/tiennm99/github-readme-stats.git
synced 2026-08-11 16:25:26 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user