Skip to content

Commit ada9cf4

Browse files
authored
feat: add INCLUDE_ORGS env variable (anuraghazra#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).
1 parent 3cb205c commit ada9cf4

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

src/common/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const isValidHexColor = (hexColor) => {
7777
/**
7878
* Returns boolean if value is either "true" or "false" else the value as it is.
7979
*
80-
* @param {string | boolean} value The value to parse.
80+
* @param {string | boolean| undefined} value The value to parse.
8181
* @returns {boolean | undefined } The parsed value.
8282
*/
8383
const parseBoolean = (value) => {

src/fetchers/stats-fetcher.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
CustomError,
88
logger,
99
MissingParamError,
10+
parseBoolean,
1011
request,
1112
wrapTextMultiline,
1213
} from "../common/utils.js";
@@ -22,7 +23,7 @@ const fetcher = (variables, token) => {
2223
return request(
2324
{
2425
query: `
25-
query userInfo($login: String!) {
26+
query userInfo($login: String!, $ownerAffiliations: [RepositoryAffiliation]) {
2627
user(login: $login) {
2728
name
2829
login
@@ -45,7 +46,7 @@ const fetcher = (variables, token) => {
4546
followers {
4647
totalCount
4748
}
48-
repositories(ownerAffiliations: OWNER) {
49+
repositories(ownerAffiliations: $ownerAffiliations) {
4950
totalCount
5051
}
5152
}
@@ -70,9 +71,9 @@ const repositoriesFetcher = (variables, token) => {
7071
return request(
7172
{
7273
query: `
73-
query userInfo($login: String!, $after: String) {
74+
query userInfo($login: String!, $after: String, $ownerAffiliations: [RepositoryAffiliation]) {
7475
user(login: $login) {
75-
repositories(first: 100, ownerAffiliations: OWNER, orderBy: {direction: DESC, field: STARGAZERS}, after: $after) {
76+
repositories(first: 100, ownerAffiliations: $ownerAffiliations, orderBy: {direction: DESC, field: STARGAZERS}, after: $after) {
7677
nodes {
7778
name
7879
stargazers {
@@ -149,7 +150,14 @@ const totalStarsFetcher = async (username, repoToHide) => {
149150
let hasNextPage = true;
150151
let endCursor = null;
151152
while (hasNextPage) {
152-
const variables = { login: username, first: 100, after: endCursor };
153+
const variables = {
154+
login: username,
155+
first: 100,
156+
after: endCursor,
157+
ownerAffiliations: parseBoolean(process.env.INCLUDE_ORGS)
158+
? ["OWNER", "COLLABORATOR"]
159+
: ["OWNER"],
160+
};
153161
let res = await retryer(repositoriesFetcher, variables);
154162

155163
if (res.data.errors) {
@@ -203,7 +211,12 @@ const fetchStats = async (
203211
rank: { level: "C", score: 0 },
204212
};
205213

206-
let res = await retryer(fetcher, { login: username });
214+
let res = await retryer(fetcher, {
215+
login: username,
216+
ownerAffiliations: parseBoolean(process.env.INCLUDE_ORGS)
217+
? ["OWNER", "COLLABORATOR"]
218+
: ["OWNER"],
219+
});
207220

208221
// Catch GraphQL errors.
209222
if (res.data.errors) {

src/fetchers/top-languages-fetcher.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
CustomError,
55
logger,
66
MissingParamError,
7+
parseBoolean,
78
request,
89
wrapTextMultiline,
910
} from "../common/utils.js";
@@ -19,10 +20,10 @@ const fetcher = (variables, token) => {
1920
return request(
2021
{
2122
query: `
22-
query userInfo($login: String!) {
23+
query userInfo($login: String!, $ownerAffiliations: [RepositoryAffiliation]) {
2324
user(login: $login) {
2425
# fetch only owner repos & not forks
25-
repositories(ownerAffiliations: OWNER, isFork: false, first: 100) {
26+
repositories(ownerAffiliations: $ownerAffiliations, isFork: false, first: 100) {
2627
nodes {
2728
name
2829
languages(first: 10, orderBy: {field: SIZE, direction: DESC}) {
@@ -57,7 +58,12 @@ const fetcher = (variables, token) => {
5758
const fetchTopLanguages = async (username, exclude_repo = []) => {
5859
if (!username) throw new MissingParamError(["username"]);
5960

60-
const res = await retryer(fetcher, { login: username });
61+
const res = await retryer(fetcher, {
62+
login: username,
63+
ownerAffiliations: parseBoolean(process.env.INCLUDE_ORGS)
64+
? ["OWNER", "COLLABORATOR"]
65+
: ["OWNER"],
66+
});
6167

6268
if (res.data.errors) {
6369
logger.error(res.data.errors);

0 commit comments

Comments
 (0)