feat: add support for EXCLUDE_REPO env variable (#1299)

* Add support for EXCLUDE_REPO env variable

* review

* docs

* refactor

---------

Co-authored-by: Alexandr <qwerty541zxc@gmail.com>
This commit is contained in:
Bear_03
2025-10-05 23:49:17 +03:00
committed by GitHub
co-authored by Alexandr
parent 39b93b57c8
commit a697215f8e
4 changed files with 16 additions and 3 deletions
+1
View File
@@ -888,6 +888,7 @@ GitHub Readme Stats provides several environment variables that can be used to c
* `CACHE_SECONDS`: This takes precedence over our cache minimum and maximum values and can circumvent these values for self-hosted instances.
* `WHITELIST`: A comma-separated list of GitHub usernames that are allowed to access your instance. If this variable is not set, all usernames are allowed.
* `GIST_WHITELIST`: A comma-separated list of GitHub gist IDs that are allowed to be accessed on your instance. If this variable is not set, all gist IDs are allowed.
* `EXCLUDE_REPO`: A comma-separated list of repositories that will be excluded from stats and top languages cards on your instance. This allows repository exclusion without exposing repository names in public URLs. This enhances privacy for self-hosted instances that include private repositories in stats cards.
See [the Vercel documentation](https://vercel.com/docs/concepts/projects/environment-variables) on adding these environment variables to your Vercel instance.
+6
View File
@@ -0,0 +1,6 @@
const excludeRepositories = process.env.EXCLUDE_REPO
? process.env.EXCLUDE_REPO.split(",")
: [];
export { excludeRepositories };
export default excludeRepositories;
+4 -1
View File
@@ -1,4 +1,5 @@
// @ts-check
import axios from "axios";
import * as dotenv from "dotenv";
import githubUsernameRegex from "github-username-regex";
@@ -11,6 +12,7 @@ import {
request,
wrapTextMultiline,
} from "../common/utils.js";
import excludeRepositories from "../common/excludeRepo.js";
dotenv.config();
@@ -312,7 +314,8 @@ const fetchStats = async (
stats.contributedTo = user.repositoriesContributedTo.totalCount;
// Retrieve stars while filtering out repositories to be hidden.
let repoToHide = new Set(exclude_repo);
const allExcludedRepos = [...exclude_repo, ...excludeRepositories];
let repoToHide = new Set(allExcludedRepos);
stats.totalStars = user.repositories.nodes
.filter((data) => {
+5 -2
View File
@@ -1,4 +1,5 @@
// @ts-check
import { retryer } from "../common/retryer.js";
import {
CustomError,
@@ -7,6 +8,7 @@ import {
request,
wrapTextMultiline,
} from "../common/utils.js";
import excludeRepositories from "../common/excludeRepo.js";
/**
* @typedef {import("axios").AxiosRequestHeaders} AxiosRequestHeaders Axios request headers.
@@ -99,11 +101,12 @@ const fetchTopLanguages = async (
let repoNodes = res.data.data.user.repositories.nodes;
let repoToHide = {};
const allExcludedRepos = [...exclude_repo, ...excludeRepositories];
// populate repoToHide map for quick lookup
// while filtering out
if (exclude_repo) {
exclude_repo.forEach((repoName) => {
if (allExcludedRepos) {
allExcludedRepos.forEach((repoName) => {
repoToHide[repoName] = true;
});
}