diff --git a/src/fetchers/top-languages-fetcher.js b/src/fetchers/top-languages-fetcher.js index 7e248fb1e03cc..1d3a684da89dd 100644 --- a/src/fetchers/top-languages-fetcher.js +++ b/src/fetchers/top-languages-fetcher.js @@ -6,10 +6,16 @@ const fetcher = (variables, token) => { return request( { query: ` - query userInfo($login: String!) { + query userInfo($login: String!, $first: Int!, $after: String) { user(login: $login) { # fetch only owner repos & not forks - repositories(ownerAffiliations: OWNER, isFork: false, first: 100) { + repositories( + ownerAffiliations: OWNER, isFork: false, + first: $first, after: $after + ) { + edges { + cursor + } nodes { name languages(first: 10, orderBy: {field: SIZE, direction: DESC}) { @@ -37,14 +43,28 @@ const fetcher = (variables, token) => { async function fetchTopLanguages(username, exclude_repo = []) { if (!username) throw Error("Invalid username"); - const res = await retryer(fetcher, { login: username }); + const pageSize = 100; + let pageCursor = null; + + let repoNodes = []; + + while (true) { + const variables = { login: username, first: pageSize, after: pageCursor }; + const res = await retryer(fetcher, variables); + + if (res.data.errors) { + logger.error(res.data.errors); + throw Error(res.data.errors[0].message || "Could not fetch user"); + } - if (res.data.errors) { - logger.error(res.data.errors); - throw Error(res.data.errors[0].message || "Could not fetch user"); + repoNodes = repoNodes.concat(res.data.data.user.repositories.nodes); + if (!res.data.data.user.repositories.edges || + res.data.data.user.repositories.edges.length < pageSize) { + break; + } + pageCursor = res.data.data.user.repositories.edges[pageSize - 1].cursor; } - let repoNodes = res.data.data.user.repositories.nodes; let repoToHide = {}; // populate repoToHide map for quick lookup diff --git a/tests/fetchTopLanguages.test.js b/tests/fetchTopLanguages.test.js index f9aaa024390e5..35b23eef61c1f 100644 --- a/tests/fetchTopLanguages.test.js +++ b/tests/fetchTopLanguages.test.js @@ -13,6 +13,12 @@ const data_langs = { data: { user: { repositories: { + edges: [ + { cursor: "1" }, + { cursor: "2" }, + { cursor: "3" }, + { cursor: "4" }, + ], nodes: [ { languages: {