From 8e3147014ca6ef63033574f12c70c1372ec26db8 Mon Sep 17 00:00:00 2001
From: Rick Staa
Date: Mon, 24 Oct 2022 14:18:37 +0200
Subject: [PATCH 01/17] refactor: make issue templates required (#2226)
---
.github/ISSUE_TEMPLATE/bug_report.yml | 2 ++
.github/ISSUE_TEMPLATE/feature_request.yml | 2 ++
2 files changed, 4 insertions(+)
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
index 854c103feef8f..198bc80ef0fe4 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.yml
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -11,6 +11,8 @@ body:
attributes:
label: Describe the bug
description: A clear and concise description of what the bug is.
+ validations:
+ required: true
- type: textarea
attributes:
label: Expected behaviour
diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml
index 239fcc9147916..fe3a4b3411bfb 100644
--- a/.github/ISSUE_TEMPLATE/feature_request.yml
+++ b/.github/ISSUE_TEMPLATE/feature_request.yml
@@ -9,6 +9,8 @@ body:
description:
A clear and concise description of what the problem is. Ex. I'm always
frustrated when [...]
+ validations:
+ required: true
- type: textarea
attributes:
label: Describe the solution you'd like
From 199870aa9f7f59afd6950e7917cb758df2f8dea4 Mon Sep 17 00:00:00 2001
From: Frieder Bluemle
Date: Wed, 26 Oct 2022 07:41:59 -0700
Subject: [PATCH 02/17] refactor: fix GitHub capitalization (#2232)
---
docs/readme_kr.md | 6 +++---
docs/readme_np.md | 4 ++--
docs/readme_tr.md | 14 +++++++-------
readme.md | 4 ++--
scripts/helpers.js | 2 +-
scripts/preview-theme.js | 2 +-
scripts/push-theme-readme.sh | 2 +-
src/fetchers/repo-fetcher.js | 6 +++---
src/fetchers/stats-fetcher.js | 12 ++++++------
src/fetchers/top-languages-fetcher.js | 4 ++--
src/translations.js | 2 +-
11 files changed, 29 insertions(+), 29 deletions(-)
diff --git a/docs/readme_kr.md b/docs/readme_kr.md
index f5dfc9f2edf19..ce0b4ad0379ee 100644
--- a/docs/readme_kr.md
+++ b/docs/readme_kr.md
@@ -1,7 +1,7 @@
GitHub Readme Stats
- 동적으로 생성되는 Github 사용량 통계를 여러분의 README 에 추가해보세요!
+ 동적으로 생성되는 GitHub 사용량 통계를 여러분의 README 에 추가해보세요!
@@ -72,7 +72,7 @@
아래 코드를 복사해서 마크다운 파일에 붙여넣으면 끝이에요, 아주 간단해요!
-`?username=` 속성의 값을 Github 계정의 사용자 명(닉네임)으로 바꿔주세요.
+`?username=` 속성의 값을 GitHub 계정의 사용자 명(닉네임)으로 바꿔주세요.
```md
[![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra)](https://github.com/anuraghazra/github-readme-stats)
@@ -235,7 +235,7 @@ GitHub 저장소 여분 핀을 이용하면, 6개 이상의 저장소 핀을 여
# 언어 사용량 통계
-언어 사용량 통계 카드는 Github 사용자가 가장 많이 사용한 언어가 표시됩니다.
+언어 사용량 통계 카드는 GitHub 사용자가 가장 많이 사용한 언어가 표시됩니다.
_참고:
언어 사용량 통계는 GitHub 에서 가장 많이 사용된 언어의 표기일 뿐입니다.
diff --git a/docs/readme_np.md b/docs/readme_np.md
index 15bb34ba601b8..654427fbda654 100644
--- a/docs/readme_np.md
+++ b/docs/readme_np.md
@@ -219,7 +219,7 @@ Use [show_owner](#customization) variable to include the repo's owner username
टोप भाषाकार्डले github परयोग गर्नेहरुको प्रोग्रम्मिंग भाषाहरु देखाऊने गर्दछ |.
-_NOTE: टोप भाषाहरुले आफ्नो सिपलाए संकेत गरेको होईन | योचै Github Metricबाट धेरै कुन भाषा परयोग भाकोलाए संकेत गरेको हो |
+_NOTE: टोप भाषाहरुले आफ्नो सिपलाए संकेत गरेको होईन | योचै GitHub Metricबाट धेरै कुन भाषा परयोग भाकोलाए संकेत गरेको हो |
### प्रयोग
कोदलाए कपी- पेसेत readme मा गर्नु होला र लिंक परिवतन गर्नु होला |
@@ -389,7 +389,7 @@ NOTE: Since [#58](https://github.com/anuraghazra/github-readme-stats/pull/58) we
येदि तपाइले यो प्रोजेक्ट चलाउनु बाकोक्ष बने र मलाई अझै प्रसंसा गर्ने हो बने तपाइले थुप्रै तरिका ले गर्नु सक्नु हुने छ :-
- यो प्रोजेक्टमा तपाइले प्रहयोग गर्दा मलाई क्रेडिट दिन सक्नु हुनेक्ष ।
-- तपाइले Github ReadMe Stats स्तार्रेड गर्न सक्नु हुनेक्ष :rocket:
+- तपाइले GitHub ReadMe Stats स्तार्रेड गर्न सक्नु हुनेक्ष :rocket:
- [![paypal.me/anuraghazra](https://ionicabizau.github.io/badges/paypal.svg)](https://www.paypal.me/anuraghazra) - तपाइले पेपाल बाट पनि सहयोग (डक्क्षिन) गर्न सक्नु हुनेक्ष | म ~~कोफी ~~ चिया . :tea: किन्न सक्क्षु ।
धन्याबाद! :heart:
diff --git a/docs/readme_tr.md b/docs/readme_tr.md
index 35f32f2f20f99..7b11cf3706f1e 100644
--- a/docs/readme_tr.md
+++ b/docs/readme_tr.md
@@ -73,10 +73,10 @@
Alt kısımdaki kodu Kopyalayın ve yapıştırın. İşte bu kadar. Çok basit!
-`?username=` değerini kendi Github kullanıcı adınız ile değiştirin.
+`?username=` değerini kendi GitHub kullanıcı adınız ile değiştirin.
```md
-[![Anurag'nın Github İstatistikleri](https://github-readme-stats.vercel.app/api?username=anuraghazra)](https://github.com/anuraghazra/github-readme-stats)
+[![Anurag'nın GitHub İstatistikleri](https://github-readme-stats.vercel.app/api?username=anuraghazra)](https://github.com/anuraghazra/github-readme-stats)
```
_Not: Şu sıralamalar mevcut: S+ (en üst 1%), S (en üst 25%), A++ (en üst 45%), A+ (en üst 60%), and B+ (herkes).
Buradaki değerler [cumulative distribution function](https://en.wikipedia.org/wiki/Cumulative_distribution_function) ile hesaplanırken; commitler, katkılar, hatalar, yıldızlar, çekme istekleri, takipçiler ve sahip olunan depolar (repository) göz önünde bulundurulamaktadır.
@@ -199,7 +199,7 @@ bg_color içerisinde birden fazla rengi gradient olarak göstermek için virgül
# GitHub Ekstra Pinler
-Github ekstra pinler profilinize 6'dan fazla repoyu / depoyu profilinizde pinleyebilirsiniz.
+GitHub ekstra pinler profilinize 6'dan fazla repoyu / depoyu profilinizde pinleyebilirsiniz.
Hey! Artık 6 pin ile kısıtlı kalmayacaksınız!
@@ -225,7 +225,7 @@ Endpoint: `api/pin?username=mustafacagri&repo=github-readme-stats`
En çok kullanılan diller kartı kullanıcının en çok kullandığı dilleri gösterir.
-_NOTE: En çok kullanılan dillerde yer alan bilgiler sizin yeteneğinizi ve benzeri şeyleri göstermek. Bu, kodlarınızda en çok kullandığınız dilleri gösteren bir Github metriğidir. Ayrıca, github-readme-stats'ın yeni özelliğidir.
+_NOTE: En çok kullanılan dillerde yer alan bilgiler sizin yeteneğinizi ve benzeri şeyleri göstermek. Bu, kodlarınızda en çok kullandığınız dilleri gösteren bir GitHub metriğidir. Ayrıca, github-readme-stats'ın yeni özelliğidir.
### Kullanım
@@ -365,7 +365,7 @@ Genellikle resimleri yan yana düzenleyemezsiniz. Bunu yapmak için şu yaklaş
#### [@codeSTACKr'ın Yayınladığı Video Eğitimine Göz Atın](https://youtu.be/n6d4KHSKqGk?t=107)
-Github API saatte sadece 5.000 isteğe izin verdiği için `https://github-readme-stats.vercel.app/api` adresindeki API'm bu limite muhtemelen takılmış olabilir. Eğer projeyi kendi Vercel sunucunuzda yayınlarsanız, böyle bir sorun yaşamayabilirsiniz. Deploy butonuna tıkla ve deploy başlasın!
+GitHub API saatte sadece 5.000 isteğe izin verdiği için `https://github-readme-stats.vercel.app/api` adresindeki API'm bu limite muhtemelen takılmış olabilir. Eğer projeyi kendi Vercel sunucunuzda yayınlarsanız, böyle bir sorun yaşamayabilirsiniz. Deploy butonuna tıkla ve deploy başlasın!
NOT: [#58](https://github.com/anuraghazra/github-readme-stats/pull/58) geliştirmesi sonrasında anlamadığımız bir şekilde 5.000 istek limitine takılmıyoruz :)
@@ -378,9 +378,9 @@ NOT: [#58](https://github.com/anuraghazra/github-readme-stats/pull/58) geliştir
1. [vercel.com](https://vercel.com/) adresine gidin
1. `Log in`'e tıklayın
![](https://files.catbox.moe/tct1wg.png)
-1. `Continue with GitHub`'e basarak Github ile giriş yapın
+1. `Continue with GitHub`'e basarak GitHub ile giriş yapın
![](https://files.catbox.moe/btd78j.jpeg)
-1. Github'a giriş yapın ve eğer çıkarsa tüm repolara izin verin.
+1. GitHub'a giriş yapın ve eğer çıkarsa tüm repolara izin verin.
1. Bu repoyu fork'layın
1. [Vercel dashboard](https://vercel.com/dashboard)'unuza geri dönün.
1. `Import Project`'i seçin.
diff --git a/readme.md b/readme.md
index 9c773ff84707c..926c52c59cf5a 100644
--- a/readme.md
+++ b/readme.md
@@ -150,7 +150,7 @@ Use `&theme=THEME_NAME` parameter like so :
#### All inbuilt themes
-Github readme stats comes with several built-in themes (e.g. `dark`, `radical`, `merko`, `gruvbox`, `tokyonight`, `onedark`, `cobalt`, `synthwave`, `highcontrast`, `dracula`).
+GitHub readme stats comes with several built-in themes (e.g. `dark`, `radical`, `merko`, `gruvbox`, `tokyonight`, `onedark`, `cobalt`, `synthwave`, `highcontrast`, `dracula`).
@@ -193,7 +193,7 @@ You can provide multiple comma-separated values in the bg_color option to render
- `count_private` - Count private commits _(boolean)_. Default: `false`.
- `line_height` - Sets the line height between text _(number)_. Default: `25`.
- `exclude_repo` - Exclude stars from specified repositories _(Comma-separated values)_. Default: `[] (blank array)`.
-- `custom_title` - Sets a custom title for the card. Default: ` Github Stats`.
+- `custom_title` - Sets a custom title for the card. Default: ` GitHub Stats`.
- `text_bold` - Use bold text _(boolean)_. Default: `true`.
- `disable_animations` - Disables all animations in the card _(boolean)_. Default: `false`.
diff --git a/scripts/helpers.js b/scripts/helpers.js
index bc9621e47b72e..6746adc92693c 100644
--- a/scripts/helpers.js
+++ b/scripts/helpers.js
@@ -30,7 +30,7 @@ export const getRepoInfo = (ctx) => {
/**
* Retrieve github token and throw error if it is not found.
*
- * @returns {string} Github token.
+ * @returns {string} GitHub token.
*/
export const getGithubToken = () => {
const token = getInput("github_token") || process.env.GITHUB_TOKEN;
diff --git a/scripts/preview-theme.js b/scripts/preview-theme.js
index 5f705f012177c..38faf873ce3d5 100644
--- a/scripts/preview-theme.js
+++ b/scripts/preview-theme.js
@@ -92,7 +92,7 @@ const isPreviewComment = (inputs, comment) => {
* @param {number} issueNumber Issue number.
* @param {string} repo Repository name.
* @param {string} owner Owner of the repository.
- * @returns {Object} The Github comment object.
+ * @returns {Object} The GitHub comment object.
*/
const findComment = async (octokit, issueNumber, owner, repo, commenter) => {
const parameters = {
diff --git a/scripts/push-theme-readme.sh b/scripts/push-theme-readme.sh
index 946096bd4d592..4a035db3041a0 100755
--- a/scripts/push-theme-readme.sh
+++ b/scripts/push-theme-readme.sh
@@ -5,7 +5,7 @@ set -e
export BRANCH_NAME=updated-theme-readme
git --version
git config --global user.email "no-reply@githubreadmestats.com"
-git config --global user.name "Github Readme Stats Bot"
+git config --global user.name "GitHub Readme Stats Bot"
git branch -d $BRANCH_NAME || true
git checkout -b $BRANCH_NAME
git add --all
diff --git a/src/fetchers/repo-fetcher.js b/src/fetchers/repo-fetcher.js
index 9ff907c82bae6..28dd89a7f3e4a 100644
--- a/src/fetchers/repo-fetcher.js
+++ b/src/fetchers/repo-fetcher.js
@@ -6,7 +6,7 @@ import { MissingParamError, request } from "../common/utils.js";
* Repo data fetcher.
*
* @param {import('Axios').AxiosRequestHeaders} variables Fetcher variables.
- * @param {string} token Github token.
+ * @param {string} token GitHub token.
* @returns {Promise} The response.
*/
const fetcher = (variables, token) => {
@@ -56,8 +56,8 @@ const urlExample = "/api/pin?username=USERNAME&repo=REPO_NAME";
/**
* Fetch repository data.
*
- * @param {string} username Github username.
- * @param {string} reponame Github repository name.
+ * @param {string} username GitHub username.
+ * @param {string} reponame GitHub repository name.
* @returns {Promise} Repository data.
*/
async function fetchRepo(username, reponame) {
diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js
index d592b75857a8a..c236b5882b42f 100644
--- a/src/fetchers/stats-fetcher.js
+++ b/src/fetchers/stats-fetcher.js
@@ -18,7 +18,7 @@ dotenv.config();
* Stats fetcher object.
*
* @param {import('axios').AxiosRequestHeaders} variables Fetcher variables.
- * @param {string} token Github token.
+ * @param {string} token GitHub token.
* @returns {Promise} Stats fetcher response.
*/
const fetcher = (variables, token) => {
@@ -66,7 +66,7 @@ const fetcher = (variables, token) => {
* Fetch first 100 repositories for a given username.
*
* @param {import('axios').AxiosRequestHeaders} variables Fetcher variables.
- * @param {string} token Github token.
+ * @param {string} token GitHub token.
* @returns {Promise} Repositories fetcher response.
*/
const repositoriesFetcher = (variables, token) => {
@@ -101,10 +101,10 @@ const repositoriesFetcher = (variables, token) => {
/**
* Fetch all the commits for all the repositories of a given username.
*
- * @param {*} username Github username.
+ * @param {*} username GitHub username.
* @returns {Promise} Total commits.
*
- * @description Done like this because the Github API does not provide a way to fetch all the commits. See
+ * @description Done like this because the GitHub API does not provide a way to fetch all the commits. See
* #92#issuecomment-661026467 and #211 for more information.
*/
const totalCommitsFetcher = async (username) => {
@@ -143,7 +143,7 @@ const totalCommitsFetcher = async (username) => {
/**
* Fetch all the stars for all the repositories of a given username.
*
- * @param {string} username Github username.
+ * @param {string} username GitHub username.
* @param {array} repoToHide Repositories to hide.
* @returns {Promise} Total stars.
*/
@@ -183,7 +183,7 @@ const totalStarsFetcher = async (username, repoToHide) => {
/**
* Fetch stats for a given username.
*
- * @param {string} username Github username.
+ * @param {string} username GitHub username.
* @param {boolean} count_private Include private contributions.
* @param {boolean} include_all_commits Include all commits.
* @returns {Promise} Stats data.
diff --git a/src/fetchers/top-languages-fetcher.js b/src/fetchers/top-languages-fetcher.js
index ba3fc72ca7e03..109fa06bd2207 100644
--- a/src/fetchers/top-languages-fetcher.js
+++ b/src/fetchers/top-languages-fetcher.js
@@ -15,7 +15,7 @@ dotenv.config();
* Top languages fetcher object.
*
* @param {import('Axios').AxiosRequestHeaders} variables Fetcher variables.
- * @param {string} token Github token.
+ * @param {string} token GitHub token.
* @returns {Promise} Languages fetcher response.
*/
const fetcher = (variables, token) => {
@@ -53,7 +53,7 @@ const fetcher = (variables, token) => {
/**
* Fetch top languages for a given username.
*
- * @param {string} username Github username.
+ * @param {string} username GitHub username.
* @param {string[]} exclude_repo List of repositories to exclude.
* @returns {Promise} Top languages data.
*/
diff --git a/src/translations.js b/src/translations.js
index b71d37f9d7a03..904da37d8f1ba 100644
--- a/src/translations.js
+++ b/src/translations.js
@@ -37,7 +37,7 @@ const statCardLocales = ({ name, apostrophe }) => {
sk: `GitHub štatistiky používateľa ${encodedName}`,
tr: `${encodedName} Hesabının GitHub Yıldızları`,
pl: `Statystyki GitHub użytkownika ${encodedName}`,
- uz: `${encodedName}ning Github'dagi statistikasi`,
+ uz: `${encodedName}ning GitHub'dagi statistikasi`,
vi: `Thống Kê GitHub ${encodedName}`,
se: `GitHubstatistik för ${encodedName}`,
},
From 45f434f0830b9ef06067469d69183103e0079127 Mon Sep 17 00:00:00 2001
From: Falguni Sarkar
Date: Fri, 28 Oct 2022 13:13:17 +0530
Subject: [PATCH 03/17] docs: document auto theme change #2074 (#2229)
* Document auto theme change in README #2074
* Document auto theme change in README
Document auto theme change in README #2074 (update-1)
* Document auto theme change updates
#2074
* docs: improve dynamic theme documentation
Co-authored-by: rickstaa
---
readme.md | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
diff --git a/readme.md b/readme.md
index 926c52c59cf5a..7b81c37e0547e 100644
--- a/readme.md
+++ b/readme.md
@@ -85,6 +85,7 @@ Visit and make a small donation to hel
- [Top Languages Card](#top-languages-card)
- [Wakatime Week Stats](#wakatime-week-stats)
- [Themes](#themes)
+ - [Responsive Card Theme](#responsive-card-theme)
- [Customization](#customization)
- [Common Options](#common-options)
- [Stats Card Exclusive Options](#stats-card-exclusive-options)
@@ -156,6 +157,95 @@ GitHub readme stats comes with several built-in themes (e.g. `dark`, `radical`,
You can look at a preview for [all available themes](./themes/README.md) or checkout the [theme config file](./themes/index.js) & **you can also contribute new themes** if you like :D
+#### Responsive Card Theme
+
+[![Anurag's GitHub stats-Dark](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=dark#gh-dark-mode-only)](https://github.com/anuraghazra/github-readme-stats#gh-dark-mode-only)
+[![Anurag's GitHub stats-Light](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=default#gh-light-mode-only)](https://github.com/anuraghazra/github-readme-stats#gh-light-mode-only)
+
+Since GitHub will re-upload the cards and serve them from their [CDN](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/about-anonymized-urls), we can not infer the browser/GitHub theme on the server side. There are, however, four methods you can use to create dynamics themes on the client side:
+
+##### Use the transparent theme
+
+We have included a `transparent` theme that has a transparent background. This theme is optimized to look good on GitHub's dark and light default themes. You can enable this theme using the `&theme=transparent` parameter like so:
+
+```md
+![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=transparent)
+```
+
+
+:eyes: Show example
+
+![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=transparent)
+
+
+
+##### Add transparent alpha channel to a themes bg_color
+
+You can use the `bg_color` parameter to make any of [the available themes](./themes/README.md) transparent. This is done by setting the `bg_color` to a colour with a transparent alpha channel (i.e. `bg_color=00000000`):
+
+```md
+![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&bg_color=00000000)
+```
+
+
+:eyes: Show example
+
+![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&bg_color=00000000)
+
+
+
+##### Use GitHub's theme context tag
+
+You can use [GitHub's theme context](https://github.blog/changelog/2021-11-24-specify-theme-context-for-images-in-markdown/) tags to switch the theme based on the user GitHub theme automatically. This is done by appending `#gh-dark-mode-only` or `#gh-light-mode-only` to the end of an image URL. This tag will define whether the image specified in the markdown is only shown to viewers using a light or a dark GitHub theme:
+
+```md
+[![Anurag's GitHub stats-Dark](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=dark#gh-dark-mode-only)](https://github.com/anuraghazra/github-readme-stats#gh-dark-mode-only)
+[![Anurag's GitHub stats-Light](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=default#gh-light-mode-only)](https://github.com/anuraghazra/github-readme-stats#gh-light-mode-only)
+```
+
+
+:eyes: Show example
+
+[![Anurag's GitHub stats-Dark](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=dark#gh-dark-mode-only)](https://github.com/anuraghazra/github-readme-stats#gh-dark-mode-only)
+[![Anurag's GitHub stats-Light](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=default#gh-light-mode-only)](https://github.com/anuraghazra/github-readme-stats#gh-light-mode-only)
+
+
+
+##### Use GitHub's new media feature
+
+You can use [GitHub's new media feature](https://github.blog/changelog/2022-05-19-specify-theme-context-for-images-in-markdown-beta/) in HTML to specify whether to display images for light or dark themes. This is done using the HTML `
Gostou do projeto? Por favor considere fazer uma doação para ajudar a melhorá-lo!
@@ -142,7 +144,7 @@ Personalize a aparência do seu `Stats Card` ou `Repo Card` da maneira que desej
- `cache_seconds` - Defina o cabeçalho do cache manualmente _(min: 1800, max: 86400)_
- `locale` - defina o idioma no cartão _(por exemplo. cn, de, es, etc.)_
-> Nota sobre o cache: Cartões de repositório tem um cache padrão de 30 minutos (1800 segundos), se o número a contagem de forks e contagem de estrelas é menor que 1 mil o padrão é 2 horas (7200). Note também que o cache é limitado a um mínimo de 30 minutos e um máximo de 24 horas.
+> Nota sobre o cache: Cartões de repositório tem um cache padrão de 30 minutos (1800 segundos), se o número a contagem de forks e contagem de estrelas é menor que 1 mil o padrão é 2 horas (7200 segundos). Note também que o cache é limitado a um mínimo de 30 minutos e um máximo de 24 horas.
#### Opções exclusivas do cartão de estatísticas:
@@ -167,7 +169,7 @@ Personalize a aparência do seu `Stats Card` ou `Repo Card` da maneira que desej
> :warning: **Importante:**
> Nomes de linguagens devem ser uma sequência escapada de URI, como específicado em [Codificação por cento](https://pt.wikipedia.org/wiki/Codificação_por_cento)
-> (Isso é: `c++` deve se tornar `c%2B%2B`, `jupyter notebook` deve se tornar `jupyter%20notebook`, etc.)
+> (Ou seja: `c++` deve se tornar `c%2B%2B`, `jupyter notebook` deve se tornar `jupyter%20notebook`, etc.)
---
From 9aa39dfe81649eef84e8b750be86993e35c93a2b Mon Sep 17 00:00:00 2001
From: Pranav Joglekar
Date: Sun, 20 Nov 2022 00:48:42 +0530
Subject: [PATCH 11/17] feat: allow users to pass ring_color param (#2075)
* fix: prevent crash if undefined color is passed to func fallbackColor
* feat: allow users to pass ring_color param
Before this commit, the ring color was always equal to the title color.
This commit allows the user to pass a ring_color property to allow him
to style the ring color the way he pleases to. If no ring_color is
passed we default to the title color.
* docs: improves ring color documentation
* fix: improve code style
Co-authored-by: rickstaa
---
api/index.js | 2 ++
readme.md | 1 +
src/cards/stats-card.js | 7 ++--
src/common/utils.js | 12 +++++--
src/getStyles.js | 5 +--
.../renderWakatimeCard.test.js.snap | 4 +--
tests/api.test.js | 35 +++++++++++++++++++
tests/renderStatsCard.test.js | 33 +++++++++++++++++
tests/utils.test.js | 23 ++++++++++++
9 files changed, 114 insertions(+), 8 deletions(-)
diff --git a/api/index.js b/api/index.js
index 34824ba658a1f..88bd3c2e3e7ea 100644
--- a/api/index.js
+++ b/api/index.js
@@ -26,6 +26,7 @@ export default async (req, res) => {
include_all_commits,
line_height,
title_color,
+ ring_color,
icon_color,
text_color,
text_bold,
@@ -76,6 +77,7 @@ export default async (req, res) => {
include_all_commits: parseBoolean(include_all_commits),
line_height,
title_color,
+ ring_color,
icon_color,
text_color,
text_bold: parseBoolean(text_bold),
diff --git a/readme.md b/readme.md
index e18efc80f73b9..bfe042fcc2032 100644
--- a/readme.md
+++ b/readme.md
@@ -286,6 +286,7 @@ You can provide multiple comma-separated values in the bg_color option to render
- `custom_title` - Sets a custom title for the card. Default: ` GitHub Stats`.
- `text_bold` - Use bold text _(boolean)_. Default: `true`.
- `disable_animations` - Disables all animations in the card _(boolean)_. Default: `false`.
+- `ring_color` - Color of the rank circle _(hex color)_. Defaults to the theme ring color if it exists and otherwise the title color.
> **Note**
> When hide_rank=`true`, the minimum card width is 270 px + the title length and padding.
diff --git a/src/cards/stats-card.js b/src/cards/stats-card.js
index 782ff069674bb..b078728ea54c3 100644
--- a/src/cards/stats-card.js
+++ b/src/cards/stats-card.js
@@ -89,6 +89,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
include_all_commits = false,
line_height = 25,
title_color,
+ ring_color,
icon_color,
text_color,
text_bold = true,
@@ -104,13 +105,14 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
const lheight = parseInt(String(line_height), 10);
// returns theme based colors with proper overrides and defaults
- const { titleColor, textColor, iconColor, bgColor, borderColor } =
+ const { titleColor, iconColor, textColor, bgColor, borderColor, ringColor } =
getCardColors({
title_color,
- icon_color,
text_color,
+ icon_color,
bg_color,
border_color,
+ ring_color,
theme,
});
@@ -201,6 +203,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
const progress = 100 - rank.score;
const cssStyles = getStyles({
titleColor,
+ ringColor,
textColor,
iconColor,
show_icons,
diff --git a/src/common/utils.js b/src/common/utils.js
index 43c7587fc2932..a0fbf3dabade7 100644
--- a/src/common/utils.js
+++ b/src/common/utils.js
@@ -133,9 +133,9 @@ function isValidGradient(colors) {
* @returns {string | string[]} The gradient or color.
*/
function fallbackColor(color, fallbackColor) {
- let colors = color.split(",");
let gradient = null;
+ let colors = color ? color.split(",") : [];
if (colors.length > 1 && isValidGradient(colors)) {
gradient = colors;
}
@@ -207,6 +207,7 @@ function getCardColors({
icon_color,
bg_color,
border_color,
+ ring_color,
theme,
fallbackTheme = "default",
}) {
@@ -221,6 +222,13 @@ function getCardColors({
title_color || selectedTheme.title_color,
"#" + defaultTheme.title_color,
);
+
+ // get the color provided by the user else the theme color
+ // finally if both colors are invalid we use the titleColor
+ const ringColor = fallbackColor(
+ ring_color || selectedTheme.ring_color,
+ titleColor,
+ );
const iconColor = fallbackColor(
icon_color || selectedTheme.icon_color,
"#" + defaultTheme.icon_color,
@@ -239,7 +247,7 @@ function getCardColors({
"#" + defaultBorderColor,
);
- return { titleColor, iconColor, textColor, bgColor, borderColor };
+ return { titleColor, iconColor, textColor, bgColor, borderColor, ringColor };
}
/**
diff --git a/src/getStyles.js b/src/getStyles.js
index 79692e8579035..f7b90f4adc7b4 100644
--- a/src/getStyles.js
+++ b/src/getStyles.js
@@ -77,6 +77,7 @@ const getStyles = ({
titleColor,
textColor,
iconColor,
+ ringColor,
show_icons,
progress,
}) => {
@@ -105,13 +106,13 @@ const getStyles = ({
}
.rank-circle-rim {
- stroke: ${titleColor};
+ stroke: ${ringColor};
fill: none;
stroke-width: 6;
opacity: 0.2;
}
.rank-circle {
- stroke: ${titleColor};
+ stroke: ${ringColor};
stroke-dasharray: 250;
fill: none;
stroke-width: 6;
diff --git a/tests/__snapshots__/renderWakatimeCard.test.js.snap b/tests/__snapshots__/renderWakatimeCard.test.js.snap
index 416ead953e459..cc6129272f51e 100644
--- a/tests/__snapshots__/renderWakatimeCard.test.js.snap
+++ b/tests/__snapshots__/renderWakatimeCard.test.js.snap
@@ -51,13 +51,13 @@ exports[`Test Render Wakatime Card should render correctly with compact layout 1
}
.rank-circle-rim {
- stroke: #2f80ed;
+ stroke: undefined;
fill: none;
stroke-width: 6;
opacity: 0.2;
}
.rank-circle {
- stroke: #2f80ed;
+ stroke: undefined;
stroke-dasharray: 250;
fill: none;
stroke-width: 6;
diff --git a/tests/api.test.js b/tests/api.test.js
index f77a7175b43d7..e1830858be063 100644
--- a/tests/api.test.js
+++ b/tests/api.test.js
@@ -248,4 +248,39 @@ describe("Test /api/", () => {
),
);
});
+
+ it("should allow changing ring_color", async () => {
+ const { req, res } = faker(
+ {
+ username: "anuraghazra",
+ hide: "issues,prs,contribs",
+ show_icons: true,
+ hide_border: true,
+ line_height: 100,
+ title_color: "fff",
+ ring_color: "0000ff",
+ icon_color: "fff",
+ text_color: "fff",
+ bg_color: "fff",
+ },
+ data,
+ );
+
+ await api(req, res);
+
+ expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml");
+ expect(res.send).toBeCalledWith(
+ renderStatsCard(stats, {
+ hide: ["issues", "prs", "contribs"],
+ show_icons: true,
+ hide_border: true,
+ line_height: 100,
+ title_color: "fff",
+ ring_color: "0000ff",
+ icon_color: "fff",
+ text_color: "fff",
+ bg_color: "fff",
+ }),
+ );
+ });
});
diff --git a/tests/renderStatsCard.test.js b/tests/renderStatsCard.test.js
index 69708137b334c..288048670f20b 100644
--- a/tests/renderStatsCard.test.js
+++ b/tests/renderStatsCard.test.js
@@ -239,6 +239,39 @@ describe("Test renderStatsCard", () => {
);
});
+ it("should render custom ring_color properly", () => {
+ const customColors = {
+ title_color: "5a0",
+ ring_color: "0000ff",
+ icon_color: "1b998b",
+ text_color: "9991",
+ bg_color: "252525",
+ };
+
+ document.body.innerHTML = renderStatsCard(stats, { ...customColors });
+
+ const styleTag = document.querySelector("style");
+ const stylesObject = cssToObject(styleTag.innerHTML);
+
+ const headerClassStyles = stylesObject[":host"][".header "];
+ const statClassStyles = stylesObject[":host"][".stat "];
+ const iconClassStyles = stylesObject[":host"][".icon "];
+ const rankCircleStyles = stylesObject[":host"][".rank-circle "];
+ const rankCircleRimStyles = stylesObject[":host"][".rank-circle-rim "];
+
+ expect(headerClassStyles.fill.trim()).toBe(`#${customColors.title_color}`);
+ expect(statClassStyles.fill.trim()).toBe(`#${customColors.text_color}`);
+ expect(iconClassStyles.fill.trim()).toBe(`#${customColors.icon_color}`);
+ expect(rankCircleStyles.stroke.trim()).toBe(`#${customColors.ring_color}`);
+ expect(rankCircleRimStyles.stroke.trim()).toBe(
+ `#${customColors.ring_color}`,
+ );
+ expect(queryByTestId(document.body, "card-bg")).toHaveAttribute(
+ "fill",
+ "#252525",
+ );
+ });
+
it("should render icons correctly", () => {
document.body.innerHTML = renderStatsCard(stats, {
show_icons: true,
diff --git a/tests/utils.test.js b/tests/utils.test.js
index b6e4a3be3f9f9..5f6231cceff2d 100644
--- a/tests/utils.test.js
+++ b/tests/utils.test.js
@@ -48,6 +48,7 @@ describe("Test utils.js", () => {
let colors = getCardColors({
title_color: "f00",
text_color: "0f0",
+ ring_color: "0000ff",
icon_color: "00f",
bg_color: "fff",
border_color: "fff",
@@ -57,6 +58,7 @@ describe("Test utils.js", () => {
titleColor: "#f00",
textColor: "#0f0",
iconColor: "#00f",
+ ringColor: "#0000ff",
bgColor: "#fff",
borderColor: "#fff",
});
@@ -75,6 +77,7 @@ describe("Test utils.js", () => {
titleColor: "#2f80ed",
textColor: "#0f0",
iconColor: "#00f",
+ ringColor: "#2f80ed",
bgColor: "#fff",
borderColor: "#e4e2e2",
});
@@ -87,11 +90,31 @@ describe("Test utils.js", () => {
expect(colors).toStrictEqual({
titleColor: "#fff",
textColor: "#9f9f9f",
+ ringColor: "#fff",
iconColor: "#79ff97",
bgColor: "#151515",
borderColor: "#e4e2e2",
});
});
+
+ it("getCardColors: should return ring color equal to title color if not ring color is defined", () => {
+ let colors = getCardColors({
+ title_color: "f00",
+ text_color: "0f0",
+ icon_color: "00f",
+ bg_color: "fff",
+ border_color: "fff",
+ theme: "dark",
+ });
+ expect(colors).toStrictEqual({
+ titleColor: "#f00",
+ textColor: "#0f0",
+ iconColor: "#00f",
+ ringColor: "#f00",
+ bgColor: "#fff",
+ borderColor: "#fff",
+ });
+ });
});
describe("wrapTextMultiline", () => {
From 0e02523459a527007f196cd1a35297d850d08839 Mon Sep 17 00:00:00 2001
From: Bradley Jester <109996512+jesterb0206@users.noreply.github.com>
Date: Sat, 19 Nov 2022 13:44:42 -0800
Subject: [PATCH 12/17] feat: added Date Night theme to index.js (#2264)
* Added Date Night theme to index.js
* My theme name should be in snake_case now
---
themes/index.js | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/themes/index.js b/themes/index.js
index 4279317b3edc3..a5d3abae8cb6f 100644
--- a/themes/index.js
+++ b/themes/index.js
@@ -367,6 +367,13 @@ export const themes = {
text_color: "e0def4",
bg_color: "191724",
},
+ date_night: {
+ title_color: "DA7885",
+ text_color: "E1B2A2",
+ icon_color: "BB8470",
+ border_color: "170F0C",
+ bg_color: "170F0C",
+ },
};
export default themes;
From b2e34ac8db9dd28f009ac1f7f657da8b7f21800c Mon Sep 17 00:00:00 2001
From: rickstaa
Date: Sun, 20 Nov 2022 08:39:44 +0100
Subject: [PATCH 13/17] test: update snapshots
---
tests/__snapshots__/renderWakatimeCard.test.js.snap | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/__snapshots__/renderWakatimeCard.test.js.snap b/tests/__snapshots__/renderWakatimeCard.test.js.snap
index cc6129272f51e..1c0bd701fbbfe 100644
--- a/tests/__snapshots__/renderWakatimeCard.test.js.snap
+++ b/tests/__snapshots__/renderWakatimeCard.test.js.snap
@@ -209,13 +209,13 @@ exports[`Test Render Wakatime Card should render correctly with compact layout w
}
.rank-circle-rim {
- stroke: #2f80ed;
+ stroke: undefined;
fill: none;
stroke-width: 6;
opacity: 0.2;
}
.rank-circle {
- stroke: #2f80ed;
+ stroke: undefined;
stroke-dasharray: 250;
fill: none;
stroke-width: 6;
From 4b656ebabb8cb866d08bd010df29845372027018 Mon Sep 17 00:00:00 2001
From: Rick Staa
Date: Mon, 21 Nov 2022 10:07:09 +0100
Subject: [PATCH 14/17] refactor: migrate to using arrow functions (#2033)
---
src/calculateRank.js | 10 ++---
src/common/utils.js | 62 +++++++++++++--------------
src/fetchers/repo-fetcher.js | 4 +-
src/fetchers/stats-fetcher.js | 6 +--
src/fetchers/top-languages-fetcher.js | 4 +-
src/translations.js | 4 +-
6 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/src/calculateRank.js b/src/calculateRank.js
index 23d61dba35ddb..24845bc7d9944 100644
--- a/src/calculateRank.js
+++ b/src/calculateRank.js
@@ -9,7 +9,7 @@
* @param {number} to The value to calculate the probability for.
* @returns {number} Probability.
*/
-function normalcdf(mean, sigma, to) {
+const normalcdf = (mean, sigma, to) => {
var z = (to - mean) / Math.sqrt(2 * sigma * sigma);
var t = 1 / (1 + 0.3275911 * Math.abs(z));
var a1 = 0.254829592;
@@ -24,7 +24,7 @@ function normalcdf(mean, sigma, to) {
sign = -1;
}
return (1 / 2) * (1 + sign * erf);
-}
+};
/**
* Calculates the users rank.
@@ -38,7 +38,7 @@ function normalcdf(mean, sigma, to) {
* @param {number} stargazers The number of stars.
* @returns {{level: string, score: number}}} The users rank.
*/
-function calculateRank({
+const calculateRank = ({
totalRepos,
totalCommits,
contributions,
@@ -46,7 +46,7 @@ function calculateRank({
prs,
issues,
stargazers,
-}) {
+}) => {
const COMMITS_OFFSET = 1.65;
const CONTRIBS_OFFSET = 1.65;
const ISSUES_OFFSET = 1;
@@ -98,7 +98,7 @@ function calculateRank({
})();
return { level, score: normalizedScore };
-}
+};
export { calculateRank };
export default calculateRank;
diff --git a/src/common/utils.js b/src/common/utils.js
index a0fbf3dabade7..688219c8d8e18 100644
--- a/src/common/utils.js
+++ b/src/common/utils.js
@@ -42,13 +42,13 @@ const renderError = (message, secondaryMessage = "") => {
* @param {string} str String to encode.
* @returns {string} Encoded string.
*/
-function encodeHTML(str) {
+const encodeHTML = (str) => {
return str
.replace(/[\u00A0-\u9999<>&](?!#)/gim, (i) => {
return "" + i.charCodeAt(0) + ";";
})
.replace(/\u0008/gim, "");
-}
+};
/**
* Retrieves num with suffix k(thousands) precise to 1 decimal if greater than 999.
@@ -56,11 +56,11 @@ function encodeHTML(str) {
* @param {number} num The number to format.
* @returns {string|number} The formatted number.
*/
-function kFormatter(num) {
+const kFormatter = (num) => {
return Math.abs(num) > 999
? Math.sign(num) * parseFloat((Math.abs(num) / 1000).toFixed(1)) + "k"
: Math.sign(num) * Math.abs(num);
-}
+};
/**
* Checks if a string is a valid hex color.
@@ -68,11 +68,11 @@ function kFormatter(num) {
* @param {string} hexColor String to check.
* @returns {boolean} True if the given string is a valid hex color.
*/
-function isValidHexColor(hexColor) {
+const isValidHexColor = (hexColor) => {
return new RegExp(
/^([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{4})$/,
).test(hexColor);
-}
+};
/**
* Returns boolean if value is either "true" or "false" else the value as it is.
@@ -80,7 +80,7 @@ function isValidHexColor(hexColor) {
* @param {string} value The value to parse.
* @returns {boolean | string} The parsed value.
*/
-function parseBoolean(value) {
+const parseBoolean = (value) => {
if (value === "true") {
return true;
} else if (value === "false") {
@@ -88,7 +88,7 @@ function parseBoolean(value) {
} else {
return value;
}
-}
+};
/**
* Parse string to array of strings.
@@ -96,10 +96,10 @@ function parseBoolean(value) {
* @param {string} str The string to parse.
* @returns {string[]} The array of strings.
*/
-function parseArray(str) {
+const parseArray = (str) => {
if (!str) return [];
return str.split(",");
-}
+};
/**
* Clamp the given number between the given range.
@@ -109,11 +109,11 @@ function parseArray(str) {
* @param {number} max The maximum value.
* returns {number} The clamped number.
*/
-function clampValue(number, min, max) {
+const clampValue = (number, min, max) => {
// @ts-ignore
if (Number.isNaN(parseInt(number))) return min;
return Math.max(min, Math.min(number, max));
-}
+};
/**
* Check if the given string is a valid gradient.
@@ -121,9 +121,9 @@ function clampValue(number, min, max) {
* @param {string[]} colors Array of colors.
* @returns {boolean} True if the given string is a valid gradient.
*/
-function isValidGradient(colors) {
+const isValidGradient = (colors) => {
return isValidHexColor(colors[1]) && isValidHexColor(colors[2]);
-}
+};
/**
* Retrieves a gradient if color has more than one valid hex codes else a single color.
@@ -132,7 +132,7 @@ function isValidGradient(colors) {
* @param {string} fallbackColor The fallback color.
* @returns {string | string[]} The gradient or color.
*/
-function fallbackColor(color, fallbackColor) {
+const fallbackColor = (color, fallbackColor) => {
let gradient = null;
let colors = color ? color.split(",") : [];
@@ -144,7 +144,7 @@ function fallbackColor(color, fallbackColor) {
(gradient ? gradient : isValidHexColor(color) && `#${color}`) ||
fallbackColor
);
-}
+};
/**
* Send GraphQL request to GitHub API.
@@ -153,7 +153,7 @@ function fallbackColor(color, fallbackColor) {
* @param {import('axios').AxiosRequestConfig['headers']} headers Request headers.
* @returns {Promise} Request response.
*/
-function request(data, headers) {
+const request = (data, headers) => {
// @ts-ignore
return axios({
url: "https://api.github.com/graphql",
@@ -161,7 +161,7 @@ function request(data, headers) {
headers,
data,
});
-}
+};
/**
* Auto layout utility, allows us to layout things vertically or horizontally with
@@ -174,7 +174,7 @@ function request(data, headers) {
* @param {"column" | "row"?=} props.direction Direction to layout items.
* @returns {string[]} Array of items with proper layout.
*/
-function flexLayout({ items, gap, direction, sizes = [] }) {
+const flexLayout = ({ items, gap, direction, sizes = [] }) => {
let lastSize = 0;
// filter() for filtering out empty strings
return items.filter(Boolean).map((item, i) => {
@@ -186,7 +186,7 @@ function flexLayout({ items, gap, direction, sizes = [] }) {
lastSize += size + gap;
return `${item}`;
});
-}
+};
/**
* Returns theme based colors with proper overrides and defaults.
@@ -201,7 +201,7 @@ function flexLayout({ items, gap, direction, sizes = [] }) {
* @param {string} args.fallbackTheme Fallback theme.
*
*/
-function getCardColors({
+const getCardColors = ({
title_color,
text_color,
icon_color,
@@ -210,7 +210,7 @@ function getCardColors({
ring_color,
theme,
fallbackTheme = "default",
-}) {
+}) => {
const defaultTheme = themes[fallbackTheme];
const selectedTheme = themes[theme] || defaultTheme;
const defaultBorderColor =
@@ -248,7 +248,7 @@ function getCardColors({
);
return { titleColor, iconColor, textColor, bgColor, borderColor, ringColor };
-}
+};
/**
* Split text over multiple lines based on the card width.
@@ -258,7 +258,7 @@ function getCardColors({
* @param {number} maxLines Maximum number of lines.
* @returns {string[]} Array of lines.
*/
-function wrapTextMultiline(text, width = 59, maxLines = 3) {
+const wrapTextMultiline = (text, width = 59, maxLines = 3) => {
const fullWidthComma = ",";
const encoded = encodeHTML(text);
const isChinese = encoded.includes(fullWidthComma);
@@ -283,7 +283,7 @@ function wrapTextMultiline(text, width = 59, maxLines = 3) {
// Remove empty lines if text fits in less than maxLines lines
const multiLineText = lines.filter(Boolean);
return multiLineText;
-}
+};
const noop = () => {};
// return console instance based on the environment
@@ -349,7 +349,7 @@ class MissingParamError extends Error {
* @param {number} fontSize Font size.
* @returns {number} Text length.
*/
-function measureText(str, fontSize = 10) {
+const measureText = (str, fontSize = 10) => {
// prettier-ignore
const widths = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -381,7 +381,7 @@ function measureText(str, fontSize = 10) {
)
.reduce((cur, acc) => acc + cur) * fontSize
);
-}
+};
/** @param {string} name */
const lowercaseTrim = (name) => name.toLowerCase().trim();
@@ -394,7 +394,7 @@ const lowercaseTrim = (name) => name.toLowerCase().trim();
* @param {number} perChunk Number of languages per column.
* @returns {Array} Array of languages split in two columns.
*/
-function chunkArray(arr, perChunk) {
+const chunkArray = (arr, perChunk) => {
return arr.reduce((resultArray, item, index) => {
const chunkIndex = Math.floor(index / perChunk);
@@ -406,7 +406,7 @@ function chunkArray(arr, perChunk) {
return resultArray;
}, []);
-}
+};
/**
* Parse emoji from string.
@@ -414,12 +414,12 @@ function chunkArray(arr, perChunk) {
* @param {string} str String to parse emoji from.
* @returns {string} String with emoji parsed.
*/
-function parseEmojis(str) {
+const parseEmojis = (str) => {
if (!str) throw new Error("[parseEmoji]: str argument not provided");
return str.replace(/:\w+:/gm, (emoji) => {
return toEmoji.get(emoji) || "";
});
-}
+};
export {
ERROR_CARD_LENGTH,
diff --git a/src/fetchers/repo-fetcher.js b/src/fetchers/repo-fetcher.js
index 28dd89a7f3e4a..ff7a2be8164cc 100644
--- a/src/fetchers/repo-fetcher.js
+++ b/src/fetchers/repo-fetcher.js
@@ -60,7 +60,7 @@ const urlExample = "/api/pin?username=USERNAME&repo=REPO_NAME";
* @param {string} reponame GitHub repository name.
* @returns {Promise} Repository data.
*/
-async function fetchRepo(username, reponame) {
+const fetchRepo = async (username, reponame) => {
if (!username && !reponame) {
throw new MissingParamError(["username", "repo"], urlExample);
}
@@ -100,7 +100,7 @@ async function fetchRepo(username, reponame) {
starCount: data.organization.repository.stargazers.totalCount,
};
}
-}
+};
export { fetchRepo };
export default fetchRepo;
diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js
index c236b5882b42f..9d17d009c0b70 100644
--- a/src/fetchers/stats-fetcher.js
+++ b/src/fetchers/stats-fetcher.js
@@ -188,12 +188,12 @@ const totalStarsFetcher = async (username, repoToHide) => {
* @param {boolean} include_all_commits Include all commits.
* @returns {Promise} Stats data.
*/
-async function fetchStats(
+const fetchStats = async (
username,
count_private = false,
include_all_commits = false,
exclude_repo = [],
-) {
+) => {
if (!username) throw new MissingParamError(["username"]);
const stats = {
@@ -275,7 +275,7 @@ async function fetchStats(
});
return stats;
-}
+};
export { fetchStats };
export default fetchStats;
diff --git a/src/fetchers/top-languages-fetcher.js b/src/fetchers/top-languages-fetcher.js
index 109fa06bd2207..5fa1c8040b170 100644
--- a/src/fetchers/top-languages-fetcher.js
+++ b/src/fetchers/top-languages-fetcher.js
@@ -57,7 +57,7 @@ const fetcher = (variables, token) => {
* @param {string[]} exclude_repo List of repositories to exclude.
* @returns {Promise} Top languages data.
*/
-async function fetchTopLanguages(username, exclude_repo = []) {
+const fetchTopLanguages = async (username, exclude_repo = []) => {
if (!username) throw new MissingParamError(["username"]);
const res = await retryer(fetcher, { login: username });
@@ -136,7 +136,7 @@ async function fetchTopLanguages(username, exclude_repo = []) {
}, {});
return topLangs;
-}
+};
export { fetchTopLanguages };
export default fetchTopLanguages;
diff --git a/src/translations.js b/src/translations.js
index 65fc231f59b4e..45c8295e024de 100644
--- a/src/translations.js
+++ b/src/translations.js
@@ -367,9 +367,9 @@ const availableLocales = Object.keys(repoCardLocales["repocard.archived"]);
* @param {string} locale The locale to check.
* @returns {boolean} Boolean specifying whether the locale is available or not.
*/
-function isLocaleAvailable(locale) {
+const isLocaleAvailable = (locale) => {
return availableLocales.includes(locale.toLowerCase());
-}
+};
export {
isLocaleAvailable,
From 5df25a64721847ae6086fd1fcae0b4724805f5a8 Mon Sep 17 00:00:00 2001
From: Rick Staa
Date: Mon, 21 Nov 2022 10:10:46 +0100
Subject: [PATCH 15/17] fix: improve boolean parse behaviour (#2029)
---
src/common/utils.js | 19 +++++++++++--------
tests/utils.test.js | 18 ++++++++++++++++++
2 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/src/common/utils.js b/src/common/utils.js
index 688219c8d8e18..1215fc9ac8cc2 100644
--- a/src/common/utils.js
+++ b/src/common/utils.js
@@ -77,17 +77,20 @@ const isValidHexColor = (hexColor) => {
/**
* Returns boolean if value is either "true" or "false" else the value as it is.
*
- * @param {string} value The value to parse.
- * @returns {boolean | string} The parsed value.
+ * @param {string | boolean} value The value to parse.
+ * @returns {boolean | undefined } The parsed value.
*/
const parseBoolean = (value) => {
- if (value === "true") {
- return true;
- } else if (value === "false") {
- return false;
- } else {
- return value;
+ if (typeof value === "boolean") return value;
+
+ if (typeof value === "string") {
+ if (value.toLowerCase() === "true") {
+ return true;
+ } else if (value.toLowerCase() === "false") {
+ return false;
+ }
}
+ return undefined;
};
/**
diff --git a/tests/utils.test.js b/tests/utils.test.js
index 5f6231cceff2d..c91fe9d54ae5d 100644
--- a/tests/utils.test.js
+++ b/tests/utils.test.js
@@ -4,6 +4,7 @@ import {
encodeHTML,
getCardColors,
kFormatter,
+ parseBoolean,
renderError,
wrapTextMultiline,
} from "../src/common/utils.js";
@@ -19,6 +20,23 @@ describe("Test utils.js", () => {
expect(kFormatter(9900000)).toBe("9900k");
});
+ it("should test parseBoolean", () => {
+ expect(parseBoolean(true)).toBe(true);
+ expect(parseBoolean(false)).toBe(false);
+
+ expect(parseBoolean("true")).toBe(true);
+ expect(parseBoolean("false")).toBe(false);
+ expect(parseBoolean("True")).toBe(true);
+ expect(parseBoolean("False")).toBe(false);
+ expect(parseBoolean("TRUE")).toBe(true);
+ expect(parseBoolean("FALSE")).toBe(false);
+
+ expect(parseBoolean("1")).toBe(undefined);
+ expect(parseBoolean("0")).toBe(undefined);
+ expect(parseBoolean("")).toBe(undefined);
+ expect(parseBoolean(undefined)).toBe(undefined);
+ });
+
it("should test encodeHTML", () => {
expect(encodeHTML(`hello world<,.#4^&^@%!))`)).toBe(
"<html>hello world<,.#4^&^@%!))",
From 42a4b6f60a5d534c9de5434ebaa09f222ac40247 Mon Sep 17 00:00:00 2001
From: Rick Staa
Date: Mon, 21 Nov 2022 10:13:14 +0100
Subject: [PATCH 16/17] refactor: remove unused dotenv calls (#2059)
As explained in the Vercel documentation vercel ignores dot files (see
https://github.com/vercel/vercel/discussions/3962#discussioncomment-4277). It
instead loads the env variables defined in the vercel instance. As a
result we can therefore remove dotenv.
---
api/index.js | 3 ---
api/top-langs.js | 3 ---
api/wakatime.js | 3 ---
src/fetchers/stats-fetcher.js | 3 ---
src/fetchers/top-languages-fetcher.js | 3 ---
5 files changed, 15 deletions(-)
diff --git a/api/index.js b/api/index.js
index 88bd3c2e3e7ea..8fbe2bc28e998 100644
--- a/api/index.js
+++ b/api/index.js
@@ -1,4 +1,3 @@
-import * as dotenv from "dotenv";
import { renderStatsCard } from "../src/cards/stats-card.js";
import { blacklist } from "../src/common/blacklist.js";
import {
@@ -11,8 +10,6 @@ import {
import { fetchStats } from "../src/fetchers/stats-fetcher.js";
import { isLocaleAvailable } from "../src/translations.js";
-dotenv.config();
-
export default async (req, res) => {
const {
username,
diff --git a/api/top-langs.js b/api/top-langs.js
index 25f97c8b455b2..1b6b980d77c4b 100644
--- a/api/top-langs.js
+++ b/api/top-langs.js
@@ -1,4 +1,3 @@
-import * as dotenv from "dotenv";
import { renderTopLanguages } from "../src/cards/top-languages-card.js";
import { blacklist } from "../src/common/blacklist.js";
import {
@@ -11,8 +10,6 @@ import {
import { fetchTopLanguages } from "../src/fetchers/top-languages-fetcher.js";
import { isLocaleAvailable } from "../src/translations.js";
-dotenv.config();
-
export default async (req, res) => {
const {
username,
diff --git a/api/wakatime.js b/api/wakatime.js
index fb8caa51c9477..7680b76e602f2 100644
--- a/api/wakatime.js
+++ b/api/wakatime.js
@@ -1,4 +1,3 @@
-import * as dotenv from "dotenv";
import { renderWakatimeCard } from "../src/cards/wakatime-card.js";
import {
clampValue,
@@ -10,8 +9,6 @@ import {
import { fetchWakatimeStats } from "../src/fetchers/wakatime-fetcher.js";
import { isLocaleAvailable } from "../src/translations.js";
-dotenv.config();
-
export default async (req, res) => {
const {
username,
diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js
index 9d17d009c0b70..7f6cb9e5e95b4 100644
--- a/src/fetchers/stats-fetcher.js
+++ b/src/fetchers/stats-fetcher.js
@@ -1,6 +1,5 @@
// @ts-check
import axios from "axios";
-import * as dotenv from "dotenv";
import githubUsernameRegex from "github-username-regex";
import { calculateRank } from "../calculateRank.js";
import { retryer } from "../common/retryer.js";
@@ -12,8 +11,6 @@ import {
wrapTextMultiline,
} from "../common/utils.js";
-dotenv.config();
-
/**
* Stats fetcher object.
*
diff --git a/src/fetchers/top-languages-fetcher.js b/src/fetchers/top-languages-fetcher.js
index 5fa1c8040b170..86d794435be08 100644
--- a/src/fetchers/top-languages-fetcher.js
+++ b/src/fetchers/top-languages-fetcher.js
@@ -1,5 +1,4 @@
// @ts-check
-import * as dotenv from "dotenv";
import { retryer } from "../common/retryer.js";
import {
CustomError,
@@ -9,8 +8,6 @@ import {
wrapTextMultiline,
} from "../common/utils.js";
-dotenv.config();
-
/**
* Top languages fetcher object.
*
From f07cd133d3166688c5883f64c6491665f38bba78 Mon Sep 17 00:00:00 2001
From: Rick Staa
Date: Mon, 21 Nov 2022 10:15:43 +0100
Subject: [PATCH 17/17] fix: fix retry max-out bug (#2121)
* fix: fix retry max-out bug
This commit makes sure that the retry function tests all PATs.
* style: format code
* test: fix retry tests
* style: format code
---
src/common/retryer.js | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/common/retryer.js b/src/common/retryer.js
index 77f69d3cbbbce..e54eedbec6dd5 100644
--- a/src/common/retryer.js
+++ b/src/common/retryer.js
@@ -1,5 +1,11 @@
import { CustomError, logger } from "./utils.js";
+// Script variables.
+const PATs = Object.keys(process.env).filter((key) =>
+ /PAT_\d*$/.exec(key),
+).length;
+const RETRIES = PATs ? PATs : 7;
+
/**
* Try to execute the fetcher function until it succeeds or the max number of retries is reached.
*
@@ -10,7 +16,7 @@ import { CustomError, logger } from "./utils.js";
* @returns Promise
*/
const retryer = async (fetcher, variables, retries = 0) => {
- if (retries > 7) {
+ if (retries > RETRIES) {
throw new CustomError("Maximum retries exceeded", CustomError.MAX_RETRY);
}
try {