From b63c10f5455cb0a484cb943baec91e308387d2dd Mon Sep 17 00:00:00 2001 From: rjoydip Date: Wed, 5 Aug 2020 12:37:01 +0530 Subject: [PATCH] change logic as per the request --- api/index.js | 2 ++ readme.md | 16 ++++++++++++---- src/cards/stats-card.js | 17 ++++++++++++----- tests/renderStatsCard.test.js | 15 ++++++++++----- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/api/index.js b/api/index.js index b1b0b3a7..74d26ade 100644 --- a/api/index.js +++ b/api/index.js @@ -17,6 +17,7 @@ module.exports = async (req, res) => { hide_border, hide_rank, show_icons, + show_forks, count_private, include_all_commits, line_height, @@ -61,6 +62,7 @@ module.exports = async (req, res) => { hide_title: parseBoolean(hide_title), hide_border: parseBoolean(hide_border), hide_rank: parseBoolean(hide_rank), + show_forks: parseBoolean(show_forks), include_all_commits: parseBoolean(include_all_commits), line_height, title_color, diff --git a/readme.md b/readme.md index 0131f3e7..e2827709 100644 --- a/readme.md +++ b/readme.md @@ -78,6 +78,14 @@ To hide any specific stats, you can pass a query parameter `?hide=` with comma s ![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=contribs,prs) ``` +### Show total forked repository count + +To show forked repository count, you can pass a query parameter `show_forks=true`. + +```md +![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_forks=true) +``` + ### Adding private contributions count to total commits count You can add the count of all your private contributions to the total commits count by using the query parameter `?count_private=true`. @@ -120,7 +128,7 @@ You can look at a preview for [all available themes](./themes/README.md) or chec You can customize the appearance of your `Stats Card` or `Repo Card` however you want with URL params. -#### Common Options: +#### Common Options - `title_color` - Card's title color _(hex color)_ - `text_color` - Body text color _(hex color)_ @@ -131,7 +139,7 @@ You can customize the appearance of your `Stats Card` or `Repo Card` however you > Note on cache: Repo cards have default cache of 30mins (1800 seconds) if the fork count & star count is less than 1k otherwise it's 2hours (7200). Also note that cache is clamped to minimum of 30min and maximum of 24hours -#### Stats Card Exclusive Options: +#### Stats Card Exclusive Options - `hide` - Hide's the specified items from stats _(Comma seperated values)_ - `hide_title` - _(boolean)_ @@ -141,11 +149,11 @@ You can customize the appearance of your `Stats Card` or `Repo Card` however you - `count_private` - Count private commits _(boolean)_ - `line_height` - Sets the line-height between text _(number)_ -#### Repo Card Exclusive Options: +#### Repo Card Exclusive Options - `show_owner` - Show the owner name of the repo _(boolean)_ -#### Language Card Exclusive Options: +#### Language Card Exclusive Options - `hide` - Hide the languages specified from the card _(Comma seperated values)_ - `hide_title` - _(boolean)_ diff --git a/src/cards/stats-card.js b/src/cards/stats-card.js index 1b35d33b..d772f174 100644 --- a/src/cards/stats-card.js +++ b/src/cards/stats-card.js @@ -51,7 +51,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { totalPRs, contributedTo, rank, - totalForkRepositories + totalForkRepositories, } = stats; const { hide = [], @@ -60,6 +60,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { hide_border = false, hide_rank = false, include_all_commits = false, + show_forks = false, line_height = 25, title_color, icon_color, @@ -86,6 +87,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { label: "Total Stars", value: totalStars, id: "stars", + isShowEnable: true, }, commits: { icon: icons.commits, @@ -94,40 +96,45 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => { }`, value: totalCommits, id: "commits", + isShowEnable: true, }, prs: { icon: icons.prs, label: "Total PRs", value: totalPRs, id: "prs", + isShowEnable: true, }, issues: { icon: icons.issues, label: "Total Issues", value: totalIssues, id: "issues", + isShowEnable: true, }, contribs: { icon: icons.contribs, label: "Contributed to", value: contributedTo, id: "contribs", + isShowEnable: true, }, forks: { icon: icons.fork, label: "Total Forks", value: totalForkRepositories, id: "forks", + isShowEnable: show_forks, }, }; // filter out hidden stats defined by user & create the text nodes - const statItems = Object.keys(STATS) - .filter((key) => !hide.includes(key)) - .map((key, index) => + const statItems = Object.entries(STATS) + .filter((item) => !hide.includes(item[0]) && item[1].isShowEnable) + .map((item, index) => // create the text nodes, and pass index so that we can calculate the line spacing createTextNode({ - ...STATS[key], + ...STATS[item[0]], index, showIcons: show_icons, shiftValuePos: !include_all_commits, diff --git a/tests/renderStatsCard.test.js b/tests/renderStatsCard.test.js index ddeb8bc7..fa28e7d3 100644 --- a/tests/renderStatsCard.test.js +++ b/tests/renderStatsCard.test.js @@ -18,7 +18,7 @@ describe("Test renderStatsCard", () => { totalPRs: 400, contributedTo: 500, rank: { level: "A+", score: 40 }, - totalForkRepositories: 3 + totalForkRepositories: 3, }; it("should render correctly", () => { @@ -30,12 +30,11 @@ describe("Test renderStatsCard", () => { expect( document.body.getElementsByTagName("svg")[0].getAttribute("height") - ).toBe("220"); + ).toBe("195"); expect(getByTestId(document.body, "stars").textContent).toBe("100"); expect(getByTestId(document.body, "commits").textContent).toBe("200"); expect(getByTestId(document.body, "issues").textContent).toBe("300"); expect(getByTestId(document.body, "prs").textContent).toBe("400"); - expect(getByTestId(document.body, "forks").textContent).toBe("3"); expect(getByTestId(document.body, "contribs").textContent).toBe("500"); expect(queryByTestId(document.body, "card-bg")).toBeInTheDocument(); expect(queryByTestId(document.body, "rank-circle")).toBeInTheDocument(); @@ -57,7 +56,7 @@ describe("Test renderStatsCard", () => { it("should hide individual stats", () => { document.body.innerHTML = renderStatsCard(stats, { - hide: ["issues", "prs", "contribs", "forks"], + hide: ["issues", "prs", "contribs"], }); expect( @@ -69,7 +68,6 @@ describe("Test renderStatsCard", () => { expect(queryByTestId(document.body, "issues")).toBeNull(); expect(queryByTestId(document.body, "prs")).toBeNull(); expect(queryByTestId(document.body, "contribs")).toBeNull(); - expect(queryByTestId(document.body, "forks")).toBeNull(); }); it("should hide_rank", () => { @@ -212,4 +210,11 @@ describe("Test renderStatsCard", () => { queryByTestId(document.body, "stars").previousElementSibling // the label ).not.toHaveAttribute("x"); }); + + it("should render properly with show_forks flag", () => { + document.body.innerHTML = renderStatsCard(stats, { show_forks: false }); + expect(queryByTestId(document.body, "forks")).toBeNull(); + document.body.innerHTML = renderStatsCard(stats, { show_forks: true }); + expect(queryByTestId(document.body, "forks")).toBeDefined(); + }); });