Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
parameterize affiliation
  • Loading branch information
developStorm committed Dec 4, 2021
commit 41e4424c8fad4867a84d617f139497688315759d
2 changes: 2 additions & 0 deletions api/top-langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = async (req, res) => {
locale,
border_radius,
border_color,
role,
} = req.query;
res.setHeader("Content-Type", "image/svg+xml");

Expand All @@ -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),
);

Expand Down
11 changes: 8 additions & 3 deletions src/fetchers/top-languages-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}) {
Expand All @@ -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);
Expand Down