Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from anuraghazra:master #2

Merged
merged 82 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
077d405
feat: add PAT monitoring functions (#2178)
rickstaa Jan 28, 2023
7aa502d
chore: minor changes in pat info (#2481)
anuraghazra Jan 28, 2023
1120006
ci: add update languages action (#2484)
rickstaa Jan 29, 2023
888663a
Add `rose` theme (#2480)
Meezzi Feb 14, 2023
ba7c2f8
Support hide_progress for top-langs feature (#2514)
amirhakimnejad Feb 16, 2023
5f20e6c
add holi_theme (#2539)
mohamedhassan279 Feb 25, 2023
a6ff0fa
Add one_dark_pro (#2507)
b3dyk Feb 25, 2023
f3f7a48
fix: fix JSON themes bug. (#2544)
catelinemnemosyne Feb 25, 2023
55a303b
Add auto-labelling for documentation updates (#2526)
Zo-Bro-23 Feb 25, 2023
91345ed
ci: fix unsafe directory bug (#2518)
rickstaa Feb 25, 2023
8898d01
Update readme.md (#2414)
raphaelricardo10 Feb 25, 2023
a3c6f87
test: update snapshots (#2519)
rickstaa Feb 25, 2023
2ab8b85
fix: for issue #2534 (#2536)
md-rehman Feb 25, 2023
1d528da
Add option to deploy using other services (#2525)
Zo-Bro-23 Feb 25, 2023
82224fa
ci: update e2e tests (#2548)
rickstaa Feb 25, 2023
d5fbfb4
ci: fix a bug in the theme preview action (#2549)
rickstaa Feb 25, 2023
252c2b4
refactor: format code (#2550)
rickstaa Feb 26, 2023
d60d53c
refactor: update languages JSON (#2554)
github-actions[bot] Mar 1, 2023
8849b5f
Preview theme workflow fix (#2557)
Zo-Bro-23 Mar 1, 2023
a1c3c6a
ci: preview theme workflow fix (#2559)
Zo-Bro-23 Mar 1, 2023
9ec2c83
refactor: fix code comments and change 'up' rate limit (#2560)
rickstaa Mar 2, 2023
7bc8f19
Preview action fix (#2561)
Zo-Bro-23 Mar 2, 2023
9767710
ci: fix theme preview action (#2563)
rickstaa Mar 3, 2023
1e61f9f
fix theme preview (#2564)
rickstaa Mar 3, 2023
ed18914
ci: fixes theme preview action (#2566)
rickstaa Mar 5, 2023
b93aee3
ci: improve theme preview action (#2572)
rickstaa Mar 6, 2023
c5063b9
Added "Shadow" set (Red, Green, Blue, transparent BG) (#2529)
Etanarvazac Mar 8, 2023
2bd9d45
ci: fix theme docs generate bug (#2573)
rickstaa Mar 9, 2023
3299829
update my theme (#2576)
eduardozaniboni Mar 14, 2023
b928f51
refactor: update languages JSON (#2596)
github-actions[bot] Mar 31, 2023
d8244a7
Add format stats option (#2155)
CaedenPH Apr 1, 2023
4d1d83d
add github_dark_dimmed theme (#2594)
fabianocouto Apr 1, 2023
879937c
feat(RankIcon): add rank_icon option (#2628)
fabianocouto Apr 24, 2023
aec73d2
Updated the custom error there was a Typo. (#2618)
LokeshXs Apr 24, 2023
be0d966
Fix typos inside wakatime test name (#2617)
qwerty541 Apr 24, 2023
da5f82f
removed redundant comparison (#957)
qwerty541 Apr 25, 2023
8aacec0
dev (#1782)
qwerty541 Apr 25, 2023
21a9ba4
fix path to powered by vercel image (#1792)
qwerty541 Apr 25, 2023
da46a50
Synchonize cache seconds min value inside docs translations with main…
qwerty541 Apr 25, 2023
5577bbf
New top language algorithm implementation (#1732)
kitswas Apr 25, 2023
f5f0a79
feat: improve CONTRIBUTING.md (#2609)
rickstaa Apr 28, 2023
fd64333
docs: update give logo (#2605)
rickstaa Apr 28, 2023
30a45d3
Fixed typo in word color inside README (#2652)
qwerty541 Apr 28, 2023
6eebfe3
Fixed docs typo inside src/common/utils.js (#2651)
qwerty541 Apr 28, 2023
a82a617
Fixed several typos inside preview theme script (#2650)
qwerty541 Apr 28, 2023
31d1ab4
Fixed todo inside stats card data fetcher (#2649)
qwerty541 Apr 28, 2023
3bd6519
docs: fix README language card usage order (#2659)
rickstaa Apr 29, 2023
2f4279e
Fixed vscode type error in get card colors function (#2660)
qwerty541 Apr 30, 2023
cb99414
Show no activity error in compact layout of wakatime card (#2662)
qwerty541 May 1, 2023
a4d6fe1
Fixed card constructor docstring to resolve vscode type errors (#2674)
qwerty541 May 3, 2023
0dc3531
Fixed wakatime create text node func docstring to resolve vscode type…
qwerty541 May 4, 2023
311204f
Fixed docstring for several wakatime card gen functions to resolve mu…
qwerty541 May 5, 2023
c6dab8b
Fixed docstring for stats card create text node function to resolve t…
qwerty541 May 5, 2023
c656f3d
Update codecov action version to resolve github action deprecation wa…
qwerty541 May 5, 2023
d306bec
Add PRs cache cleaning workflow (#2661)
qwerty541 May 5, 2023
2619c12
build(deps): bump yaml from 2.1.3 to 2.2.2 (#2644)
dependabot[bot] May 5, 2023
a340900
fix(wakatime-fetcher): add default range to prevent user not found er…
fabianocouto May 5, 2023
0c2fe4e
Cover with test changes in #2662 pull request (#2673)
qwerty541 May 6, 2023
0caa4c5
test: fix mistaken pageInfo.endCursor keys (#2657)
Rongronggg9 May 6, 2023
688f4e4
docs: update wakatime user (#2697)
rickstaa May 6, 2023
6f449a1
Fixed docstring for get styles function to resolve vscode type errors…
qwerty541 May 7, 2023
15436e2
Fixed axios imports inside docstrings to resolve vscode type errors (…
qwerty541 May 7, 2023
ce116e2
Fixed typos inside bug report issue template (#2706)
qwerty541 May 8, 2023
550b88c
Update wakatime user inside docs translations (#2705)
qwerty541 May 8, 2023
8ff5a3b
Fixed docstring for create language text node function (#2704)
qwerty541 May 8, 2023
daa1977
Fixed docstring for wakatime card recalculate percentages function (#…
qwerty541 May 9, 2023
c5e7f7b
add pie chart layout to language card (#2099)
arndom May 9, 2023
4b19453
Fixed docstring for create donut language node function (#2713)
qwerty541 May 10, 2023
1f4a2c4
Add missing argument to create compact lang node function to resolve …
qwerty541 May 11, 2023
ff9839b
Top languages card pie layout (#2709)
qwerty541 May 11, 2023
d59a805
Docs: add missing top languages card layouts. (#2717)
qwerty541 May 13, 2023
6d45f89
Top languages card render test: move repeated code into helper functi…
qwerty541 May 13, 2023
7ec1a76
Docs (translations): add missing top languages card layouts. (#2728)
qwerty541 May 17, 2023
f9427b2
Top languages card donut vertical layout (#2701)
qwerty541 May 19, 2023
c8d5eda
Docs (translations): add top languages card donut vertical layout (#2…
qwerty541 May 22, 2023
ff2e02b
Docs: fix top languages card available layouts number (#2738)
qwerty541 May 22, 2023
c96e84a
Ranking System v2 (#1186)
francois-rozet May 26, 2023
73b0a91
Improve ukrainian translation of langcard.title (#2756)
qwerty541 May 29, 2023
275c1fc
Show notice about no languages data instead of empty card (#2755)
qwerty541 May 29, 2023
e0b3d83
refactor: update languages JSON (#2760)
github-actions[bot] May 31, 2023
c301289
fix: Make WakaTime card compatible with new API (#2707)
rickstaa Jun 2, 2023
1a2a82c
test: add new ranking to e2e test (#2750)
rickstaa Jun 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ body:
required: true
- type: textarea
attributes:
label: Expected behaviour
label: Expected behavior
description:
A clear and concise description of what you expected to happen.
- type: textarea
Expand Down
1 change: 1 addition & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
themes: themes/index.js
doc-translation: docs/*
card-i18n: src/translations.js
documentation: readme.md
4 changes: 4 additions & 0 deletions .github/workflows/generate-theme-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: npm

# Fix the unsafe repo error which was introduced by the CVE-2022-24765 git patches.
- name: Fix unsafe repo error
run: git config --global --add safe.directory ${{ github.workspace }}

- name: npm install, generate readme
run: |
npm ci
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/prs-cache-clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: prs cache clean
on:
pull_request:
types:
- closed

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cleanup
run: |
gh extension install actions/gh-actions-cache

REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"

echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )

## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
npm run format:check

- name: Code Coverage
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
44 changes: 44 additions & 0 deletions .github/workflows/update-langs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Update supported languages
on:
schedule:
- cron: "0 0 */30 * *"

jobs:
updateLanguages:
if: github.repository == 'anuraghazra/github-readme-stats'
name: Update supported languages
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: npm

- name: Install dependencies
run: npm ci
env:
CI: true

- name: Run update-languages-json.js script
run: npm run generate-langs-json

- name: Create Pull Request if upstream language file is changed
uses: peter-evans/create-pull-request@v4
with:
commit-message: "refactor: update languages JSON"
branch: "update_langs/patch"
delete-branch: true
title: Update languages JSON
body:
"The
[update-langs](https://github.com/anuraghazra/github-readme-stats/actions/workflows/update-langs.yaml)
action found new/updated languages in the [upstream languages JSON
file](https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml)."
labels: "ci, lang-card"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ vercel_token
# IDE
.vscode
*.code-workspace

.vercel
20 changes: 12 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:

- Reporting an issue
- Discussing the current state of the code
- Submitting a fix
- Proposing new features
- Becoming a maintainer
- Reporting [an issue](https://github.com/anuraghazra/github-readme-stats/issues/new?assignees=&labels=bug&template=bug_report.yml).
- [Discussing](https://github.com/anuraghazra/github-readme-stats/discussions) the current state of the code.
- Submitting [a fix](https://github.com/anuraghazra/github-readme-stats/compare).
- Proposing [new features](https://github.com/anuraghazra/github-readme-stats/issues/new?assignees=&labels=enhancement&template=feature_request.yml).
- Becoming a maintainer.

## All Changes Happen Through Pull Requests

Expand All @@ -33,11 +33,15 @@ _(make sure you already have a [Vercel](https://vercel.com/) account)_
1. Install [Vercel CLI](https://vercel.com/download).
2. Fork the repository and clone the code to your local machine.
3. Run `npm install` in the repository root.
4. Run the command "vercel" in the root and follow the steps there.
4. Run the command `vercel` in the root and follow the steps there.
5. Open `vercel.json` and set the maxDuration to 10.
6. Create a `.env` file in the root of the directory.
7. In the .env file add a new variable named "PAT_1" with your [GitHub Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token).
8. Run the command "vercel dev" to start a development server at <https://localhost:3000>.
7. In the .env file add a new variable named `PAT_1` with your [GitHub Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token).
8. Run the command `vercel dev` to start a development server at <https://localhost:3000>.
9. The cards will then be available from this local endpoint (i.e. `https://localhost:3000/api?username=anuraghazra`).

> **Note**
> You can also debug any tests using the [VSCode Jest extension](https://marketplace.visualstudio.com/items?itemName=Orta.vscode-jest). For more information see https://github.com/jest-community/vscode-jest/issues/912.

## Themes Contribution

Expand Down
4 changes: 4 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export default async (req, res) => {
locale,
disable_animations,
border_radius,
number_format,
border_color,
rank_icon,
} = req.query;
res.setHeader("Content-Type", "image/svg+xml");

Expand Down Expand Up @@ -88,8 +90,10 @@ export default async (req, res) => {
custom_title,
border_radius,
border_color,
number_format,
locale: locale ? locale.toLowerCase() : null,
disable_animations: parseBoolean(disable_animations),
rank_icon,
}),
);
} catch (err) {
Expand Down
139 changes: 139 additions & 0 deletions api/status/pat-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* @file Contains a simple cloud function that can be used to check which PATs are no
* longer working. It returns a list of valid PATs, expired PATs and PATs with errors.
*
* @description This function is currently rate limited to 1 request per 5 minutes.
*/

import { logger, request, dateDiff } from "../../src/common/utils.js";
export const RATE_LIMIT_SECONDS = 60 * 5; // 1 request per 5 minutes

/**
* Simple uptime check fetcher for the PATs.
*
* @param {import('axios').AxiosRequestHeaders} variables
* @param {string} token
*/
const uptimeFetcher = (variables, token) => {
return request(
{
query: `
query {
rateLimit {
remaining
resetAt
},
}`,
variables,
},
{
Authorization: `bearer ${token}`,
},
);
};

const getAllPATs = () => {
return Object.keys(process.env).filter((key) => /PAT_\d*$/.exec(key));
};

/**
* Check whether any of the PATs is expired.
*/
const getPATInfo = async (fetcher, variables) => {
const details = {};
const PATs = getAllPATs();

for (const pat of PATs) {
try {
const response = await fetcher(variables, process.env[pat]);
const errors = response.data.errors;
const hasErrors = Boolean(errors);
const errorType = errors?.[0]?.type;
const isRateLimited =
(hasErrors && errorType === "RATE_LIMITED") ||
response.data.data?.rateLimit?.remaining === 0;

// Store PATs with errors.
if (hasErrors && errorType !== "RATE_LIMITED") {
details[pat] = {
status: "error",
error: {
type: errors[0].type,
message: errors[0].message,
},
};
continue;
} else if (isRateLimited) {
const date1 = new Date();
const date2 = new Date(response.data?.data?.rateLimit?.resetAt);
details[pat] = {
status: "exhausted",
remaining: 0,
resetIn: dateDiff(date2, date1) + " minutes",
};
} else {
details[pat] = {
status: "valid",
remaining: response.data.data.rateLimit.remaining,
};
}
} catch (err) {
// Store the PAT if it is expired.
const errorMessage = err.response?.data?.message?.toLowerCase();
if (errorMessage === "bad credentials") {
details[pat] = {
status: "expired",
};
} else if (errorMessage === "sorry. your account was suspended.") {
details[pat] = {
status: "suspended",
};
} else {
throw err;
}
}
}

const filterPATsByStatus = (status) => {
return Object.keys(details).filter((pat) => details[pat].status === status);
};

const sortedDetails = Object.keys(details)
.sort()
.reduce((obj, key) => {
obj[key] = details[key];
return obj;
}, {});

return {
validPATs: filterPATsByStatus("valid"),
expiredPATs: filterPATsByStatus("expired"),
exhaustedPATs: filterPATsByStatus("exhausted"),
suspendedPATs: filterPATsByStatus("suspended"),
errorPATs: filterPATsByStatus("error"),
details: sortedDetails,
};
};

/**
* Cloud function that returns information about the used PATs.
*/
export default async (_, res) => {
res.setHeader("Content-Type", "application/json");
try {
// Add header to prevent abuse.
const PATsInfo = await getPATInfo(uptimeFetcher, {});
if (PATsInfo) {
res.setHeader(
"Cache-Control",
`max-age=0, s-maxage=${RATE_LIMIT_SECONDS}`,
);
}
res.send(JSON.stringify(PATsInfo, null, 2));
} catch (err) {
// Throw error if something went wrong.
logger.error(err);
res.setHeader("Cache-Control", "no-store");
res.send("Something went wrong: " + err.message);
}
};
Loading