From 1383a636bb4b2624ead95e414783fc0773242357 Mon Sep 17 00:00:00 2001 From: anuraghazra Date: Thu, 9 Jul 2020 18:46:41 +0530 Subject: [PATCH] feat: added icons support --- api/index.js | 63 +++++++++++++++++++++++++++++++++++++++------------- readme.md | 14 ++++++++++++ 2 files changed, 61 insertions(+), 16 deletions(-) diff --git a/api/index.js b/api/index.js index d951d71e..6343f5d6 100644 --- a/api/index.js +++ b/api/index.js @@ -16,6 +16,9 @@ async function fetchStats(username) { repositoriesContributedTo(first: 100, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY]) { totalCount } + contributionsCollection { + totalCommitContributions + } pullRequests(first: 100) { totalCount } @@ -41,6 +44,7 @@ async function fetchStats(username) { const stats = { name: "", totalPRs: 0, + totalCommits: 0, totalIssues: 0, totalStars: 0, contributedTo: 0, @@ -51,6 +55,7 @@ async function fetchStats(username) { stats.name = user.name; stats.totalIssues = user.issues.totalCount; + stats.totalCommits = user.contributionsCollection.totalCommitContributions; stats.totalPRs = user.pullRequests.totalCount; stats.contributedTo = user.repositoriesContributedTo.totalCount; @@ -62,43 +67,66 @@ async function fetchStats(username) { } const renderSVG = (stats, options) => { - const { name, totalStars, totalIssues, totalPRs, contributedTo } = stats; - const { hide } = options || {}; - const height = 150 - hide.length * 20; + const { + name, + totalStars, + totalCommits, + totalIssues, + totalPRs, + contributedTo, + } = stats; + const { hide, show_icons } = options || {}; const STAT_MAP = { stars: ` - Total Stars: - ${totalStars} + + Total Stars: + ${totalStars} + `, + commits: ` + + 🕗 Total Commits: + ${totalCommits} `, prs: ` - Total PRs: - ${totalPRs} + + 🔀 Total PRs: + ${totalPRs} `, issues: ` - Total Issues: - ${totalIssues} + + Total Issues: + ${totalIssues} `, contribs: ` - Contributed to: - ${contributedTo} repos + 📕 Contributed to: + ${contributedTo} repos `, }; + const statItems = Object.keys(STAT_MAP) + .filter((key) => !hide.includes(key)) + .map((key) => STAT_MAP[key]); + + const height = 45 + (statItems.length + 1) * 25; + return ` - + ${name}'s github stats - ${Object.keys(STAT_MAP) - .filter((key) => !hide.includes(key)) - .map((key) => STAT_MAP[key])} + ${statItems} `; @@ -107,9 +135,11 @@ const renderSVG = (stats, options) => { module.exports = async (req, res) => { const username = req.query.username; const hide = req.query.hide; + const show_icons = req.query.show_icons; let { name, totalPRs, + totalCommits, totalStars, totalIssues, contributedTo, @@ -121,11 +151,12 @@ module.exports = async (req, res) => { { name, totalStars, + totalCommits, totalIssues, totalPRs, contributedTo, }, - { hide: JSON.parse(hide || "[]") } + { hide: JSON.parse(hide || "[]"), show_icons } ) ); }; diff --git a/readme.md b/readme.md index 02788efa..eba58f32 100644 --- a/readme.md +++ b/readme.md @@ -22,14 +22,28 @@ To hide any specific stats you can pass a query parameter `?hide=` with an array ![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=["contribs","prs"]) ``` +### Showing icons + +To enable icons you can pass `show_icons=true` in the query param like so + +```md +![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true) +``` + ## Demo +- Default + ![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra) - Hiding specific stats ![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=["contribs","issues"]) +- Showing icons + +![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=["issues"]&show_icons=true) + Contributions are welcomed! <3 Made with :heart: and javascript.