mirror of
https://github.com/tiennm99/github-readme-stats.git
synced 2026-09-04 10:16:45 +00:00
feat: add INCLUDE_ORGS env variable (#2275)
This commit adds an INCLUDE_ORGS ENV variable that can be used to include results from organizations into the GRS cards for self-deployed Vercel instances. **Warning** This is a hidden feature since we can not officially support this on the Public Vercel instance due to GraphQL and Vercel rate/timeout limits. You can set this env variable via Vercel's ENV variable menu (see https://vercel.com/docs/concepts/projects/environment-variables).
This commit is contained in:
+1
-1
@@ -77,7 +77,7 @@ const isValidHexColor = (hexColor) => {
|
|||||||
/**
|
/**
|
||||||
* Returns boolean if value is either "true" or "false" else the value as it is.
|
* Returns boolean if value is either "true" or "false" else the value as it is.
|
||||||
*
|
*
|
||||||
* @param {string | boolean} value The value to parse.
|
* @param {string | boolean| undefined} value The value to parse.
|
||||||
* @returns {boolean | undefined } The parsed value.
|
* @returns {boolean | undefined } The parsed value.
|
||||||
*/
|
*/
|
||||||
const parseBoolean = (value) => {
|
const parseBoolean = (value) => {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
CustomError,
|
CustomError,
|
||||||
logger,
|
logger,
|
||||||
MissingParamError,
|
MissingParamError,
|
||||||
|
parseBoolean,
|
||||||
request,
|
request,
|
||||||
wrapTextMultiline,
|
wrapTextMultiline,
|
||||||
} from "../common/utils.js";
|
} from "../common/utils.js";
|
||||||
@@ -22,7 +23,7 @@ const fetcher = (variables, token) => {
|
|||||||
return request(
|
return request(
|
||||||
{
|
{
|
||||||
query: `
|
query: `
|
||||||
query userInfo($login: String!) {
|
query userInfo($login: String!, $ownerAffiliations: [RepositoryAffiliation]) {
|
||||||
user(login: $login) {
|
user(login: $login) {
|
||||||
name
|
name
|
||||||
login
|
login
|
||||||
@@ -45,7 +46,7 @@ const fetcher = (variables, token) => {
|
|||||||
followers {
|
followers {
|
||||||
totalCount
|
totalCount
|
||||||
}
|
}
|
||||||
repositories(ownerAffiliations: OWNER) {
|
repositories(ownerAffiliations: $ownerAffiliations) {
|
||||||
totalCount
|
totalCount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,9 +71,9 @@ const repositoriesFetcher = (variables, token) => {
|
|||||||
return request(
|
return request(
|
||||||
{
|
{
|
||||||
query: `
|
query: `
|
||||||
query userInfo($login: String!, $after: String) {
|
query userInfo($login: String!, $after: String, $ownerAffiliations: [RepositoryAffiliation]) {
|
||||||
user(login: $login) {
|
user(login: $login) {
|
||||||
repositories(first: 100, ownerAffiliations: OWNER, orderBy: {direction: DESC, field: STARGAZERS}, after: $after) {
|
repositories(first: 100, ownerAffiliations: $ownerAffiliations, orderBy: {direction: DESC, field: STARGAZERS}, after: $after) {
|
||||||
nodes {
|
nodes {
|
||||||
name
|
name
|
||||||
stargazers {
|
stargazers {
|
||||||
@@ -149,7 +150,14 @@ const totalStarsFetcher = async (username, repoToHide) => {
|
|||||||
let hasNextPage = true;
|
let hasNextPage = true;
|
||||||
let endCursor = null;
|
let endCursor = null;
|
||||||
while (hasNextPage) {
|
while (hasNextPage) {
|
||||||
const variables = { login: username, first: 100, after: endCursor };
|
const variables = {
|
||||||
|
login: username,
|
||||||
|
first: 100,
|
||||||
|
after: endCursor,
|
||||||
|
ownerAffiliations: parseBoolean(process.env.INCLUDE_ORGS)
|
||||||
|
? ["OWNER", "COLLABORATOR"]
|
||||||
|
: ["OWNER"],
|
||||||
|
};
|
||||||
let res = await retryer(repositoriesFetcher, variables);
|
let res = await retryer(repositoriesFetcher, variables);
|
||||||
|
|
||||||
if (res.data.errors) {
|
if (res.data.errors) {
|
||||||
@@ -203,7 +211,12 @@ const fetchStats = async (
|
|||||||
rank: { level: "C", score: 0 },
|
rank: { level: "C", score: 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = await retryer(fetcher, { login: username });
|
let res = await retryer(fetcher, {
|
||||||
|
login: username,
|
||||||
|
ownerAffiliations: parseBoolean(process.env.INCLUDE_ORGS)
|
||||||
|
? ["OWNER", "COLLABORATOR"]
|
||||||
|
: ["OWNER"],
|
||||||
|
});
|
||||||
|
|
||||||
// Catch GraphQL errors.
|
// Catch GraphQL errors.
|
||||||
if (res.data.errors) {
|
if (res.data.errors) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
CustomError,
|
CustomError,
|
||||||
logger,
|
logger,
|
||||||
MissingParamError,
|
MissingParamError,
|
||||||
|
parseBoolean,
|
||||||
request,
|
request,
|
||||||
wrapTextMultiline,
|
wrapTextMultiline,
|
||||||
} from "../common/utils.js";
|
} from "../common/utils.js";
|
||||||
@@ -19,10 +20,10 @@ const fetcher = (variables, token) => {
|
|||||||
return request(
|
return request(
|
||||||
{
|
{
|
||||||
query: `
|
query: `
|
||||||
query userInfo($login: String!) {
|
query userInfo($login: String!, $ownerAffiliations: [RepositoryAffiliation]) {
|
||||||
user(login: $login) {
|
user(login: $login) {
|
||||||
# fetch only owner repos & not forks
|
# fetch only owner repos & not forks
|
||||||
repositories(ownerAffiliations: OWNER, isFork: false, first: 100) {
|
repositories(ownerAffiliations: $ownerAffiliations, isFork: false, first: 100) {
|
||||||
nodes {
|
nodes {
|
||||||
name
|
name
|
||||||
languages(first: 10, orderBy: {field: SIZE, direction: DESC}) {
|
languages(first: 10, orderBy: {field: SIZE, direction: DESC}) {
|
||||||
@@ -57,7 +58,12 @@ const fetcher = (variables, token) => {
|
|||||||
const fetchTopLanguages = async (username, exclude_repo = []) => {
|
const fetchTopLanguages = async (username, exclude_repo = []) => {
|
||||||
if (!username) throw new MissingParamError(["username"]);
|
if (!username) throw new MissingParamError(["username"]);
|
||||||
|
|
||||||
const res = await retryer(fetcher, { login: username });
|
const res = await retryer(fetcher, {
|
||||||
|
login: username,
|
||||||
|
ownerAffiliations: parseBoolean(process.env.INCLUDE_ORGS)
|
||||||
|
? ["OWNER", "COLLABORATOR"]
|
||||||
|
: ["OWNER"],
|
||||||
|
});
|
||||||
|
|
||||||
if (res.data.errors) {
|
if (res.data.errors) {
|
||||||
logger.error(res.data.errors);
|
logger.error(res.data.errors);
|
||||||
|
|||||||
Reference in New Issue
Block a user