Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added include_forks path parameter #2611

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions api/top-langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default async (req, res) => {
border_color,
disable_animations,
hide_progress,
include_forks,
} = req.query;
res.setHeader("Content-Type", "image/svg+xml");

Expand All @@ -46,6 +47,7 @@ export default async (req, res) => {
const topLangs = await fetchTopLanguages(
username,
parseArray(exclude_repo),
parseBoolean(include_forks) ? null : false,
);

const cacheSeconds = clampValue(
Expand Down
12 changes: 8 additions & 4 deletions src/fetchers/top-languages-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const fetcher = (variables, token) => {
return request(
{
query: `
query userInfo($login: String!) {
query userInfo($login: String!, $isFork: Boolean) {
user(login: $login) {
# fetch only owner repos & not forks
repositories(ownerAffiliations: OWNER, isFork: false, first: 100) {
repositories(ownerAffiliations: OWNER, isFork: $isFork, first: 100) {
nodes {
name
languages(first: 10, orderBy: {field: SIZE, direction: DESC}) {
Expand Down Expand Up @@ -54,10 +54,14 @@ const fetcher = (variables, token) => {
* @param {string[]} exclude_repo List of repositories to exclude.
* @returns {Promise<import("./types").TopLangData>} Top languages data.
*/
const fetchTopLanguages = async (username, exclude_repo = []) => {
const fetchTopLanguages = async (
username,
exclude_repo = [],
isFork = null,
) => {
if (!username) throw new MissingParamError(["username"]);

const res = await retryer(fetcher, { login: username });
const res = await retryer(fetcher, { login: username, isFork });

if (res.data.errors) {
logger.error(res.data.errors);
Expand Down