forked from anuraghazra/github-readme-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'anuraghazra:master' into master
- Loading branch information
Showing
59 changed files
with
2,913 additions
and
671 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ vercel_token | |
# IDE | ||
.vscode | ||
*.code-workspace | ||
|
||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
Oops, something went wrong.
6714de2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
github-readme-stats – ./
github-readme-stats-zhangyijia.vercel.app
github-readme-stats-miku-o.vercel.app
github-readme-stats-git-master-zhangyijia.vercel.app