diff --git a/src/fetchTopLanguages.js b/src/fetchTopLanguages.js index ba8d64fdb9e3e..97c8152be6d3b 100644 --- a/src/fetchTopLanguages.js +++ b/src/fetchTopLanguages.js @@ -8,9 +8,10 @@ const fetcher = (variables, token) => { query: ` query userInfo($login: String!) { user(login: $login) { - repositories(isFork: false, first: 100, orderBy: {field: UPDATED_AT, direction: DESC}) { + # fetch only owner repos & not forks + repositories(ownerAffiliations: OWNER, isFork: false, first: 100) { nodes { - languages(first: 1, orderBy: {field: SIZE, direction: DESC}) { + languages(first: 10, orderBy: {field: SIZE, direction: DESC}) { edges { size node { @@ -49,18 +50,13 @@ async function fetchTopLanguages(username) { .filter((node) => { return node.languages.edges.length > 0; }) - .sort((a, b) => { - return b.languages.edges[0].size - a.languages.edges[0].size; - }) - .map((node) => { - return node.languages.edges[0]; - }) + .reduce((acc, curr) => curr.languages.edges.concat(acc), []) + .sort((a, b) => b.size - a.size) .reduce((acc, prev) => { let langSize = prev.size; if (acc[prev.node.name] && prev.node.name === acc[prev.node.name].name) { langSize = prev.size + acc[prev.node.name].size; } - return { ...acc, [prev.node.name]: { diff --git a/src/renderTopLanguages.js b/src/renderTopLanguages.js index e3c290cb7ef72..21594df7d2663 100644 --- a/src/renderTopLanguages.js +++ b/src/renderTopLanguages.js @@ -185,7 +185,7 @@ const renderTopLanguages = (topLangs, options = {}) => { ${ hide_title ? "" - : `Top Languages` + : `Most Used Languages` } diff --git a/tests/renderTopLanguages.test.js b/tests/renderTopLanguages.test.js index 3c192630a3e6e..a6f94a8b79bb4 100644 --- a/tests/renderTopLanguages.test.js +++ b/tests/renderTopLanguages.test.js @@ -32,7 +32,7 @@ describe("Test renderTopLanguages", () => { document.body.innerHTML = renderTopLanguages(langs); expect(queryByTestId(document.body, "header")).toHaveTextContent( - "Top Languages" + "Most Used Languages" ); expect(queryAllByTestId(document.body, "lang-name")[0]).toHaveTextContent( @@ -211,7 +211,7 @@ describe("Test renderTopLanguages", () => { it('should render with layout compact', () => { document.body.innerHTML = renderTopLanguages(langs, {layout: 'compact'}); - expect(queryByTestId(document.body, "header")).toHaveTextContent("Top Languages"); + expect(queryByTestId(document.body, "header")).toHaveTextContent("Most Used Languages"); expect(queryAllByTestId(document.body, "lang-name")[0]).toHaveTextContent("HTML 40.00%"); expect(queryAllByTestId(document.body, "lang-progress")[0]).toHaveAttribute("width","120.00"); diff --git a/tests/top-langs.test.js b/tests/top-langs.test.js index 330acfa465797..a214eb4e925ac 100644 --- a/tests/top-langs.test.js +++ b/tests/top-langs.test.js @@ -12,7 +12,7 @@ const data_langs = { nodes: [ { languages: { - edges: [{ size: 100, node: { color: "#0f0", name: "HTML" } }], + edges: [{ size: 150, node: { color: "#0f0", name: "HTML" } }], }, }, { @@ -55,7 +55,7 @@ const langs = { HTML: { color: "#0f0", name: "HTML", - size: 200, + size: 250, }, javascript: { color: "#0ff",