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 ability for top languages to count more than 100 repos #3483

Closed
wants to merge 1 commit into from
Closed
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
55 changes: 35 additions & 20 deletions src/fetchers/top-languages-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const fetcher = (variables, token) => {
return request(
{
query: `
query userInfo($login: String!) {
query userInfo($login: String!, $afterCur: String) {
user(login: $login) {
# fetch only owner repos & not forks
repositories(ownerAffiliations: OWNER, isFork: false, first: 100) {
repositories(ownerAffiliations: OWNER, isFork: false, first: 100, after: $afterCur) {
nodes {
name
languages(first: 10, orderBy: {field: SIZE, direction: DESC}) {
Expand All @@ -40,6 +40,11 @@ const fetcher = (variables, token) => {
}
}
}
pageInfo {
startCursor
hasNextPage
endCursor
}
}
}
}
Expand Down Expand Up @@ -75,29 +80,39 @@ const fetchTopLanguages = async (
throw new MissingParamError(["username"]);
}

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

if (res.data.errors) {
logger.error(res.data.errors);
if (res.data.errors[0].type === "NOT_FOUND") {
throw new CustomError(
res.data.errors[0].message || "Could not fetch user.",
CustomError.USER_NOT_FOUND,
);
}
if (res.data.errors[0].message) {
let repoNodes = [];
let hasNextPage = true;
let afterCursor = null;
let res;

while (hasNextPage) {
res = await retryer(fetcher, { login: username, afterCur: afterCursor });

if (res.data.errors) {
logger.error(res.data.errors);
if (res.data.errors[0].type === "NOT_FOUND") {
throw new CustomError(
res.data.errors[0].message || "Could not fetch user.",
CustomError.USER_NOT_FOUND,
);
}
if (res.data.errors[0].message) {
throw new CustomError(
wrapTextMultiline(res.data.errors[0].message, 90, 1)[0],
res.statusText,
);
}
throw new CustomError(
wrapTextMultiline(res.data.errors[0].message, 90, 1)[0],
res.statusText,
"Something went wrong while trying to retrieve the language data using the GraphQL API.",
CustomError.GRAPHQL_ERROR,
);
}
throw new CustomError(
"Something went wrong while trying to retrieve the language data using the GraphQL API.",
CustomError.GRAPHQL_ERROR,
);

hasNextPage = res.data.data.user.repositories.pageInfo.hasNextPage;
afterCursor = res.data.data.user.repositories.pageInfo.endCursor;
repoNodes = [...repoNodes, ...res.data.data.user.repositories.nodes];
}

let repoNodes = res.data.data.user.repositories.nodes;
let repoToHide = {};

// populate repoToHide map for quick lookup
Expand Down
5 changes: 5 additions & 0 deletions tests/fetchTopLanguages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ const data_langs = {
},
},
],
pageInfo: {
startCursor: "Y3Vyc29yOnYyOpHOKejkVw==",
hasNextPage: false,
endCursor: "Y3Vyc29yOnYyOpHOKqrSXg==",
},
},
},
},
Expand Down
5 changes: 5 additions & 0 deletions tests/top-langs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const data_langs = {
},
},
],
pageInfo: {
startCursor: "Y3Vyc29yOnYyOpHOKejkVw==",
hasNextPage: false,
endCursor: "Y3Vyc29yOnYyOpHOKqrSXg==",
},
},
},
},
Expand Down