parameterize affiliation

This commit is contained in:
devStorm
2021-12-04 15:19:13 -05:00
parent 45e211eb0e
commit 41e4424c8f
2 changed files with 10 additions and 3 deletions
+2
View File
@@ -30,6 +30,7 @@ module.exports = async (req, res) => {
locale,
border_radius,
border_color,
role,
} = req.query;
res.setHeader("Content-Type", "image/svg+xml");
@@ -45,6 +46,7 @@ module.exports = async (req, res) => {
const topLangs = await fetchTopLanguages(
username,
parseArray(exclude_repo),
parseArray(role).filter(value => ['OWNER', 'ORGANIZATION_MEMBER', 'COLLABORATOR'].includes(value)),
parseArray(hide),
);
+8 -3
View File
@@ -3,13 +3,18 @@ const retryer = require("../common/retryer");
require("dotenv").config();
const fetcher = (variables, token) => {
let ownerAffiliations = ["OWNER"];
if (variables.ownerAffiliations.length > 0) {
ownerAffiliations = variables.ownerAffiliations;
}
delete variables.ownerAffiliations;
return request(
{
query: `
query userInfo($login: String!) {
user(login: $login) {
# fetch only owner repos & not forks
repositories(ownerAffiliations: [OWNER, ORGANIZATION_MEMBER, COLLABORATOR], isFork: false, first: 100) {
repositories(ownerAffiliations: [${ownerAffiliations.join(', ')}], isFork: false, first: 100) {
nodes {
name
languages(first: 10, orderBy: {field: SIZE, direction: DESC}) {
@@ -34,10 +39,10 @@ const fetcher = (variables, token) => {
);
};
async function fetchTopLanguages(username, exclude_repo = []) {
async function fetchTopLanguages(username, exclude_repo = [], ownerAffiliations) {
if (!username) throw Error("Invalid username");
const res = await retryer(fetcher, { login: username });
const res = await retryer(fetcher, { login: username, ownerAffiliations });
if (res.data.errors) {
logger.error(res.data.errors);