forked from mirrored/github-readme-stats
Compare commits
34
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
533fe040a6 | ||
|
|
54cc291978 | ||
|
|
65424fa90f | ||
|
|
f7a2b2162b | ||
|
|
dea583d426 | ||
|
|
6fdf73f39c | ||
|
|
8dd70924da | ||
|
|
32b8daa71d | ||
|
|
7eb85d3b31 | ||
|
|
166972d7e4 | ||
|
|
c4bfacb9e0 | ||
|
|
f0f92c2635 | ||
|
|
4df8094e52 | ||
|
|
0a394a625b | ||
|
|
f77e34e383 | ||
|
|
fcd0588786 | ||
|
|
60012707c7 | ||
|
|
bd9865d5a2 | ||
|
|
39535db38c | ||
|
|
80e8233c53 | ||
|
|
06e3e052df | ||
|
|
36a8c392d0 | ||
|
|
343058cc15 | ||
|
|
d7451d8288 | ||
|
|
5c514dbda0 | ||
|
|
15533596e6 | ||
|
|
df243efdd5 | ||
|
|
15620a11db | ||
|
|
e8dfbde7bb | ||
|
|
bcb8ae9281 | ||
|
|
04595dfe62 | ||
|
|
cea4a39548 | ||
|
|
aae83cb22e | ||
|
|
94d0978d2b |
@@ -1,43 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ""
|
||||
labels: ""
|
||||
assignees: ""
|
||||
---
|
||||
<!--PLEASE FIRST READ THE FAQ (#1770) AND COMMON ERROR CODES (#1772)!!!-->
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**Expected behaviour**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots / Live demo link (paste the github-readme-stats link as markdown image)**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
|
||||
<!-- FAQ
|
||||
Below are some questions that are found in the FAQ. The full FAQ can be found in #1770.
|
||||
|
||||
Q: My card displays an error
|
||||
Ans: First, check the common error codes (i.e. https://github.com/anuraghazra/github-readme-stats/issues/1772) and existing issues before creating a new one.
|
||||
|
||||
Q: How to hide jupyter Notebook?
|
||||
Ans: &hide=jupyter%20notebook
|
||||
|
||||
Q: I could not figure out how to deploy on my own vercel instance
|
||||
Ans:
|
||||
- docs: https://github.com/anuraghazra/github-readme-stats/#deploy-on-your-own-vercel-instance
|
||||
- YT tutorial by codeSTACKr: https://www.youtube.com/watch?v=n6d4KHSKqGk&feature=youtu.be&t=107
|
||||
|
||||
Q: Language Card is incorrect
|
||||
Ans: Please read all the issues/comments before opening any issues regarding language card stats:
|
||||
- https://github.com/anuraghazra/github-readme-stats/issues/136#issuecomment-665164174
|
||||
- https://github.com/anuraghazra/github-readme-stats/issues/136#issuecomment-665172181
|
||||
|
||||
Q: How to count private stats?
|
||||
Ans: We can only count private commits & we cannot access any other private info of any users, so it's impossible. The only way is to deploy on your own instance & use your own PAT (Personal Access Token)
|
||||
-->
|
||||
@@ -0,0 +1,58 @@
|
||||
name: Bug report
|
||||
description: Create a report to help us improve.
|
||||
labels:
|
||||
- "bug"
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
:warning: PLEASE FIRST READ THE FAQ [(#1770)](https://github.com/anuraghazra/github-readme-stats/discussions/1770) AND COMMON ERROR CODES [(#1772)](https://github.com/anuraghazra/github-readme-stats/issues/1772)!!!
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Describe the bug
|
||||
description: A clear and concise description of what the bug is.
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Expected behaviour
|
||||
description:
|
||||
A clear and concise description of what you expected to happen.
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Screenshots / Live demo link
|
||||
description: If applicable, add screenshots to help explain your problem.
|
||||
placeholder: Paste the github-readme-stats link as markdown image
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: Add any other context about the problem here.
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
---
|
||||
### FAQ (Snippet)
|
||||
|
||||
Below are some questions that are found in the FAQ. The full FAQ can be found in [#1770](https://github.com/anuraghazra/github-readme-stats/discussions/1770).
|
||||
|
||||
#### Q: My card displays an error
|
||||
|
||||
**Ans:** First, check the common error codes (i.e. https://github.com/anuraghazra/github-readme-stats/issues/1772) and existing issues before creating a new one.
|
||||
|
||||
#### Q: How to hide jupyter Notebook?
|
||||
|
||||
**Ans:** `&hide=jupyter%20notebook`.
|
||||
|
||||
#### Q: I could not figure out how to deploy on my own vercel instance
|
||||
|
||||
**Ans:** Please check:
|
||||
- Docs: https://github.com/anuraghazra/github-readme-stats/#deploy-on-your-own-vercel-instance
|
||||
- YT tutorial by codeSTACKr: https://www.youtube.com/watch?v=n6d4KHSKqGk&feature=youtu.be&t=107
|
||||
|
||||
#### Q: Language Card is incorrect
|
||||
|
||||
**Ans:** Please read these issues/comments before opening any issues regarding language card stats:
|
||||
- https://github.com/anuraghazra/github-readme-stats/issues/136#issuecomment-665164174
|
||||
- https://github.com/anuraghazra/github-readme-stats/issues/136#issuecomment-665172181
|
||||
|
||||
#### Q: How to count private stats?
|
||||
|
||||
**Ans:** We can only count private commits & we cannot access any other private info of any users, so it's impossible. The only way is to deploy on your own instance & use your own PAT (Personal Access Token).
|
||||
@@ -0,0 +1,12 @@
|
||||
blank_issues_enabled: true
|
||||
contact_links:
|
||||
- name: Question
|
||||
url: https://github.com/anuraghazra/github-readme-stats/discussions
|
||||
about: Please ask and answer questions here.
|
||||
- name: Error
|
||||
url: https://github.com/anuraghazra/github-readme-stats/issues/1772
|
||||
about:
|
||||
Before opening a bug report, please check the 'Common Error Codes' issue.
|
||||
- name: FAQ
|
||||
url: https://github.com/anuraghazra/github-readme-stats/discussions/1770
|
||||
about: Please first check the FAQ before asking a question.
|
||||
@@ -1,41 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ""
|
||||
labels: ""
|
||||
assignees: ""
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
|
||||
<!--
|
||||
|
||||
PLEASE READ THE FAQs!!!
|
||||
|
||||
Q: How to hide jupyter Notebook?
|
||||
Ans: &hide=jupyter%20notebook
|
||||
|
||||
Q: I could not figure out how to deploy on my own vercel instance
|
||||
Ans:
|
||||
- docs: https://github.com/anuraghazra/github-readme-stats/#deploy-on-your-own-vercel-instance
|
||||
- YT tutorial by codeSTACKr: https://www.youtube.com/watch?v=n6d4KHSKqGk&feature=youtu.be&t=107
|
||||
|
||||
Q: Language Card is incorrect
|
||||
Ans: Please read all the issues / comments before opening any issues regarding language card stats:
|
||||
- https://github.com/anuraghazra/github-readme-stats/issues/136#issuecomment-665164174
|
||||
- https://github.com/anuraghazra/github-readme-stats/issues/136#issuecomment-665172181
|
||||
|
||||
Q: How to count private stats?
|
||||
Ans: We can only count private commits & we cannot access any other private info of any users, so it's not possible. only way is to deploy on your own instance & use your own PAT (Personal Access Token)
|
||||
|
||||
-->
|
||||
@@ -0,0 +1,26 @@
|
||||
name: Feature request
|
||||
description: Suggest an idea for this project.
|
||||
labels:
|
||||
- "enhancement"
|
||||
body:
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Is your feature request related to a problem? Please describe.
|
||||
description:
|
||||
A clear and concise description of what the problem is. Ex. I'm always
|
||||
frustrated when [...]
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Describe the solution you'd like
|
||||
description: A clear and concise description of what you want to happen.
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Describe alternatives you've considered
|
||||
description:
|
||||
A clear and concise description of any alternative solutions or features
|
||||
you've considered.
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Additional context
|
||||
description:
|
||||
Add any other context or screenshots about the feature request here.
|
||||
@@ -0,0 +1 @@
|
||||
_
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
npm test
|
||||
npx lint-staged
|
||||
@@ -89,6 +89,7 @@ export default async (req, res) => {
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
res.setHeader("Cache-Control", `no-store`); // Don't cache error responses.
|
||||
return res.send(renderError(err.message, err.secondaryMessage));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -75,6 +75,7 @@ export default async (req, res) => {
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
res.setHeader("Cache-Control", `no-store`); // Don't cache error responses.
|
||||
return res.send(renderError(err.message, err.secondaryMessage));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -76,6 +76,7 @@ export default async (req, res) => {
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
res.setHeader("Cache-Control", `no-store`); // Don't cache error responses.
|
||||
return res.send(renderError(err.message, err.secondaryMessage));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -78,6 +78,7 @@ export default async (req, res) => {
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
res.setHeader("Cache-Control", `no-store`); // Don't cache error responses.
|
||||
return res.send(renderError(err.message, err.secondaryMessage));
|
||||
}
|
||||
};
|
||||
|
||||
Generated
+876
-383
File diff suppressed because it is too large
Load Diff
+23
-9
@@ -1,9 +1,23 @@
|
||||
{
|
||||
"name": "github-readme-stats",
|
||||
"version": "1.0.0",
|
||||
"description": "Dynamically generate stats for your github readmes",
|
||||
"main": "index.js",
|
||||
"description": "Dynamically generate stats for your GitHub readme",
|
||||
"keywords": [
|
||||
"github-readme-stats",
|
||||
"readme-stats",
|
||||
"cards",
|
||||
"card-generator"
|
||||
],
|
||||
"main": "src/index.js",
|
||||
"type": "module",
|
||||
"homepage": "https://github.com/anuraghazra/github-readme-stats",
|
||||
"bugs": {
|
||||
"url": "https://github.com/anuraghazra/github-readme-stats/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/anuraghazra/github-readme-stats.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
|
||||
"test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch",
|
||||
@@ -13,8 +27,9 @@
|
||||
"preview-theme": "node scripts/preview-theme",
|
||||
"close-stale-theme-prs": "node scripts/close-stale-theme-prs",
|
||||
"generate-langs-json": "node scripts/generate-langs-json",
|
||||
"format": "./node_modules/.bin/prettier --write .",
|
||||
"format:check": "./node_modules/.bin/prettier --check ."
|
||||
"format": "prettier --write .",
|
||||
"format:check": "prettier --check .",
|
||||
"prepare": "husky install"
|
||||
},
|
||||
"author": "Anurag Hazra",
|
||||
"license": "MIT",
|
||||
@@ -27,10 +42,11 @@
|
||||
"axios-mock-adapter": "^1.18.1",
|
||||
"color-contrast-checker": "^2.1.0",
|
||||
"hjson": "^3.2.2",
|
||||
"husky": "^4.2.5",
|
||||
"husky": "^8.0.0",
|
||||
"jest": "^29.0.3",
|
||||
"jest-environment-jsdom": "^29.0.3",
|
||||
"js-yaml": "^4.1.0",
|
||||
"lint-staged": "^13.0.3",
|
||||
"lodash.snakecase": "^4.1.1",
|
||||
"parse-diff": "^0.7.0",
|
||||
"prettier": "^2.1.2"
|
||||
@@ -43,9 +59,7 @@
|
||||
"upgrade": "^1.1.0",
|
||||
"word-wrap": "^1.2.3"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "npm test"
|
||||
}
|
||||
"lint-staged": {
|
||||
"*.{js,css,md}": "prettier --write"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,8 @@
|
||||
<a href="/docs/readme_tr.md">Türkçe</a>
|
||||
</p>
|
||||
</p>
|
||||
<p align="center">Love the project? Please consider <a href="https://www.paypal.me/anuraghazra">donating</a> to help it improve!
|
||||
|
||||
<p align="center">Love the project? Please consider <a href="https://www.paypal.me/anuraghazra">donating</a> to help it improve!</p>
|
||||
|
||||
<a href="https://indiafightscorona.giveindia.org">
|
||||
<img src="https://indiaspora.org/wp-content/uploads/2021/04/give-India-logo.png" alt="Give india logo" width="200" />
|
||||
@@ -91,6 +92,7 @@ Visit <https://indiafightscorona.giveindia.org> and make a small donation to hel
|
||||
- [Language Card Exclusive Options](#language-card-exclusive-options)
|
||||
- [Wakatime Card Exclusive Option](#wakatime-card-exclusive-options)
|
||||
- [Deploy Yourself](#deploy-on-your-own-vercel-instance)
|
||||
- [Keep your fork up to date](#keep-your-fork-up-to-date)
|
||||
|
||||
# GitHub Stats Card
|
||||
|
||||
@@ -102,9 +104,8 @@ Change the `?username=` value to your GitHub username.
|
||||
[](https://github.com/anuraghazra/github-readme-stats)
|
||||
```
|
||||
|
||||
_Note: Available ranks are S+ (top 1%), S (top 25%), A++ (top 45%), A+ (top 60%), and B+ (everyone).
|
||||
The values are calculated by using the [cumulative distribution function](https://en.wikipedia.org/wiki/Cumulative_distribution_function) using commits, contributions, issues, stars, pull requests, followers, and owned repositories.
|
||||
The implementation can be investigated at [src/calculateRank.js](./src/calculateRank.js)._
|
||||
> **Note**
|
||||
> Available ranks are S+ (top 1%), S (top 25%), A++ (top 45%), A+ (top 60%), and B+ (everyone). The values are calculated by using the [cumulative distribution function](https://en.wikipedia.org/wiki/Cumulative_distribution_function) using commits, contributions, issues, stars, pull requests, followers, and owned repositories. The implementation can be investigated at [src/calculateRank.js](./src/calculateRank.js).
|
||||
|
||||
### Hiding individual stats
|
||||
|
||||
@@ -120,7 +121,8 @@ You can pass a query parameter `&hide=` to hide any specific stats with comma-se
|
||||
|
||||
You can add the count of all your private contributions to the total commits count by using the query parameter `&count_private=true`.
|
||||
|
||||
_Note: If you are deploying this project yourself, the private contributions will be counted by default. If you are using the public Vercel instance, you need to choose to [share your private contributions](https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/managing-contribution-settings-on-your-profile/showing-your-private-contributions-and-achievements-on-your-profile)._
|
||||
> **Note**
|
||||
> If you are deploying this project yourself, the private contributions will be counted by default. If you are using the public Vercel instance, you need to choose to [share your private contributions](https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/managing-contribution-settings-on-your-profile/showing-your-private-contributions-and-achievements-on-your-profile).
|
||||
|
||||
> Options: `&count_private=true`
|
||||
|
||||
@@ -171,7 +173,8 @@ You can customize the appearance of your `Stats Card` or `Repo Card` however you
|
||||
- `locale` - set the language in the card _(e.g. cn, de, es, etc.)_. Default: `en`.
|
||||
- `border_radius` - Corner rounding on the card. Default: `4.5`.
|
||||
|
||||
> Note: The minimum of cache_seconds is currently 4 hours as a temporary fix for PATs exhaustion.
|
||||
> **Warning**
|
||||
> We use caching to decrease the load on our servers (see https://github.com/anuraghazra/github-readme-stats/issues/1471#issuecomment-1271551425). Our cards have a default cache of 4 hours (14400 seconds). Also, note that the cache is clamped to a minimum of 4 hours and a maximum of 24 hours.
|
||||
|
||||
##### Gradient in bg_color
|
||||
|
||||
@@ -179,8 +182,6 @@ You can provide multiple comma-separated values in the bg_color option to render
|
||||
|
||||
&bg_color=DEG,COLOR1,COLOR2,COLOR3...COLOR10
|
||||
|
||||
> Note on cache: Repo cards have a default cache of 4 hours (14400 seconds) if the fork count & star count is less than 1k; otherwise, it is 2 hours (7200 seconds). Also, note that the cache is clamped to a minimum of 2 hours and a maximum of 24 hours.
|
||||
|
||||
#### Stats Card Exclusive Options
|
||||
|
||||
- `hide` - Hides the [specified items](#hiding-individual-stats) from stats _(Comma-separated values)_. Default: `[] (blank array)`.
|
||||
@@ -196,7 +197,7 @@ You can provide multiple comma-separated values in the bg_color option to render
|
||||
- `text_bold` - Use bold text _(boolean)_. Default: `true`.
|
||||
- `disable_animations` - Disables all animations in the card _(boolean)_. Default: `false`.
|
||||
|
||||
> Note on `hide_rank`:
|
||||
> **Note**
|
||||
> When hide_rank=`true`, the minimum card width is 270 px + the title length and padding.
|
||||
|
||||
#### Repo Card Exclusive Options
|
||||
@@ -213,7 +214,7 @@ You can provide multiple comma-separated values in the bg_color option to render
|
||||
- `exclude_repo` - Exclude specified repositories _(Comma-separated values)_. Default: `[] (blank array)`.
|
||||
- `custom_title` - Sets a custom title for the card _(string)_. Default `Most Used Languages`.
|
||||
|
||||
> :warning: **Important:**
|
||||
> **Warning**
|
||||
> Language names should be URI-escaped, as specified in [Percent Encoding](https://en.wikipedia.org/wiki/Percent-encoding)
|
||||
> (i.e: `c++` should become `c%2B%2B`, `jupyter notebook` should become `jupyter%20notebook`, etc.) You can use
|
||||
> [urlencoder.org](https://www.urlencoder.org/) to help you do this automatically.
|
||||
@@ -260,7 +261,8 @@ Use [show_owner](#customization) variable to include the repo's owner username
|
||||
|
||||
The top languages card shows a GitHub user's most frequently used top language.
|
||||
|
||||
_NOTE: Top Languages does not indicate my skill level or anything like that; it's a GitHub metric to determine which languages have the most code on GitHub. It is a new feature of github-readme-stats._
|
||||
> **Note**
|
||||
> Top Languages does not indicate my skill level or anything like that; it's a GitHub metric to determine which languages have the most code on GitHub. It is a new feature of github-readme-stats._
|
||||
|
||||
### Usage
|
||||
|
||||
@@ -320,7 +322,8 @@ Change the `?username=` value to your [Wakatime](https://wakatime.com) username.
|
||||
[](https://github.com/anuraghazra/github-readme-stats)
|
||||
```
|
||||
|
||||
> Note: Please be aware that we currently only show data from Wakatime profiles that are public.
|
||||
> **Note**:
|
||||
> Please be aware that we currently only show data from Wakatime profiles that are public.
|
||||
|
||||
### Demo
|
||||
|
||||
@@ -405,14 +408,18 @@ By default, GitHub does not lay out the cards side by side. To do that, you can
|
||||
|
||||
#### [Check Out Step By Step Video Tutorial By @codeSTACKr](https://youtu.be/n6d4KHSKqGk?t=107)
|
||||
|
||||
> **Warning**
|
||||
> If you are on the [hobby (i.e. free)](https://vercel.com/pricing) Vercel plan, please make sure you change the `maxDuration` parameter in the [vercel.json](https://github.com/anuraghazra/github-readme-stats/blob/master/vercel.json) file from `30` to `10` (see [#1416](https://github.com/anuraghazra/github-readme-stats/issues/1416#issuecomment-950275476) for more information).
|
||||
|
||||
Since the GitHub API only allows 5k requests per hour, my `https://github-readme-stats.vercel.app/api` could possibly hit the rate limiter. If you host it on your own Vercel server, then you do not have to worry about anything. Click on the deploy button to get started!
|
||||
|
||||
NOTE: Since [#58](https://github.com/anuraghazra/github-readme-stats/pull/58) we should be able to handle more than 5k requests and have no issues with downtime :D
|
||||
> **Note**
|
||||
> Since [#58](https://github.com/anuraghazra/github-readme-stats/pull/58), we should be able to handle more than 5k requests and have fewer issues with downtime :grin:.
|
||||
|
||||
[](https://vercel.com/import/project?template=https://github.com/anuraghazra/github-readme-stats)
|
||||
|
||||
<details>
|
||||
<summary><b> Guide on setting up Vercel 🔨 </b></summary>
|
||||
<summary><b>:hammer_and_wrench: Step-by-step guide on setting up your own Vercel instance</b></summary>
|
||||
|
||||
1. Go to [vercel.com](https://vercel.com/).
|
||||
2. Click on `Log in`.
|
||||
@@ -434,6 +441,10 @@ NOTE: Since [#58](https://github.com/anuraghazra/github-readme-stats/pull/58) we
|
||||
|
||||
</details>
|
||||
|
||||
### Keep your fork up to date
|
||||
|
||||
You can keep your fork, and thus your private Vercel instance up to date with the upstream using GitHubs' [Sync Fork button](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork). You can also use the [pull](https://github.com/wei/pull) package created by [@wei](https://github.com/wei) to automate this process.
|
||||
|
||||
## :sparkling_heart: Support the project
|
||||
|
||||
I open-source almost everything I can and try to reply to everyone needing help using these projects. Obviously,
|
||||
|
||||
@@ -24,7 +24,7 @@ const THEME_PR_FAIL_TEXT = ":x: Theme PR does not adhere to our guidelines.";
|
||||
const THEME_PR_SUCCESS_TEXT =
|
||||
":heavy_check_mark: Theme PR does adhere to our guidelines.";
|
||||
const FAIL_TEXT = `
|
||||
\rUnfortunately, your theme PR does not adhere to our [theme guidelines](https://github.com/anuraghazra/github-readme-stats/blob/master/CONTRIBUTING.md#themes-contribution). Please fix the issues below, and we will review your\
|
||||
\rUnfortunately, your theme PR contains an error or does not adhere to our [theme guidelines](https://github.com/anuraghazra/github-readme-stats/blob/master/CONTRIBUTING.md#themes-contribution). Please fix the issues below, and we will review your\
|
||||
\r PR again. This pull request will **automatically close in 15 days** if no changes are made. After this time, you must re-open the PR for it to be reviewed.
|
||||
`;
|
||||
const THEME_CONTRIB_GUIDELINESS = `
|
||||
@@ -558,6 +558,28 @@ export const run = async (prNumber) => {
|
||||
info(`DRY_RUN: Review reason: ${reviewReason}`);
|
||||
}
|
||||
} catch (error) {
|
||||
debug("Set review state to `REQUEST_CHANGES` and add `invalid` label...");
|
||||
if (!dryRun) {
|
||||
await addReview(
|
||||
octokit,
|
||||
pullRequestId,
|
||||
owner,
|
||||
repo,
|
||||
"REQUEST_CHANGES",
|
||||
error.message,
|
||||
);
|
||||
await addRemoveLabel(
|
||||
octokit,
|
||||
pullRequestId,
|
||||
owner,
|
||||
repo,
|
||||
"invalid",
|
||||
true,
|
||||
);
|
||||
} else {
|
||||
info(`DRY_RUN: Review state: REQUEST_CHANGES`);
|
||||
info(`DRY_RUN: Review reason: ${error.message}`);
|
||||
}
|
||||
setFailed(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
+10
-10
@@ -4,9 +4,9 @@
|
||||
*
|
||||
* @see https://stackoverflow.com/a/5263759/10629172
|
||||
*
|
||||
* @param {string} mean
|
||||
* @param {number} sigma
|
||||
* @param {number} to
|
||||
* @param {string} mean The mean of the normal distribution.
|
||||
* @param {number} sigma The standard deviation of the normal distribution.
|
||||
* @param {number} to The value to calculate the probability for.
|
||||
* @returns {number} Probability.
|
||||
*/
|
||||
function normalcdf(mean, sigma, to) {
|
||||
@@ -29,13 +29,13 @@ function normalcdf(mean, sigma, to) {
|
||||
/**
|
||||
* Calculates the users rank.
|
||||
*
|
||||
* @param {number} totalRepos
|
||||
* @param {number} totalCommits
|
||||
* @param {number} contributions
|
||||
* @param {number} followers
|
||||
* @param {number} prs
|
||||
* @param {number} issues
|
||||
* @param {number} stargazers
|
||||
* @param {number} totalRepos Total number of repos.
|
||||
* @param {number} totalCommits Total number of commits.
|
||||
* @param {number} contributions The number of contributions.
|
||||
* @param {number} followers The number of followers.
|
||||
* @param {number} prs The number of pull requests.
|
||||
* @param {number} issues The number of issues.
|
||||
* @param {number} stargazers The number of stars.
|
||||
* @returns {{level: string, score: number}}} The users rank.
|
||||
*/
|
||||
function calculateRank({
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export { renderRepoCard } from "./repo-card.js";
|
||||
export { renderStatsCard } from "./stats-card.js";
|
||||
export { renderTopLanguages } from "./top-languages-card.js";
|
||||
export { renderWakatimeCard } from "./wakatime-card.js";
|
||||
+24
-9
@@ -14,9 +14,11 @@ import {
|
||||
import { repoCardLocales } from "../translations.js";
|
||||
|
||||
/**
|
||||
* @param {string} label
|
||||
* @param {string} textColor
|
||||
* @returns {string}
|
||||
* Retrieves the repository description and wraps it to fit the card width.
|
||||
*
|
||||
* @param {string} label The repository description.
|
||||
* @param {string} textColor The color of the text.
|
||||
* @returns {string} Wrapped repo description SVG object.
|
||||
*/
|
||||
const getBadgeSVG = (label, textColor) => `
|
||||
<g data-testid="badge" class="badge" transform="translate(320, -18)">
|
||||
@@ -34,9 +36,11 @@ const getBadgeSVG = (label, textColor) => `
|
||||
`;
|
||||
|
||||
/**
|
||||
* @param {string} langName
|
||||
* @param {string} langColor
|
||||
* @returns {string}
|
||||
* Creates a node to display the primary programming language of the repository.
|
||||
*
|
||||
* @param {string} langName Language name.
|
||||
* @param {string} langColor Language color.
|
||||
* @returns {string} Language display SVG object.
|
||||
*/
|
||||
const createLanguageNode = (langName, langColor) => {
|
||||
return `
|
||||
@@ -48,6 +52,15 @@ const createLanguageNode = (langName, langColor) => {
|
||||
};
|
||||
|
||||
const ICON_SIZE = 16;
|
||||
|
||||
/**
|
||||
* Creates an icon with label to display repository stats like forks, stars, etc.
|
||||
*
|
||||
* @param {string} icon The icon to display.
|
||||
* @param {number|string} label The label to display.
|
||||
* @param {string} testid The testid to assign to the label.
|
||||
* @returns {string} Icon with label SVG object.
|
||||
*/
|
||||
const iconWithLabel = (icon, label, testid) => {
|
||||
if (label <= 0) return "";
|
||||
const iconSvg = `
|
||||
@@ -67,9 +80,11 @@ const iconWithLabel = (icon, label, testid) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {import('../fetchers/types').RepositoryData} repo
|
||||
* @param {Partial<import("./types").RepoCardOptions>} options
|
||||
* @returns {string}
|
||||
* Renders repository card details.
|
||||
*
|
||||
* @param {import('../fetchers/types').RepositoryData} repo Repository data.
|
||||
* @param {Partial<import("./types").RepoCardOptions>} options Card options.
|
||||
* @returns {string} Repository card SVG object.
|
||||
*/
|
||||
const renderRepoCard = (repo, options = {}) => {
|
||||
const {
|
||||
|
||||
@@ -63,9 +63,11 @@ const createTextNode = ({
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Partial<import('../fetchers/types').StatsData>} stats
|
||||
* @param {Partial<import("./types").StatCardOptions>} options
|
||||
* @returns {string}
|
||||
* Renders the stats card.
|
||||
*
|
||||
* @param {Partial<import('../fetchers/types').StatsData>} stats The stats data.
|
||||
* @param {Partial<import("./types").StatCardOptions>} options The card options.
|
||||
* @returns {string} The stats card SVG object.
|
||||
*/
|
||||
const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
||||
const {
|
||||
|
||||
@@ -23,7 +23,10 @@ const CARD_PADDING = 25;
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Lang[]} arr
|
||||
* Retrieves the programming language whose name is the longest.
|
||||
*
|
||||
* @param {Lang[]} arr Array of programming languages.
|
||||
* @returns {Object} Longest programming language object.
|
||||
*/
|
||||
const getLongestLang = (arr) =>
|
||||
arr.reduce(
|
||||
@@ -33,12 +36,15 @@ const getLongestLang = (arr) =>
|
||||
);
|
||||
|
||||
/**
|
||||
* @param {{
|
||||
* width: number,
|
||||
* color: string,
|
||||
* name: string,
|
||||
* progress: string
|
||||
* }} props
|
||||
* Creates a node to display usage of a programming language in percentage
|
||||
* using text and a horizontal progress bar.
|
||||
*
|
||||
* @param {object[]} props Function properties.
|
||||
* @param {number} props.width The card width
|
||||
* @param {string} props.name Name of the programming language.
|
||||
* @param {string} props.color Color of the programming language.
|
||||
* @param {string} props.progress Usage of the programming language in percentage.
|
||||
* @returns {string} Programming language SVG node.
|
||||
*/
|
||||
const createProgressTextNode = ({ width, color, name, progress }) => {
|
||||
const paddingRight = 95;
|
||||
@@ -60,7 +66,12 @@ const createProgressTextNode = ({ width, color, name, progress }) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {{ lang: Lang, totalSize: number }} props
|
||||
* Creates a text only node to display usage of a programming language in percentage.
|
||||
*
|
||||
* @param {object[]} props Function properties.
|
||||
* @param {Lang} props.lang Programming language object.
|
||||
* @param {number} props.totalSize Total size of all languages.
|
||||
* @returns {string} Compact layout programming language SVG node.
|
||||
*/
|
||||
const createCompactLangNode = ({ lang, totalSize }) => {
|
||||
const percentage = ((lang.size / totalSize) * 100).toFixed(2);
|
||||
@@ -77,7 +88,12 @@ const createCompactLangNode = ({ lang, totalSize }) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {{ langs: Lang[], totalSize: number }} props
|
||||
* Creates compact layout of text only language nodes.
|
||||
*
|
||||
* @param {object[]} props Function properties.
|
||||
* @param {Lang[]} props.langs Array of programming languages.
|
||||
* @param {number} props.totalSize Total size of all languages.
|
||||
* @returns {string} Programming languages SVG node.
|
||||
*/
|
||||
const createLanguageTextNode = ({ langs, totalSize }) => {
|
||||
const longestLang = getLongestLang(langs);
|
||||
@@ -109,10 +125,12 @@ const createLanguageTextNode = ({ langs, totalSize }) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Lang[]} langs
|
||||
* @param {number} width
|
||||
* @param {number} totalLanguageSize
|
||||
* @returns {string}
|
||||
* Renders layout to display user's most frequently used programming languages.
|
||||
*
|
||||
* @param {Lang[]} langs Array of programming languages.
|
||||
* @param {number} width Card width.
|
||||
* @param {number} totalLanguageSize Total size of all languages.
|
||||
* @returns {string} Normal layout card SVG object.
|
||||
*/
|
||||
const renderNormalLayout = (langs, width, totalLanguageSize) => {
|
||||
return flexLayout({
|
||||
@@ -130,10 +148,12 @@ const renderNormalLayout = (langs, width, totalLanguageSize) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Lang[]} langs
|
||||
* @param {number} width
|
||||
* @param {number} totalLanguageSize
|
||||
* @returns {string}
|
||||
* Renders compact layout to display user's most frequently used programming languages.
|
||||
*
|
||||
* @param {Lang[]} langs Array of programming languages.
|
||||
* @param {number} width Card width.
|
||||
* @param {number} totalLanguageSize Total size of all languages.
|
||||
* @returns {string} Compact layout card SVG object.
|
||||
*/
|
||||
const renderCompactLayout = (langs, width, totalLanguageSize) => {
|
||||
const paddingRight = 50;
|
||||
@@ -181,26 +201,31 @@ const renderCompactLayout = (langs, width, totalLanguageSize) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} totalLangs
|
||||
* @returns {number}
|
||||
* Calculates height for the compact layout.
|
||||
*
|
||||
* @param {number} totalLangs Total number of languages.
|
||||
* @returns {number} Card height.
|
||||
*/
|
||||
const calculateCompactLayoutHeight = (totalLangs) => {
|
||||
return 90 + Math.round(totalLangs / 2) * 25;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} totalLangs
|
||||
* @returns {number}
|
||||
* Calculates height for the normal layout.
|
||||
*
|
||||
* @param {number} totalLangs Total number of languages.
|
||||
* @returns {number} Card height.
|
||||
*/
|
||||
const calculateNormalLayoutHeight = (totalLangs) => {
|
||||
return 45 + (totalLangs + 1) * 40;
|
||||
};
|
||||
|
||||
/**
|
||||
* Hides languages and trims the list to show only the top N languages.
|
||||
*
|
||||
* @param {Record<string, Lang>} topLangs
|
||||
* @param {string[]} hide
|
||||
* @param {string} langs_count
|
||||
* @param {Record<string, Lang>} topLangs Top languages.
|
||||
* @param {string[]} hide Languages to hide.
|
||||
* @param {string} langs_count Number of languages to show.
|
||||
*/
|
||||
const useLanguages = (topLangs, hide, langs_count) => {
|
||||
let langs = Object.values(topLangs);
|
||||
@@ -229,9 +254,11 @@ const useLanguages = (topLangs, hide, langs_count) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {import('../fetchers/types').TopLangData} topLangs
|
||||
* @param {Partial<import("./types").TopLangOptions>} options
|
||||
* @returns {string}
|
||||
* Renders card to display user's most frequently used programming languages.
|
||||
*
|
||||
* @param {import('../fetchers/types').TopLangData} topLangs User's most frequently used programming languages.
|
||||
* @param {Partial<import("./types").TopLangOptions>} options Card options.
|
||||
* @returns {string} Language card SVG object.
|
||||
*/
|
||||
const renderTopLanguages = (topLangs, options = {}) => {
|
||||
const {
|
||||
|
||||
+35
-29
@@ -23,7 +23,9 @@ const require = createRequire(import.meta.url);
|
||||
const languageColors = require("../common/languageColors.json"); // now works
|
||||
|
||||
/**
|
||||
* @param {{color: string, text: string}} param0
|
||||
* Creates the no coding activity SVG node.
|
||||
*
|
||||
* @param {{color: string, text: string}} The function prop
|
||||
*/
|
||||
const noCodingActivityNode = ({ color, text }) => {
|
||||
return `
|
||||
@@ -32,13 +34,13 @@ const noCodingActivityNode = ({ color, text }) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Create compact WakaTime layout.
|
||||
*
|
||||
* @param {{
|
||||
* lang: import("../fetchers/types").WakaTimeLang,
|
||||
* totalSize: number,
|
||||
* x: number,
|
||||
* y: number
|
||||
* }} props
|
||||
* @param {Object[]} args The function arguments.
|
||||
* @param {import("../fetchers/types").WakaTimeLang[]} languages The languages array.
|
||||
* @param {number} totalSize The total size of the languages.
|
||||
* @param {number} x The x position of the language node.
|
||||
* @param {number} y The y position of the language node.
|
||||
*/
|
||||
const createCompactLangNode = ({ lang, totalSize, x, y }) => {
|
||||
const color = languageColors[lang.name] || "#858585";
|
||||
@@ -54,12 +56,13 @@ const createCompactLangNode = ({ lang, totalSize, x, y }) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {{
|
||||
* langs: import("../fetchers/types").WakaTimeLang[],
|
||||
* totalSize: number,
|
||||
* x: number,
|
||||
* y: number
|
||||
* }} props
|
||||
* Create WakaTime language text node item.
|
||||
*
|
||||
* @param {Object[]} args The function arguments.
|
||||
* @param {import("../fetchers/types").WakaTimeLang} lang The language object.
|
||||
* @param {number} totalSize The total size of the languages.
|
||||
* @param {number} x The x position of the language node.
|
||||
* @param {number} y The y position of the language node.
|
||||
*/
|
||||
const createLanguageTextNode = ({ langs, totalSize, x, y }) => {
|
||||
return langs.map((lang, index) => {
|
||||
@@ -81,17 +84,16 @@ const createLanguageTextNode = ({ langs, totalSize, x, y }) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Create WakaTime text item.
|
||||
*
|
||||
* @param {{
|
||||
* id: string;
|
||||
* label: string;
|
||||
* value: string;
|
||||
* index: number;
|
||||
* percent: number;
|
||||
* hideProgress: boolean;
|
||||
* progressBarColor: string;
|
||||
* progressBarBackgroundColor: string
|
||||
* }} props
|
||||
* @param {Object[]} args The function arguments.
|
||||
* @param {string} id The id of the text node item.
|
||||
* @param {string} label The label of the text node item.
|
||||
* @param {string} value The value of the text node item.
|
||||
* @param {number} index The index of the text node item.
|
||||
* @param {percent} percent Percentage of the text node item.
|
||||
* @param {boolean} hideProgress Whether to hide the progress bar.
|
||||
* @param {string} progressBarBackgroundColor The color of the progress bar background.
|
||||
*/
|
||||
const createTextNode = ({
|
||||
id,
|
||||
@@ -132,11 +134,13 @@ const createTextNode = ({
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {import("../fetchers/types").WakaTimeLang[]} languages
|
||||
* Recalculating percentages so that, compact layout's progress bar does not break when
|
||||
* hiding languages.
|
||||
*
|
||||
* @param {import("../fetchers/types").WakaTimeLang[]} languages The languages array.
|
||||
* @return {import("../fetchers/types").WakaTimeLang[]} The recalculated languages array.
|
||||
*/
|
||||
const recalculatePercentages = (languages) => {
|
||||
// recalculating percentages so that,
|
||||
// compact layout's progress bar does not break when hiding languages
|
||||
const totalSum = languages.reduce(
|
||||
(totalSum, language) => totalSum + language.percent,
|
||||
0,
|
||||
@@ -148,9 +152,11 @@ const recalculatePercentages = (languages) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Partial<import('../fetchers/types').WakaTimeData>} stats
|
||||
* @param {Partial<import('./types').WakaTimeOptions>} options
|
||||
* @returns {string}
|
||||
* Renders WakaTime card.
|
||||
*
|
||||
* @param {Partial<import('../fetchers/types').WakaTimeData>} stats WakaTime stats.
|
||||
* @param {Partial<import('./types').WakaTimeOptions>} options Card options.
|
||||
* @returns {string} WakaTime card SVG.
|
||||
*/
|
||||
const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
|
||||
let { languages } = stats;
|
||||
|
||||
+10
-8
@@ -3,14 +3,16 @@ import { encodeHTML, flexLayout } from "./utils.js";
|
||||
|
||||
class Card {
|
||||
/**
|
||||
* @param {object} args
|
||||
* @param {number?=} args.width
|
||||
* @param {number?=} args.height
|
||||
* @param {number?=} args.border_radius
|
||||
* @param {string?=} args.customTitle
|
||||
* @param {string?=} args.defaultTitle
|
||||
* @param {string?=} args.titlePrefixIcon
|
||||
* @param {ReturnType<import('../common/utils.js').getCardColors>?=} args.colors
|
||||
* Creates a new card instance.
|
||||
*
|
||||
* @param {object} args Card arguments.
|
||||
* @param {number?=} args.width Card width.
|
||||
* @param {number?=} args.height Card height.
|
||||
* @param {number?=} args.border_radius Card border radius.
|
||||
* @param {string?=} args.customTitle Card custom title.
|
||||
* @param {string?=} args.defaultTitle Card default title.
|
||||
* @param {string?=} args.titlePrefixIcon Card title prefix icon.
|
||||
* @returns {Card} Card instance.
|
||||
*/
|
||||
constructor({
|
||||
width = 100,
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
/**
|
||||
* I18n translation class.
|
||||
*/
|
||||
class I18n {
|
||||
constructor({ locale, translations }) {
|
||||
this.locale = locale;
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
import { clampValue } from "./utils.js";
|
||||
|
||||
/**
|
||||
* Create a node to indicate progress in percentage along a horizontal line.
|
||||
*
|
||||
* @param {Object} createProgressNodeParams Object that contains the createProgressNode parameters.
|
||||
* @param {number} createProgressNodeParams.x X-axis position.
|
||||
* @param {number} createProgressNodeParams.y Y-axis position.
|
||||
* @param {number} createProgressNodeParams.width Width of progress bar.
|
||||
* @param {string} createProgressNodeParams.color Progress color.
|
||||
* @param {string} createProgressNodeParams.progress Progress value.
|
||||
* @param {string} createProgressNodeParams.progressBarBackgroundColor Progress bar bg color.
|
||||
* @returns {string} Progress node.
|
||||
*/
|
||||
const createProgressNode = ({
|
||||
x,
|
||||
y,
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
export { blacklist } from "./blacklist.js";
|
||||
export { Card } from "./Card.js";
|
||||
export { createProgressNode } from "./createProgressNode.js";
|
||||
export { I18n } from "./I18n.js";
|
||||
export { icons } from "./icons.js";
|
||||
export { retryer } from "./retryer.js";
|
||||
export {
|
||||
ERROR_CARD_LENGTH,
|
||||
renderError,
|
||||
encodeHTML,
|
||||
kFormatter,
|
||||
isValidHexColor,
|
||||
parseBoolean,
|
||||
parseArray,
|
||||
clampValue,
|
||||
isValidGradient,
|
||||
fallbackColor,
|
||||
request,
|
||||
flexLayout,
|
||||
getCardColors,
|
||||
wrapTextMultiline,
|
||||
logger,
|
||||
CONSTANTS,
|
||||
CustomError,
|
||||
MissingParamError,
|
||||
measureText,
|
||||
lowercaseTrim,
|
||||
chunkArray,
|
||||
parseEmojis,
|
||||
} from "./utils.js";
|
||||
@@ -45,6 +45,8 @@ const retryer = async (fetcher, variables, retries = 0) => {
|
||||
retries++;
|
||||
// directly return from the function
|
||||
return retryer(fetcher, variables, retries);
|
||||
} else {
|
||||
return err.response;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+101
-62
@@ -4,20 +4,27 @@ import toEmoji from "emoji-name-map";
|
||||
import wrap from "word-wrap";
|
||||
import { themes } from "../../themes/index.js";
|
||||
|
||||
// Script parameters.
|
||||
const ERROR_CARD_LENGTH = 576.5;
|
||||
|
||||
/**
|
||||
* @param {string} message
|
||||
* @param {string} secondaryMessage
|
||||
* @returns {string}
|
||||
* Renders error message on the card.
|
||||
*
|
||||
* @param {string} message Main error message.
|
||||
* @param {string} secondaryMessage The secondary error message.
|
||||
* @returns {string} The SVG markup.
|
||||
*/
|
||||
const renderError = (message, secondaryMessage = "") => {
|
||||
return `
|
||||
<svg width="576.5" height="120" viewBox="0 0 576.5 120" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<svg width="${ERROR_CARD_LENGTH}" height="120" viewBox="0 0 ${ERROR_CARD_LENGTH} 120" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.text { font: 600 16px 'Segoe UI', Ubuntu, Sans-Serif; fill: #2F80ED }
|
||||
.small { font: 600 12px 'Segoe UI', Ubuntu, Sans-Serif; fill: #252525 }
|
||||
.gray { fill: #858585 }
|
||||
</style>
|
||||
<rect x="0.5" y="0.5" width="575.5" height="99%" rx="4.5" fill="#FFFEFE" stroke="#E4E2E2"/>
|
||||
<rect x="0.5" y="0.5" width="${
|
||||
ERROR_CARD_LENGTH - 1
|
||||
}" height="99%" rx="4.5" fill="#FFFEFE" stroke="#E4E2E2"/>
|
||||
<text x="25" y="45" class="text">Something went wrong! file an issue at https://tiny.one/readme-stats</text>
|
||||
<text data-testid="message" x="25" y="55" class="text small">
|
||||
<tspan x="25" dy="18">${encodeHTML(message)}</tspan>
|
||||
@@ -28,9 +35,12 @@ const renderError = (message, secondaryMessage = "") => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Encode string as HTML.
|
||||
*
|
||||
* @see https://stackoverflow.com/a/48073476/10629172
|
||||
* @param {string} str
|
||||
* @returns {string}
|
||||
*
|
||||
* @param {string} str String to encode.
|
||||
* @returns {string} Encoded string.
|
||||
*/
|
||||
function encodeHTML(str) {
|
||||
return str
|
||||
@@ -41,7 +51,10 @@ function encodeHTML(str) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} num
|
||||
* Retrieves num with suffix k(thousands) precise to 1 decimal if greater than 999.
|
||||
*
|
||||
* @param {number} num The number to format.
|
||||
* @returns {string|number} The formatted number.
|
||||
*/
|
||||
function kFormatter(num) {
|
||||
return Math.abs(num) > 999
|
||||
@@ -50,8 +63,12 @@ function kFormatter(num) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} hexColor
|
||||
* @returns {boolean}
|
||||
* Checks if a string is a valid hex color.
|
||||
*
|
||||
* @param {string} hexColor String to check.
|
||||
* @returns {boolean} True if the given string is a valid hex color.
|
||||
*
|
||||
* @description: Tests color codes without the hash (#) prefix.
|
||||
*/
|
||||
function isValidHexColor(hexColor) {
|
||||
return new RegExp(
|
||||
@@ -60,8 +77,10 @@ function isValidHexColor(hexColor) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @returns {boolean | string}
|
||||
* 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.
|
||||
*/
|
||||
function parseBoolean(value) {
|
||||
if (value === "true") {
|
||||
@@ -102,16 +121,19 @@ function clampValue(number, min, max) {
|
||||
* Check if the given string is a valid gradient.
|
||||
*
|
||||
* @param {string[]} colors Array of colors.
|
||||
* returns {boolean} True if the given string is a valid gradient.
|
||||
* @returns {boolean} True if the given string is a valid gradient.
|
||||
*/
|
||||
function isValidGradient(colors) {
|
||||
return isValidHexColor(colors[1]) && isValidHexColor(colors[2]);
|
||||
if (isNaN(colors[0])) return false;
|
||||
return colors.slice(1).every((color) => isValidHexColor(color));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} color
|
||||
* @param {string} fallbackColor
|
||||
* @returns {string | string[]}
|
||||
* Retrieves a gradient if color has more than one valid hex codes else a single color.
|
||||
*
|
||||
* @param {string} color The color to parse.
|
||||
* @param {string} fallbackColor The fallback color.
|
||||
* @returns {string | string[]} The gradient or color.
|
||||
*/
|
||||
function fallbackColor(color, fallbackColor) {
|
||||
let colors = color.split(",");
|
||||
@@ -128,8 +150,11 @@ function fallbackColor(color, fallbackColor) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('axios').AxiosRequestConfig['data']} data
|
||||
* @param {import('axios').AxiosRequestConfig['headers']} headers
|
||||
* Send GraphQL request to GitHub API.
|
||||
*
|
||||
* @param {import('axios').AxiosRequestConfig['data']} data Request data.
|
||||
* @param {import('axios').AxiosRequestConfig['headers']} headers Request headers.
|
||||
* @returns {Promise<any>} Request response.
|
||||
*/
|
||||
function request(data, headers) {
|
||||
// @ts-ignore
|
||||
@@ -142,17 +167,15 @@ function request(data, headers) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} props
|
||||
* @param {string[]} props.items
|
||||
* @param {number} props.gap
|
||||
* @param {number[]?=} props.sizes
|
||||
* @param {"column" | "row"?=} props.direction
|
||||
* Auto layout utility, allows us to layout things vertically or horizontally with
|
||||
* proper gaping.
|
||||
*
|
||||
* @returns {string[]}
|
||||
*
|
||||
* @description
|
||||
* Auto layout utility, allows us to layout things
|
||||
* vertically or horizontally with proper gaping
|
||||
* @param {object} props Function properties.
|
||||
* @param {string[]} props.items Array of items to layout.
|
||||
* @param {number} props.gap Gap between items.
|
||||
* @param {"column" | "row"?=} props.direction Direction to layout items.
|
||||
* @param {number[]?=} props.sizes Array of sizes for each item.
|
||||
* @returns {string[]} Array of items with proper layout.
|
||||
*/
|
||||
function flexLayout({ items, gap, direction, sizes = [] }) {
|
||||
let lastSize = 0;
|
||||
@@ -169,18 +192,17 @@ function flexLayout({ items, gap, direction, sizes = [] }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {object} CardColors
|
||||
* @prop {string?=} title_color
|
||||
* @prop {string?=} text_color
|
||||
* @prop {string?=} icon_color
|
||||
* @prop {string?=} bg_color
|
||||
* @prop {string?=} border_color
|
||||
* @prop {keyof typeof import('../../themes')?=} fallbackTheme
|
||||
* @prop {keyof typeof import('../../themes')?=} theme
|
||||
*/
|
||||
/**
|
||||
* returns theme based colors with proper overrides and defaults
|
||||
* @param {CardColors} options
|
||||
* Returns theme based colors with proper overrides and defaults.
|
||||
*
|
||||
* @param {Object[]} args Function arguments.
|
||||
* @param {string} args.title_color Card title color.
|
||||
* @param {string} args.text_color Card text color.
|
||||
* @param {string} args.icon_color Card icon color.
|
||||
* @param {string} args.bg_color Card background color.
|
||||
* @param {string} args.border_color Card border color.
|
||||
* @param {string} args.theme Card theme.
|
||||
* @param {string} args.fallbackTheme Fallback theme.
|
||||
*
|
||||
*/
|
||||
function getCardColors({
|
||||
title_color,
|
||||
@@ -224,10 +246,12 @@ function getCardColors({
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} text
|
||||
* @param {number} width
|
||||
* @param {number} maxLines
|
||||
* @returns {string[]}
|
||||
* Split text over multiple lines based on the card width.
|
||||
*
|
||||
* @param {string} text Text to split.
|
||||
* @param {number} width Line width in number of characters.
|
||||
* @param {number} maxLines Maximum number of lines.
|
||||
* @returns {string[]} Array of lines.
|
||||
*/
|
||||
function wrapTextMultiline(text, width = 59, maxLines = 3) {
|
||||
const fullWidthComma = ",";
|
||||
@@ -272,12 +296,16 @@ const SECONDARY_ERROR_MESSAGES = {
|
||||
MAX_RETRY:
|
||||
"Please add an env variable called PAT_1 with your github token in vercel",
|
||||
USER_NOT_FOUND: "Make sure the provided username is not an organization",
|
||||
GRAPHQL_ERROR: "Please try again later",
|
||||
};
|
||||
|
||||
/**
|
||||
* Custom error class to handle custom GRS errors.
|
||||
*/
|
||||
class CustomError extends Error {
|
||||
/**
|
||||
* @param {string} message
|
||||
* @param {string} type
|
||||
* @param {string} message Error message.
|
||||
* @param {string} type Error type.
|
||||
*/
|
||||
constructor(message, type) {
|
||||
super(message);
|
||||
@@ -287,8 +315,12 @@ class CustomError extends Error {
|
||||
|
||||
static MAX_RETRY = "MAX_RETRY";
|
||||
static USER_NOT_FOUND = "USER_NOT_FOUND";
|
||||
static GRAPHQL_ERROR = "GRAPHQL_ERROR";
|
||||
}
|
||||
|
||||
/**
|
||||
* Missing query parameter class.
|
||||
*/
|
||||
class MissingParamError extends Error {
|
||||
/**
|
||||
* @param {string[]} missedParams
|
||||
@@ -305,10 +337,12 @@ class MissingParamError extends Error {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve text length.
|
||||
*
|
||||
* @see https://stackoverflow.com/a/48172630/10629172
|
||||
* @param {string} str
|
||||
* @param {number} fontSize
|
||||
* @returns
|
||||
* @param {string} str String to measure.
|
||||
* @param {number} fontSize Font size.
|
||||
* @returns {number} Text length.
|
||||
*/
|
||||
function measureText(str, fontSize = 10) {
|
||||
// prettier-ignore
|
||||
@@ -348,10 +382,12 @@ function measureText(str, fontSize = 10) {
|
||||
const lowercaseTrim = (name) => name.toLowerCase().trim();
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {Array<T>} arr
|
||||
* @param {number} perChunk
|
||||
* @returns {Array<T>}
|
||||
* Split array of languages in columns.
|
||||
*
|
||||
* @template T Langauge object.
|
||||
* @param {Array<T>} arr Array of languages.
|
||||
* @param {number} perChunk Number of languages per column.
|
||||
* @returns {Array<T>} Array of languages split in columns.
|
||||
*/
|
||||
function chunkArray(arr, perChunk) {
|
||||
return arr.reduce((resultArray, item, index) => {
|
||||
@@ -368,35 +404,38 @@ function chunkArray(arr, perChunk) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse emoji from string.
|
||||
*
|
||||
* @param {string} str
|
||||
* @returns {string}
|
||||
* @param {string} str String to parse emoji from.
|
||||
* @returns {string} String with emoji parsed.
|
||||
*/
|
||||
function parseEmojis(str) {
|
||||
if (!str) throw new Error("[parseEmoji]: str argument not provided");
|
||||
return str.replace(/:\w+:/gm, (emoji) => {
|
||||
return str.replace(/:[\w+-]+:/gm, (emoji) => {
|
||||
return toEmoji.get(emoji) || "";
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
ERROR_CARD_LENGTH,
|
||||
renderError,
|
||||
kFormatter,
|
||||
encodeHTML,
|
||||
kFormatter,
|
||||
isValidHexColor,
|
||||
request,
|
||||
parseArray,
|
||||
parseBoolean,
|
||||
parseArray,
|
||||
clampValue,
|
||||
isValidGradient,
|
||||
fallbackColor,
|
||||
request,
|
||||
flexLayout,
|
||||
getCardColors,
|
||||
clampValue,
|
||||
wrapTextMultiline,
|
||||
measureText,
|
||||
logger,
|
||||
CONSTANTS,
|
||||
CustomError,
|
||||
MissingParamError,
|
||||
measureText,
|
||||
lowercaseTrim,
|
||||
chunkArray,
|
||||
parseEmojis,
|
||||
|
||||
@@ -3,8 +3,11 @@ import { retryer } from "../common/retryer.js";
|
||||
import { MissingParamError, request } from "../common/utils.js";
|
||||
|
||||
/**
|
||||
* @param {import('Axios').AxiosRequestHeaders} variables
|
||||
* @param {string} token
|
||||
* Repo data fetcher.
|
||||
*
|
||||
* @param {import('Axios').AxiosRequestHeaders} variables Fetcher variables.
|
||||
* @param {string} token Github token.
|
||||
* @returns {Promise<import('Axios').AxiosResponse>} The response.
|
||||
*/
|
||||
const fetcher = (variables, token) => {
|
||||
return request(
|
||||
@@ -51,9 +54,11 @@ const fetcher = (variables, token) => {
|
||||
const urlExample = "/api/pin?username=USERNAME&repo=REPO_NAME";
|
||||
|
||||
/**
|
||||
* @param {string} username
|
||||
* @param {string} reponame
|
||||
* @returns {Promise<import("./types").RepositoryData>}
|
||||
* Fetch repository data.
|
||||
*
|
||||
* @param {string} username Github username.
|
||||
* @param {string} reponame Github repository name.
|
||||
* @returns {Promise<import("./types").RepositoryData>} Repository data.
|
||||
*/
|
||||
async function fetchRepo(username, reponame) {
|
||||
if (!username && !reponame) {
|
||||
|
||||
@@ -9,13 +9,17 @@ import {
|
||||
logger,
|
||||
MissingParamError,
|
||||
request,
|
||||
wrapTextMultiline,
|
||||
} from "../common/utils.js";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
/**
|
||||
* @param {import('axios').AxiosRequestHeaders} variables
|
||||
* @param {string} token
|
||||
* Stats fetcher object.
|
||||
*
|
||||
* @param {import('axios').AxiosRequestHeaders} variables Fetcher variables.
|
||||
* @param {string} token Github token.
|
||||
* @returns {Promise<import('../common/types').StatsFetcherResponse>} Stats fetcher response.
|
||||
*/
|
||||
const fetcher = (variables, token) => {
|
||||
return request(
|
||||
@@ -59,8 +63,11 @@ const fetcher = (variables, token) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {import('axios').AxiosRequestHeaders} variables
|
||||
* @param {string} token
|
||||
* Fetch first 100 repositories for a given username.
|
||||
*
|
||||
* @param {import('axios').AxiosRequestHeaders} variables Fetcher variables.
|
||||
* @param {string} token Github token.
|
||||
* @returns {Promise<import('../common/types').StatsFetcherResponse>} Repositories fetcher response.
|
||||
*/
|
||||
const repositoriesFetcher = (variables, token) => {
|
||||
return request(
|
||||
@@ -91,8 +98,15 @@ const repositoriesFetcher = (variables, token) => {
|
||||
);
|
||||
};
|
||||
|
||||
// https://github.com/anuraghazra/github-readme-stats/issues/92#issuecomment-661026467
|
||||
// https://github.com/anuraghazra/github-readme-stats/pull/211/
|
||||
/**
|
||||
* Fetch all the commits for all the repositories of a given username.
|
||||
*
|
||||
* @param {*} username Github username.
|
||||
* @returns {Promise<number>} Total commits.
|
||||
*
|
||||
* @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) => {
|
||||
if (!githubUsernameRegex.test(username)) {
|
||||
logger.log("Invalid username");
|
||||
@@ -127,9 +141,11 @@ const totalCommitsFetcher = async (username) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetch all the stars for all the repositories of a given username
|
||||
* @param {string} username
|
||||
* @param {array} repoToHide
|
||||
* Fetch all the stars for all the repositories of a given username.
|
||||
*
|
||||
* @param {string} username Github username.
|
||||
* @param {array} repoToHide Repositories to hide.
|
||||
* @returns {Promise<number>} Total stars.
|
||||
*/
|
||||
const totalStarsFetcher = async (username, repoToHide) => {
|
||||
let nodes = [];
|
||||
@@ -152,9 +168,10 @@ const totalStarsFetcher = async (username, repoToHide) => {
|
||||
(node) => node.stargazers.totalCount !== 0,
|
||||
);
|
||||
nodes.push(...nodesWithStars);
|
||||
hasNextPage =
|
||||
allNodes.length === nodesWithStars.length &&
|
||||
res.data.data.user.repositories.pageInfo.hasNextPage;
|
||||
// hasNextPage =
|
||||
// allNodes.length === nodesWithStars.length &&
|
||||
// res.data.data.user.repositories.pageInfo.hasNextPage;
|
||||
hasNextPage = false; // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
endCursor = res.data.data.user.repositories.pageInfo.endCursor;
|
||||
}
|
||||
|
||||
@@ -164,10 +181,12 @@ const totalStarsFetcher = async (username, repoToHide) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} username
|
||||
* @param {boolean} count_private
|
||||
* @param {boolean} include_all_commits
|
||||
* @returns {Promise<import("./types").StatsData>}
|
||||
* Fetch stats for a given username.
|
||||
*
|
||||
* @param {string} username Github username.
|
||||
* @param {boolean} count_private Include private contributions.
|
||||
* @param {boolean} include_all_commits Include all commits.
|
||||
* @returns {Promise<import("./types").StatsData>} Stats data.
|
||||
*/
|
||||
async function fetchStats(
|
||||
username,
|
||||
@@ -189,11 +208,24 @@ async function fetchStats(
|
||||
|
||||
let res = await retryer(fetcher, { login: username });
|
||||
|
||||
// Catch GraphQL errors.
|
||||
if (res.data.errors) {
|
||||
logger.error(res.data.errors);
|
||||
if (res.data.errors[0].type === "NOT_FOUND") {
|
||||
throw new CustomError(
|
||||
res.data.errors[0].message || "Could not fetch user.",
|
||||
CustomError.USER_NOT_FOUND,
|
||||
);
|
||||
}
|
||||
if (res.data.errors[0].message) {
|
||||
throw new CustomError(
|
||||
wrapTextMultiline(res.data.errors[0].message, 90, 1)[0],
|
||||
res.statusText,
|
||||
);
|
||||
}
|
||||
throw new CustomError(
|
||||
res.data.errors[0].message || "Could not fetch user",
|
||||
CustomError.USER_NOT_FOUND,
|
||||
"Something went while trying to retrieve the stats data using the GraphQL API.",
|
||||
CustomError.GRAPHQL_ERROR,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
// @ts-check
|
||||
import * as dotenv from "dotenv";
|
||||
import { retryer } from "../common/retryer.js";
|
||||
import { logger, MissingParamError, request } from "../common/utils.js";
|
||||
import {
|
||||
CustomError,
|
||||
logger,
|
||||
MissingParamError,
|
||||
request,
|
||||
wrapTextMultiline,
|
||||
} from "../common/utils.js";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
/**
|
||||
* @param {import('Axios').AxiosRequestHeaders} variables
|
||||
* @param {string} token
|
||||
* Top languages fetcher object.
|
||||
*
|
||||
* @param {import('Axios').AxiosRequestHeaders} variables Fetcher variables.
|
||||
* @param {string} token Github token.
|
||||
* @returns {Promise<import('../common/types').StatsFetcherResponse>} Languages fetcher response.
|
||||
*/
|
||||
const fetcher = (variables, token) => {
|
||||
return request(
|
||||
@@ -42,9 +51,11 @@ const fetcher = (variables, token) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} username
|
||||
* @param {string[]} exclude_repo
|
||||
* @returns {Promise<import("./types").TopLangData>}
|
||||
* Fetch top languages for a given username.
|
||||
*
|
||||
* @param {string} username Github username.
|
||||
* @param {string[]} exclude_repo List of repositories to exclude.
|
||||
* @returns {Promise<import("./types").TopLangData>} Top languages data.
|
||||
*/
|
||||
async function fetchTopLanguages(username, exclude_repo = []) {
|
||||
if (!username) throw new MissingParamError(["username"]);
|
||||
@@ -56,6 +67,27 @@ async function fetchTopLanguages(username, exclude_repo = []) {
|
||||
throw Error(res.data.errors[0].message || "Could not fetch user");
|
||||
}
|
||||
|
||||
// Catch GraphQL errors.
|
||||
if (res.data.errors) {
|
||||
logger.error(res.data.errors);
|
||||
if (res.data.errors[0].type === "NOT_FOUND") {
|
||||
throw new CustomError(
|
||||
res.data.errors[0].message || "Could not fetch user.",
|
||||
CustomError.USER_NOT_FOUND,
|
||||
);
|
||||
}
|
||||
if (res.data.errors[0].message) {
|
||||
throw new CustomError(
|
||||
wrapTextMultiline(res.data.errors[0].message, 90, 1)[0],
|
||||
res.statusText,
|
||||
);
|
||||
}
|
||||
throw new CustomError(
|
||||
"Something went while trying to retrieve the language data using the GraphQL API.",
|
||||
CustomError.GRAPHQL_ERROR,
|
||||
);
|
||||
}
|
||||
|
||||
let repoNodes = res.data.data.user.repositories.nodes;
|
||||
let repoToHide = {};
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@ import axios from "axios";
|
||||
import { MissingParamError } from "../common/utils.js";
|
||||
|
||||
/**
|
||||
* @param {{username: string, api_domain: string, range: string}} props
|
||||
* @returns {Promise<WakaTimeData>}
|
||||
* WakaTime data fetcher.
|
||||
*
|
||||
* @param {{username: string, api_domain: string, range: string}} props Fetcher props.
|
||||
* @returns {Promise<WakaTimeData>} WakaTime data response.
|
||||
*/
|
||||
const fetchWakatimeStats = async ({ username, api_domain, range }) => {
|
||||
if (!username) throw new MissingParamError(["username"]);
|
||||
|
||||
+22
-10
@@ -1,6 +1,9 @@
|
||||
// @ts-check
|
||||
/**
|
||||
* @param {number} value
|
||||
* Calculates progress along the boundary of the circle i.e it's circumference.
|
||||
*
|
||||
* @param {number} value The rank value to calculate progress for.
|
||||
* @returns {number} Progress value.
|
||||
*/
|
||||
const calculateCircleProgress = (value) => {
|
||||
const radius = 40;
|
||||
@@ -13,9 +16,11 @@ const calculateCircleProgress = (value) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the animation to display progress along the circumference of circle
|
||||
* from the beginning to the given value in a clockwise direction.
|
||||
*
|
||||
* @param {{progress: number}} param0
|
||||
* @returns
|
||||
* @param {{progress: number}} progress The progress value to animate to.
|
||||
* @returns {string} Progress animation css.
|
||||
*/
|
||||
const getProgressAnimation = ({ progress }) => {
|
||||
return `
|
||||
@@ -30,6 +35,11 @@ const getProgressAnimation = ({ progress }) => {
|
||||
`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves css animations for a card.
|
||||
*
|
||||
* @returns {string} Animation css.
|
||||
*/
|
||||
const getAnimations = () => {
|
||||
return `
|
||||
/* Animations */
|
||||
@@ -53,13 +63,15 @@ const getAnimations = () => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {{
|
||||
* titleColor?: string | string[]
|
||||
* textColor?: string | string[]
|
||||
* iconColor?: string | string[]
|
||||
* show_icons?: boolean;
|
||||
* progress?: number;
|
||||
* }} args
|
||||
* Retrieves CSS styles for a card.
|
||||
*
|
||||
* @param {Object[]} colors The colors to use for the card.
|
||||
* @param {string} colors.titleColor The title color.
|
||||
* @param {string} colors.textColor The text color.
|
||||
* @param {string} colors.iconColor The icon color.
|
||||
* @param {boolean} colors.show_icons Whether to show icons.
|
||||
* @param {number} colors.progress The progress value to animate to.
|
||||
* @returns {string} Card CSS styles.
|
||||
*/
|
||||
const getStyles = ({
|
||||
titleColor,
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from "./common/index.js";
|
||||
export * from "./cards/index.js";
|
||||
export { getStyles, getAnimations } from "./getStyles.js";
|
||||
@@ -1,5 +1,12 @@
|
||||
import { encodeHTML } from "./common/utils.js";
|
||||
|
||||
/**
|
||||
* Retrieves stat card labels in the available locales.
|
||||
*
|
||||
* @param {string} name The name of the locale.
|
||||
* @param {string} apostrophe Whether to use apostrophe or not.
|
||||
* @returns {Object} The locales object.
|
||||
*/
|
||||
const statCardLocales = ({ name, apostrophe }) => {
|
||||
const encodedName = encodeHTML(name);
|
||||
return {
|
||||
@@ -354,6 +361,12 @@ const wakatimeCardLocales = {
|
||||
|
||||
const availableLocales = Object.keys(repoCardLocales["repocard.archived"]);
|
||||
|
||||
/**
|
||||
* Checks whether the locale is available or not.
|
||||
*
|
||||
* @param {string} locale The locale to check.
|
||||
* @returns {boolean} Boolean specifying whether the locale is available or not.
|
||||
*/
|
||||
function isLocaleAvailable(locale) {
|
||||
return availableLocales.includes(locale.toLowerCase());
|
||||
}
|
||||
|
||||
@@ -174,6 +174,16 @@ describe("Test /api/", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("should not store cache when error", async () => {
|
||||
const { req, res } = faker({}, error);
|
||||
await api(req, res);
|
||||
|
||||
expect(res.setHeader.mock.calls).toEqual([
|
||||
["Content-Type", "image/svg+xml"],
|
||||
["Cache-Control", `no-store`],
|
||||
]);
|
||||
});
|
||||
|
||||
it("should set proper cache with clamped values", async () => {
|
||||
{
|
||||
let { req, res } = faker({ cache_seconds: 200000 }, data);
|
||||
|
||||
@@ -145,6 +145,7 @@ describe("Card", () => {
|
||||
"#fff",
|
||||
);
|
||||
});
|
||||
|
||||
it("should render gradient backgrounds", () => {
|
||||
const { titleColor, textColor, iconColor, bgColor } = getCardColors({
|
||||
title_color: "f00",
|
||||
|
||||
+19
-8
@@ -11,7 +11,6 @@ import { renderStatsCard } from "../../src/cards/stats-card.js";
|
||||
import { renderTopLanguages } from "../../src/cards/top-languages-card.js";
|
||||
import { renderWakatimeCard } from "../../src/cards/wakatime-card.js";
|
||||
|
||||
// Script variables
|
||||
const REPO = "dummy-cra";
|
||||
const USER = "grsdummy";
|
||||
const STATS_DATA = {
|
||||
@@ -26,6 +25,7 @@ const STATS_DATA = {
|
||||
score: 51.01013099671447,
|
||||
},
|
||||
};
|
||||
|
||||
const LANGS_DATA = {
|
||||
TypeScript: {
|
||||
color: "#3178c6",
|
||||
@@ -48,6 +48,7 @@ const LANGS_DATA = {
|
||||
size: 671,
|
||||
},
|
||||
};
|
||||
|
||||
const WAKATIME_DATA = {
|
||||
human_readable_range: "last week",
|
||||
is_already_updating: false,
|
||||
@@ -64,6 +65,7 @@ const WAKATIME_DATA = {
|
||||
username: "grsdummy",
|
||||
writes_only: false,
|
||||
};
|
||||
|
||||
const REPOSITORY_DATA = {
|
||||
name: "dummy-cra",
|
||||
nameWithOwner: "grsdummy/dummy-cra",
|
||||
@@ -83,6 +85,8 @@ const REPOSITORY_DATA = {
|
||||
starCount: 1,
|
||||
};
|
||||
|
||||
const CACHE_BURST_STRING = `v=${new Date().getTime()}`;
|
||||
|
||||
describe("Fetch Cards", () => {
|
||||
let VERCEL_PREVIEW_URL;
|
||||
|
||||
@@ -104,19 +108,24 @@ describe("Fetch Cards", () => {
|
||||
|
||||
// Get the Vercel preview stats card response.
|
||||
const serverStatsSvg = await axios.get(
|
||||
`${VERCEL_PREVIEW_URL}/api?username=${USER}`,
|
||||
`${VERCEL_PREVIEW_URL}/api?username=${USER}&${CACHE_BURST_STRING}`,
|
||||
);
|
||||
|
||||
// Check if stats card from deployment matches the stats card from local.
|
||||
expect(serverStatsSvg.data).toEqual(localStatsCardSVG);
|
||||
});
|
||||
}, 7000);
|
||||
|
||||
test("retrieve language card", async () => {
|
||||
expect(VERCEL_PREVIEW_URL).toBeDefined();
|
||||
|
||||
// Check if the Vercel preview instance language card function is up and running.
|
||||
console.log(
|
||||
`${VERCEL_PREVIEW_URL}/api/top-langs/?username=${USER}&${CACHE_BURST_STRING}`,
|
||||
);
|
||||
await expect(
|
||||
axios.get(`${VERCEL_PREVIEW_URL}/api/top-langs/?username=${USER}`),
|
||||
axios.get(
|
||||
`${VERCEL_PREVIEW_URL}/api/top-langs/?username=${USER}&${CACHE_BURST_STRING}`,
|
||||
),
|
||||
).resolves.not.toThrow();
|
||||
|
||||
// Get local language card.
|
||||
@@ -124,7 +133,7 @@ describe("Fetch Cards", () => {
|
||||
|
||||
// Get the Vercel preview language card response.
|
||||
const severLanguageSVG = await axios.get(
|
||||
`${VERCEL_PREVIEW_URL}/api/top-langs/?username=${USER}`,
|
||||
`${VERCEL_PREVIEW_URL}/api/top-langs/?username=${USER}&${CACHE_BURST_STRING}`,
|
||||
);
|
||||
|
||||
// Check if language card from deployment matches the local language card.
|
||||
@@ -144,7 +153,7 @@ describe("Fetch Cards", () => {
|
||||
|
||||
// Get the Vercel preview WakaTime card response.
|
||||
const serverWakaTimeSvg = await axios.get(
|
||||
`${VERCEL_PREVIEW_URL}/api/wakatime?username=${USER}`,
|
||||
`${VERCEL_PREVIEW_URL}/api/wakatime?username=${USER}&${CACHE_BURST_STRING}`,
|
||||
);
|
||||
|
||||
// Check if WakaTime card from deployment matches the local WakaTime card.
|
||||
@@ -156,7 +165,9 @@ describe("Fetch Cards", () => {
|
||||
|
||||
// Check if the Vercel preview instance Repo function is up and running.
|
||||
await expect(
|
||||
axios.get(`${VERCEL_PREVIEW_URL}/api/pin/?username=${USER}&repo=${REPO}`),
|
||||
axios.get(
|
||||
`${VERCEL_PREVIEW_URL}/api/pin/?username=${USER}&repo=${REPO}&${CACHE_BURST_STRING}`,
|
||||
),
|
||||
).resolves.not.toThrow();
|
||||
|
||||
// Get local repo card.
|
||||
@@ -164,7 +175,7 @@ describe("Fetch Cards", () => {
|
||||
|
||||
// Get the Vercel preview repo card response.
|
||||
const serverRepoSvg = await axios.get(
|
||||
`${VERCEL_PREVIEW_URL}/api/pin/?username=${USER}&repo=${REPO}`,
|
||||
`${VERCEL_PREVIEW_URL}/api/pin/?username=${USER}&repo=${REPO}&${CACHE_BURST_STRING}`,
|
||||
);
|
||||
|
||||
// Check if Repo card from deployment matches the local Repo card.
|
||||
|
||||
@@ -23,6 +23,7 @@ const data_user = {
|
||||
organization: null,
|
||||
},
|
||||
};
|
||||
|
||||
const data_org = {
|
||||
data: {
|
||||
user: null,
|
||||
|
||||
+19
-11
@@ -97,9 +97,9 @@ beforeEach(() => {
|
||||
.onPost("https://api.github.com/graphql")
|
||||
.replyOnce(200, data)
|
||||
.onPost("https://api.github.com/graphql")
|
||||
.replyOnce(200, firstRepositoriesData)
|
||||
.onPost("https://api.github.com/graphql")
|
||||
.replyOnce(200, secondRepositoriesData);
|
||||
.replyOnce(200, firstRepositoriesData);
|
||||
// .onPost("https://api.github.com/graphql") // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
// .replyOnce(200, secondRepositoriesData); // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -114,7 +114,8 @@ describe("Test fetchStats", () => {
|
||||
totalRepos: 5,
|
||||
followers: 100,
|
||||
contributions: 61,
|
||||
stargazers: 400,
|
||||
// stargazers: 400, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
stargazers: 300, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
prs: 300,
|
||||
issues: 200,
|
||||
});
|
||||
@@ -125,7 +126,8 @@ describe("Test fetchStats", () => {
|
||||
totalCommits: 100,
|
||||
totalIssues: 200,
|
||||
totalPRs: 300,
|
||||
totalStars: 400,
|
||||
// totalStars: 400, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
totalStars: 300, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
rank,
|
||||
});
|
||||
});
|
||||
@@ -176,7 +178,8 @@ describe("Test fetchStats", () => {
|
||||
totalRepos: 5,
|
||||
followers: 100,
|
||||
contributions: 61,
|
||||
stargazers: 400,
|
||||
// stargazers: 400, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
stargazers: 300, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
prs: 300,
|
||||
issues: 200,
|
||||
});
|
||||
@@ -187,7 +190,8 @@ describe("Test fetchStats", () => {
|
||||
totalCommits: 150,
|
||||
totalIssues: 200,
|
||||
totalPRs: 300,
|
||||
totalStars: 400,
|
||||
// totalStars: 400, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
totalStars: 300, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
rank,
|
||||
});
|
||||
});
|
||||
@@ -203,7 +207,8 @@ describe("Test fetchStats", () => {
|
||||
totalRepos: 5,
|
||||
followers: 100,
|
||||
contributions: 61,
|
||||
stargazers: 400,
|
||||
// stargazers: 400, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
stargazers: 300, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
prs: 300,
|
||||
issues: 200,
|
||||
});
|
||||
@@ -214,7 +219,8 @@ describe("Test fetchStats", () => {
|
||||
totalCommits: 1050,
|
||||
totalIssues: 200,
|
||||
totalPRs: 300,
|
||||
totalStars: 400,
|
||||
// totalStars: 400, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
totalStars: 300, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
rank,
|
||||
});
|
||||
});
|
||||
@@ -230,7 +236,8 @@ describe("Test fetchStats", () => {
|
||||
totalRepos: 5,
|
||||
followers: 100,
|
||||
contributions: 61,
|
||||
stargazers: 300,
|
||||
// stargazers: 300, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
stargazers: 200, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
prs: 300,
|
||||
issues: 200,
|
||||
});
|
||||
@@ -241,7 +248,8 @@ describe("Test fetchStats", () => {
|
||||
totalCommits: 1050,
|
||||
totalIssues: 200,
|
||||
totalPRs: 300,
|
||||
totalStars: 300,
|
||||
// totalStars: 300, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
totalStars: 200, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
|
||||
rank,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,17 +10,17 @@ import "@testing-library/jest-dom";
|
||||
|
||||
import { themes } from "../themes/index.js";
|
||||
|
||||
describe("Test renderStatsCard", () => {
|
||||
const stats = {
|
||||
name: "Anurag Hazra",
|
||||
totalStars: 100,
|
||||
totalCommits: 200,
|
||||
totalIssues: 300,
|
||||
totalPRs: 400,
|
||||
contributedTo: 500,
|
||||
rank: { level: "A+", score: 40 },
|
||||
};
|
||||
const stats = {
|
||||
name: "Anurag Hazra",
|
||||
totalStars: 100,
|
||||
totalCommits: 200,
|
||||
totalIssues: 300,
|
||||
totalPRs: 400,
|
||||
contributedTo: 500,
|
||||
rank: { level: "A+", score: 40 },
|
||||
};
|
||||
|
||||
describe("Test renderStatsCard", () => {
|
||||
it("should render correctly", () => {
|
||||
document.body.innerHTML = renderStatsCard(stats);
|
||||
|
||||
|
||||
@@ -9,25 +9,25 @@ import "@testing-library/jest-dom";
|
||||
|
||||
import { themes } from "../themes/index.js";
|
||||
|
||||
describe("Test renderTopLanguages", () => {
|
||||
const langs = {
|
||||
HTML: {
|
||||
color: "#0f0",
|
||||
name: "HTML",
|
||||
size: 200,
|
||||
},
|
||||
javascript: {
|
||||
color: "#0ff",
|
||||
name: "javascript",
|
||||
size: 200,
|
||||
},
|
||||
css: {
|
||||
color: "#ff0",
|
||||
name: "css",
|
||||
size: 100,
|
||||
},
|
||||
};
|
||||
const langs = {
|
||||
HTML: {
|
||||
color: "#0f0",
|
||||
name: "HTML",
|
||||
size: 200,
|
||||
},
|
||||
javascript: {
|
||||
color: "#0ff",
|
||||
name: "javascript",
|
||||
size: 200,
|
||||
},
|
||||
css: {
|
||||
color: "#ff0",
|
||||
name: "css",
|
||||
size: 100,
|
||||
},
|
||||
};
|
||||
|
||||
describe("Test renderTopLanguages", () => {
|
||||
it("should render correctly", () => {
|
||||
document.body.innerHTML = renderTopLanguages(langs);
|
||||
|
||||
|
||||
+152
-22
@@ -1,30 +1,25 @@
|
||||
import { queryByTestId } from "@testing-library/dom";
|
||||
import "@testing-library/jest-dom";
|
||||
import {
|
||||
chunkArray,
|
||||
clampValue,
|
||||
encodeHTML,
|
||||
fallbackColor,
|
||||
flexLayout,
|
||||
getCardColors,
|
||||
isValidGradient,
|
||||
isValidHexColor,
|
||||
kFormatter,
|
||||
lowercaseTrim,
|
||||
measureText,
|
||||
parseArray,
|
||||
parseBoolean,
|
||||
parseEmojis,
|
||||
renderError,
|
||||
wrapTextMultiline,
|
||||
} from "../src/common/utils.js";
|
||||
|
||||
describe("Test utils.js", () => {
|
||||
it("should test kFormatter", () => {
|
||||
expect(kFormatter(1)).toBe(1);
|
||||
expect(kFormatter(-1)).toBe(-1);
|
||||
expect(kFormatter(500)).toBe(500);
|
||||
expect(kFormatter(1000)).toBe("1k");
|
||||
expect(kFormatter(10000)).toBe("10k");
|
||||
expect(kFormatter(12345)).toBe("12.3k");
|
||||
expect(kFormatter(9900000)).toBe("9900k");
|
||||
});
|
||||
|
||||
it("should test encodeHTML", () => {
|
||||
expect(encodeHTML(`<html>hello world<,.#4^&^@%!))`)).toBe(
|
||||
"<html>hello world<,.#4^&^@%!))",
|
||||
);
|
||||
});
|
||||
|
||||
it("should test renderError", () => {
|
||||
document.body.innerHTML = renderError("Something went wrong");
|
||||
expect(
|
||||
@@ -44,6 +39,111 @@ describe("Test utils.js", () => {
|
||||
).toHaveTextContent(/Secondary Message/gim);
|
||||
});
|
||||
|
||||
it("should test encodeHTML", () => {
|
||||
expect(encodeHTML(`<html>hello world<,.#4^&^@%!))`)).toBe(
|
||||
"<html>hello world<,.#4^&^@%!))",
|
||||
);
|
||||
});
|
||||
|
||||
it("should test kFormatter", () => {
|
||||
expect(kFormatter(1)).toBe(1);
|
||||
expect(kFormatter(-1)).toBe(-1);
|
||||
expect(kFormatter(500)).toBe(500);
|
||||
expect(kFormatter(1000)).toBe("1k");
|
||||
expect(kFormatter(10000)).toBe("10k");
|
||||
expect(kFormatter(12345)).toBe("12.3k");
|
||||
expect(kFormatter(9900000)).toBe("9900k");
|
||||
});
|
||||
|
||||
it("should test isValidHexColor", () => {
|
||||
expect(isValidHexColor("00f000")).toBe(true);
|
||||
expect(isValidHexColor("00f0003f")).toBe(true);
|
||||
expect(isValidHexColor("0f03")).toBe(true);
|
||||
expect(isValidHexColor("0f0")).toBe(true);
|
||||
|
||||
expect(isValidHexColor("00f00X")).toBe(false);
|
||||
expect(isValidHexColor("#")).toBe(false);
|
||||
expect(isValidHexColor("")).toBe(false);
|
||||
expect(isValidHexColor("0")).toBe(false);
|
||||
expect(isValidHexColor("00")).toBe(false);
|
||||
expect(isValidHexColor("00f00")).toBe(false);
|
||||
expect(isValidHexColor("00f00")).toBe(false);
|
||||
});
|
||||
|
||||
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(undefined)).toBe(undefined);
|
||||
});
|
||||
|
||||
it("should test parseArray", () => {
|
||||
expect(parseArray("1")).toEqual(["1"]);
|
||||
expect(parseArray("1,2,3")).toEqual(["1", "2", "3"]);
|
||||
expect(parseArray("test")).toEqual(["test"]);
|
||||
});
|
||||
|
||||
it("should test clampValue", () => {
|
||||
expect(clampValue(1, 0, 2)).toBe(1);
|
||||
expect(clampValue(1, 2, 3)).toBe(2);
|
||||
expect(clampValue(1, 0, 0)).toBe(0);
|
||||
expect(clampValue(1, 0, -1)).toBe(0);
|
||||
});
|
||||
|
||||
it("should test isValidGradient", () => {
|
||||
expect(isValidGradient(["90", "fff", "000"])).toBe(true);
|
||||
expect(isValidGradient(["90", "fff", "000", "fff"])).toBe(true);
|
||||
|
||||
expect(isValidGradient(["fff", "fff", "fxf"])).toBe(false);
|
||||
expect(isValidGradient(["90", "fff", "fxf"])).toBe(false);
|
||||
expect(isValidGradient(["90", "fxf", ""])).toBe(false);
|
||||
});
|
||||
|
||||
it("should test fallbackColor", () => {
|
||||
expect(fallbackColor("fff", "000")).toBe("#fff");
|
||||
expect(fallbackColor("fxf", "#000")).toBe("#000");
|
||||
expect(fallbackColor("90,fff,000", "#000")).toStrictEqual([
|
||||
"90",
|
||||
"fff",
|
||||
"000",
|
||||
]);
|
||||
expect(fallbackColor("90,fff,fxf", "#000")).toBe("#000");
|
||||
});
|
||||
|
||||
it("should test flexLayout", () => {
|
||||
const items = Array(2).fill(`<g></g>`);
|
||||
|
||||
const columnLayout = flexLayout({
|
||||
items,
|
||||
gap: 25,
|
||||
direction: "column",
|
||||
sizes: [],
|
||||
});
|
||||
expect(columnLayout[0]).toContain("translate(0, 0)");
|
||||
expect(columnLayout[1]).toContain("translate(0, 25)");
|
||||
|
||||
const rowLayout = flexLayout({
|
||||
items,
|
||||
gap: 25,
|
||||
direction: "row",
|
||||
sizes: [],
|
||||
});
|
||||
expect(rowLayout[0]).toContain("translate(0, 0)");
|
||||
expect(rowLayout[1]).toContain("translate(25, 0)");
|
||||
|
||||
const sizedLayout = flexLayout({
|
||||
items,
|
||||
gap: 25,
|
||||
direction: "row",
|
||||
sizes: [25, 0],
|
||||
});
|
||||
expect(sizedLayout[0]).toContain("translate(0, 0)");
|
||||
expect(sizedLayout[1]).toContain("translate(50, 0)");
|
||||
});
|
||||
|
||||
it("getCardColors: should return expected values", () => {
|
||||
let colors = getCardColors({
|
||||
title_color: "f00",
|
||||
@@ -92,16 +192,15 @@ describe("Test utils.js", () => {
|
||||
borderColor: "#e4e2e2",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("wrapTextMultiline", () => {
|
||||
it("should not wrap small texts", () => {
|
||||
it("wrapTextMultiline: should not wrap small texts", () => {
|
||||
{
|
||||
let multiLineText = wrapTextMultiline("Small text should not wrap");
|
||||
expect(multiLineText).toEqual(["Small text should not wrap"]);
|
||||
}
|
||||
});
|
||||
it("should wrap large texts", () => {
|
||||
|
||||
it("wrapTextMultiline: should wrap large texts", () => {
|
||||
let multiLineText = wrapTextMultiline(
|
||||
"Hello world long long long text",
|
||||
20,
|
||||
@@ -109,7 +208,8 @@ describe("wrapTextMultiline", () => {
|
||||
);
|
||||
expect(multiLineText).toEqual(["Hello world long", "long long text"]);
|
||||
});
|
||||
it("should wrap large texts and limit max lines", () => {
|
||||
|
||||
it("wrapTextMultiline: should wrap large texts and limit max lines", () => {
|
||||
let multiLineText = wrapTextMultiline(
|
||||
"Hello world long long long text",
|
||||
10,
|
||||
@@ -117,11 +217,41 @@ describe("wrapTextMultiline", () => {
|
||||
);
|
||||
expect(multiLineText).toEqual(["Hello", "world long..."]);
|
||||
});
|
||||
it("should wrap chinese by punctuation", () => {
|
||||
|
||||
it("wrapTextMultiline: should wrap chinese by punctuation", () => {
|
||||
let multiLineText = wrapTextMultiline(
|
||||
"专门为刚开始刷题的同学准备的算法基地,没有最细只有更细,立志用动画将晦涩难懂的算法说的通俗易懂!",
|
||||
);
|
||||
expect(multiLineText.length).toEqual(3);
|
||||
expect(multiLineText[0].length).toEqual(18 * 8); // &#xxxxx; x 8
|
||||
});
|
||||
|
||||
it("should test measureText", () => {
|
||||
expect(measureText("test")).toEqual(16.078125);
|
||||
|
||||
expect(measureText("test", 12)).toEqual(19.293750000000003);
|
||||
});
|
||||
|
||||
it("should test lowercaseTrim", () => {
|
||||
expect(lowercaseTrim("test")).toEqual("test");
|
||||
expect(lowercaseTrim(" test ")).toEqual("test");
|
||||
expect(lowercaseTrim(" Test ")).toEqual("test");
|
||||
});
|
||||
|
||||
it("should test chunkArray", () => {
|
||||
expect(chunkArray([1, 2, 3], 1)).toEqual([[1], [2], [3]]);
|
||||
expect(chunkArray([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);
|
||||
expect(chunkArray([1, 2, 3, 4, 5, 6, 7], 3)).toEqual([
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7],
|
||||
]);
|
||||
});
|
||||
|
||||
it("should test parseEmojis", () => {
|
||||
expect(parseEmojis("test")).toEqual("test");
|
||||
expect(parseEmojis("test :smile:")).toEqual("test 😄");
|
||||
expect(parseEmojis("test :smile: :+1:")).toEqual("test 😄 👍");
|
||||
expect(parseEmojis("test :smile: :+1: :smile:")).toEqual("test 😄 👍 😄");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user