forked from mirrored/github-readme-stats
Compare commits
33
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a640b871c5 | ||
|
|
c5063b92b6 | ||
|
|
b93aee34d0 | ||
|
|
ed18914fa4 | ||
|
|
1e61f9f3fe | ||
|
|
976771080f | ||
|
|
7bc8f19a7f | ||
|
|
9ec2c8367a | ||
|
|
a1c3c6accc | ||
|
|
8849b5f5fc | ||
|
|
d60d53cdb4 | ||
|
|
252c2b419d | ||
|
|
d5fbfb4345 | ||
|
|
82224fa68a | ||
|
|
1d528da1dc | ||
|
|
2ab8b85ae3 | ||
|
|
a3c6f874af | ||
|
|
8898d013b6 | ||
|
|
91345ed55f | ||
|
|
55a303b4a6 | ||
|
|
f3f7a4837d | ||
|
|
a6ff0fa521 | ||
|
|
5f20e6c97a | ||
|
|
ba7c2f8b55 | ||
|
|
888663a477 | ||
|
|
112000667c | ||
|
|
7aa502d453 | ||
|
|
077d40561a | ||
|
|
99d9d3cde0 | ||
|
|
cd5cbcdb09 | ||
|
|
b2bf4fa487 | ||
|
|
4b17300126 | ||
|
|
a17fa1cf5d |
@@ -1,3 +1,4 @@
|
|||||||
themes: themes/index.js
|
themes: themes/index.js
|
||||||
doc-translation: docs/*
|
doc-translation: docs/*
|
||||||
card-i18n: src/translations.js
|
card-i18n: src/translations.js
|
||||||
|
documentation: readme.md
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
file = open('./vercel.json', 'r')
|
||||||
|
str = file.read()
|
||||||
|
file = open('./vercel.json', 'w')
|
||||||
|
|
||||||
|
str = str.replace('"maxDuration": 10', '"maxDuration": 30')
|
||||||
|
|
||||||
|
file.write(str)
|
||||||
|
file.close()
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
name: Deployment Prep
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
config:
|
||||||
|
if: github.repository == 'anuraghazra/github-readme-stats'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Deployment Prep
|
||||||
|
run: python ./.github/workflows/deploy-prep.py
|
||||||
|
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||||
|
with:
|
||||||
|
branch: vercel
|
||||||
|
create_branch: true
|
||||||
|
push_options: "--force"
|
||||||
@@ -5,6 +5,7 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
e2eTests:
|
e2eTests:
|
||||||
if:
|
if:
|
||||||
|
github.repository == 'anuraghazra/github-readme-stats' &&
|
||||||
github.event_name == 'deployment_status' &&
|
github.event_name == 'deployment_status' &&
|
||||||
github.event.deployment_status.state == 'success'
|
github.event.deployment_status.state == 'success'
|
||||||
name: Perform 2e2 tests
|
name: Perform 2e2 tests
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
closeEmptyIssuesAndTemplates:
|
closeEmptyIssuesAndTemplates:
|
||||||
|
if: github.repository == 'anuraghazra/github-readme-stats'
|
||||||
name: Close empty issues
|
name: Close empty issues
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ jobs:
|
|||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
cache: npm
|
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
|
- name: npm install, generate readme
|
||||||
run: |
|
run: |
|
||||||
npm ci
|
npm ci
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
triage:
|
triage:
|
||||||
|
if: github.repository == 'anuraghazra/github-readme-stats'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/labeler@v4
|
- uses: actions/labeler@v4
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
closeOldThemePrs:
|
closeOldThemePrs:
|
||||||
|
if: github.repository == 'anuraghazra/github-readme-stats'
|
||||||
name: Close stale 'invalid' theme PRs
|
name: Close stale 'invalid' theme PRs
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
showAndLabelTopIssues:
|
showAndLabelTopIssues:
|
||||||
|
if: github.repository == 'anuraghazra/github-readme-stats'
|
||||||
name: Update top issues Dashboard.
|
name: Update top issues Dashboard.
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -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"
|
||||||
@@ -10,3 +10,5 @@ vercel_token
|
|||||||
# IDE
|
# IDE
|
||||||
.vscode
|
.vscode
|
||||||
*.code-workspace
|
*.code-workspace
|
||||||
|
|
||||||
|
.vercel
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
/**
|
||||||
|
* @file Contains a simple cloud function that can be used to check if the PATs are still
|
||||||
|
* functional.
|
||||||
|
*
|
||||||
|
* @description This function is currently rate limited to 1 request per 5 minutes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import retryer from "../../src/common/retryer.js";
|
||||||
|
import { logger, request } 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
variables,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Authorization: `bearer ${token}`,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates Json response that can be used for shields.io dynamic card generation.
|
||||||
|
*
|
||||||
|
* @param {*} up Whether the PATs are up or not.
|
||||||
|
* @returns Dynamic shields.io JSON response object.
|
||||||
|
*
|
||||||
|
* @see https://shields.io/endpoint.
|
||||||
|
*/
|
||||||
|
const shieldsUptimeBadge = (up) => {
|
||||||
|
const schemaVersion = 1;
|
||||||
|
const isError = true;
|
||||||
|
const label = "Public Instance";
|
||||||
|
const message = up ? "up" : "down";
|
||||||
|
const color = up ? "brightgreen" : "red";
|
||||||
|
return {
|
||||||
|
schemaVersion,
|
||||||
|
label,
|
||||||
|
message,
|
||||||
|
color,
|
||||||
|
isError,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cloud function that returns whether the PATs are still functional.
|
||||||
|
*/
|
||||||
|
export default async (req, res) => {
|
||||||
|
let { type } = req.query;
|
||||||
|
type = type ? type.toLowerCase() : "boolean";
|
||||||
|
|
||||||
|
res.setHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
|
try {
|
||||||
|
let PATsValid = true;
|
||||||
|
try {
|
||||||
|
await retryer(uptimeFetcher, {});
|
||||||
|
} catch (err) {
|
||||||
|
PATsValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PATsValid) {
|
||||||
|
res.setHeader(
|
||||||
|
"Cache-Control",
|
||||||
|
`max-age=0, s-maxage=${RATE_LIMIT_SECONDS}`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
res.setHeader("Cache-Control", "no-store");
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case "shields":
|
||||||
|
res.send(shieldsUptimeBadge(PATsValid));
|
||||||
|
break;
|
||||||
|
case "json":
|
||||||
|
res.send({ up: PATsValid });
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.send(PATsValid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// Return fail boolean if something went wrong.
|
||||||
|
logger.error(err);
|
||||||
|
res.setHeader("Cache-Control", "no-store");
|
||||||
|
res.send("Something went wrong: " + err.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -30,6 +30,7 @@ export default async (req, res) => {
|
|||||||
border_radius,
|
border_radius,
|
||||||
border_color,
|
border_color,
|
||||||
disable_animations,
|
disable_animations,
|
||||||
|
hide_progress,
|
||||||
} = req.query;
|
} = req.query;
|
||||||
res.setHeader("Content-Type", "image/svg+xml");
|
res.setHeader("Content-Type", "image/svg+xml");
|
||||||
|
|
||||||
@@ -77,6 +78,7 @@ export default async (req, res) => {
|
|||||||
border_color,
|
border_color,
|
||||||
locale: locale ? locale.toLowerCase() : null,
|
locale: locale ? locale.toLowerCase() : null,
|
||||||
disable_animations: parseBoolean(disable_animations),
|
disable_animations: parseBoolean(disable_animations),
|
||||||
|
hide_progress: parseBoolean(hide_progress),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
import statsCard from "./api/index.js";
|
||||||
|
import repoCard from "./api/pin.js";
|
||||||
|
import langCard from "./api/top-langs.js";
|
||||||
|
import wakatimeCard from "./api/wakatime.js";
|
||||||
|
import express from "express";
|
||||||
|
import dotenv from "dotenv";
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
const app = express();
|
||||||
|
app.listen(process.env.port || 9000);
|
||||||
|
|
||||||
|
app.get("/", statsCard);
|
||||||
|
app.get("/pin", repoCard);
|
||||||
|
app.get("/top-langs", langCard);
|
||||||
|
app.get("/wakatime", wakatimeCard);
|
||||||
Generated
+1
-1
@@ -22,7 +22,7 @@
|
|||||||
"@testing-library/dom": "^8.17.1",
|
"@testing-library/dom": "^8.17.1",
|
||||||
"@testing-library/jest-dom": "^5.16.5",
|
"@testing-library/jest-dom": "^5.16.5",
|
||||||
"@uppercod/css-to-object": "^1.1.1",
|
"@uppercod/css-to-object": "^1.1.1",
|
||||||
"axios-mock-adapter": "^1.18.1",
|
"axios-mock-adapter": "^1.21.2",
|
||||||
"color-contrast-checker": "^2.1.0",
|
"color-contrast-checker": "^2.1.0",
|
||||||
"hjson": "^3.2.2",
|
"hjson": "^3.2.2",
|
||||||
"husky": "^8.0.0",
|
"husky": "^8.0.0",
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@
|
|||||||
"@testing-library/dom": "^8.17.1",
|
"@testing-library/dom": "^8.17.1",
|
||||||
"@testing-library/jest-dom": "^5.16.5",
|
"@testing-library/jest-dom": "^5.16.5",
|
||||||
"@uppercod/css-to-object": "^1.1.1",
|
"@uppercod/css-to-object": "^1.1.1",
|
||||||
"axios-mock-adapter": "^1.18.1",
|
"axios-mock-adapter": "^1.21.2",
|
||||||
"color-contrast-checker": "^2.1.0",
|
"color-contrast-checker": "^2.1.0",
|
||||||
"hjson": "^3.2.2",
|
"hjson": "^3.2.2",
|
||||||
"husky": "^8.0.0",
|
"husky": "^8.0.0",
|
||||||
|
|||||||
@@ -92,7 +92,9 @@ Visit <https://indiafightscorona.giveindia.org> and make a small donation to hel
|
|||||||
- [Repo Card Exclusive Options](#repo-card-exclusive-options)
|
- [Repo Card Exclusive Options](#repo-card-exclusive-options)
|
||||||
- [Language Card Exclusive Options](#language-card-exclusive-options)
|
- [Language Card Exclusive Options](#language-card-exclusive-options)
|
||||||
- [Wakatime Card Exclusive Option](#wakatime-card-exclusive-options)
|
- [Wakatime Card Exclusive Option](#wakatime-card-exclusive-options)
|
||||||
- [Deploy Yourself](#deploy-on-your-own-vercel-instance)
|
- [Deploy Yourself](#deploy-on-your-own)
|
||||||
|
- [On Vercel](#on-vercel)
|
||||||
|
- [On other platforms](#on-other-platforms)
|
||||||
- [Keep your fork up to date](#keep-your-fork-up-to-date)
|
- [Keep your fork up to date](#keep-your-fork-up-to-date)
|
||||||
|
|
||||||
# GitHub Stats Card
|
# GitHub Stats Card
|
||||||
@@ -133,7 +135,7 @@ You can add the count of all your private contributions to the total commits cou
|
|||||||
|
|
||||||
### Showing icons
|
### Showing icons
|
||||||
|
|
||||||
To enable icons, you can pass `show_icons=true` in the query param, like so:
|
To enable icons, you can pass `&show_icons=true` in the query param, like so:
|
||||||
|
|
||||||
```md
|
```md
|
||||||

|

|
||||||
@@ -305,6 +307,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)`.
|
- `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`.
|
- `custom_title` - Sets a custom title for the card _(string)_. Default `Most Used Languages`.
|
||||||
- `disable_animations` - Disables all animations in the card _(boolean)_. Default: `false`.
|
- `disable_animations` - Disables all animations in the card _(boolean)_. Default: `false`.
|
||||||
|
- `hide_progress` - It uses the compact layout option, hides percentages, and removes the bars. Default: `false`.
|
||||||
|
|
||||||
> **Warning**
|
> **Warning**
|
||||||
> Language names should be URI-escaped, as specified in [Percent Encoding](https://en.wikipedia.org/wiki/Percent-encoding)
|
> Language names should be URI-escaped, as specified in [Percent Encoding](https://en.wikipedia.org/wiki/Percent-encoding)
|
||||||
@@ -398,6 +401,14 @@ You can use the `&layout=compact` option to change the card design.
|
|||||||
[](https://github.com/anuraghazra/github-readme-stats)
|
[](https://github.com/anuraghazra/github-readme-stats)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Hide Progress Bars
|
||||||
|
|
||||||
|
You can use the `&hide_progress=true` option to hide the percentages and the progress bars (layout will be automatically set to `compact`).
|
||||||
|
|
||||||
|
```md
|
||||||
|
[](https://github.com/anuraghazra/github-readme-stats)
|
||||||
|
```
|
||||||
|
|
||||||
### Demo
|
### Demo
|
||||||
|
|
||||||
[](https://github.com/anuraghazra/github-readme-stats)
|
[](https://github.com/anuraghazra/github-readme-stats)
|
||||||
@@ -406,6 +417,10 @@ You can use the `&layout=compact` option to change the card design.
|
|||||||
|
|
||||||
[](https://github.com/anuraghazra/github-readme-stats)
|
[](https://github.com/anuraghazra/github-readme-stats)
|
||||||
|
|
||||||
|
- Hidden progress bars
|
||||||
|
|
||||||
|
[](https://github.com/anuraghazra/github-readme-stats)
|
||||||
|
|
||||||
# Wakatime Week Stats
|
# Wakatime Week Stats
|
||||||
|
|
||||||
Change the `?username=` value to your [Wakatime](https://wakatime.com) username.
|
Change the `?username=` value to your [Wakatime](https://wakatime.com) username.
|
||||||
@@ -496,7 +511,9 @@ By default, GitHub does not lay out the cards side by side. To do that, you can
|
|||||||
</a>
|
</a>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Deploy on your own Vercel instance
|
## Deploy on your own
|
||||||
|
|
||||||
|
### On Vercel
|
||||||
|
|
||||||
#### :film_projector: [Check Out Step By Step Video Tutorial By @codeSTACKr](https://youtu.be/n6d4KHSKqGk?t=107)
|
#### :film_projector: [Check Out Step By Step Video Tutorial By @codeSTACKr](https://youtu.be/n6d4KHSKqGk?t=107)
|
||||||
|
|
||||||
@@ -533,6 +550,23 @@ Since the GitHub API only allows 5k requests per hour, my `https://github-readme
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
### On other platforms
|
||||||
|
|
||||||
|
> **Warning**
|
||||||
|
> This way of using GRS is not officially supported and was added to cater to some particular use cases where Vercel could not be used (e.g. #2341). The support for this method, therefore, is limited.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>:hammer_and_wrench: Step-by-step guide for deploying on other platforms</b></summary>
|
||||||
|
|
||||||
|
1. Fork or clone this repo as per your needs
|
||||||
|
2. Add `express` to the dependencies section of `package.json`
|
||||||
|
https://github.com/anuraghazra/github-readme-stats/blob/ba7c2f8b55eac8452e479c8bd38b044d204d0424/package.json#L54-L61
|
||||||
|
3. Run `npm i` if needed (initial setup)
|
||||||
|
4. Run `node express.js` to start the server, or set the entry point to `express.js` in `package.json` if you're deploying on a managed service
|
||||||
|
https://github.com/anuraghazra/github-readme-stats/blob/ba7c2f8b55eac8452e479c8bd38b044d204d0424/package.json#L11
|
||||||
|
5. You're done 🎉
|
||||||
|
</details>
|
||||||
|
|
||||||
### Keep your fork up to date
|
### 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.
|
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.
|
||||||
|
|||||||
+128
-60
@@ -43,6 +43,23 @@ const ACCEPTED_COLOR_PROPS = Object.keys(COLOR_PROPS);
|
|||||||
const REQUIRED_COLOR_PROPS = ACCEPTED_COLOR_PROPS.slice(0, 4);
|
const REQUIRED_COLOR_PROPS = ACCEPTED_COLOR_PROPS.slice(0, 4);
|
||||||
const INVALID_REVIEW_COMMENT = (commentUrl) =>
|
const INVALID_REVIEW_COMMENT = (commentUrl) =>
|
||||||
`Some themes are invalid. See the [Automated Theme Preview](${commentUrl}) comment above for more information.`;
|
`Some themes are invalid. See the [Automated Theme Preview](${commentUrl}) comment above for more information.`;
|
||||||
|
var OCTOKIT;
|
||||||
|
var OWNER;
|
||||||
|
var REPO;
|
||||||
|
var PULL_REQUEST_ID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Incorrect JSON format error.
|
||||||
|
* @extends Error
|
||||||
|
* @param {string} message Error message.
|
||||||
|
* @returns {Error} IncorrectJsonFormatError.
|
||||||
|
*/
|
||||||
|
class IncorrectJsonFormatError extends Error {
|
||||||
|
constructor(message) {
|
||||||
|
super(message);
|
||||||
|
this.name = "IncorrectJsonFormatError";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve PR number from the event payload.
|
* Retrieve PR number from the event payload.
|
||||||
@@ -126,15 +143,36 @@ const findComment = async (octokit, issueNumber, owner, repo, commenter) => {
|
|||||||
* Create or update the preview comment.
|
* Create or update the preview comment.
|
||||||
*
|
*
|
||||||
* @param {Object} octokit Octokit instance.
|
* @param {Object} octokit Octokit instance.
|
||||||
* @param {Object} props Comment properties.
|
* @param {number} issueNumber Issue number.
|
||||||
|
* @param {Object} repo Repository name.
|
||||||
|
* @param {Object} owner Owner of the repository.
|
||||||
|
* @param {number} commentId Comment ID.
|
||||||
|
* @param {string} body Comment body.
|
||||||
* @return {string} The comment URL.
|
* @return {string} The comment URL.
|
||||||
*/
|
*/
|
||||||
const upsertComment = async (octokit, props) => {
|
const upsertComment = async (
|
||||||
|
octokit,
|
||||||
|
issueNumber,
|
||||||
|
repo,
|
||||||
|
owner,
|
||||||
|
commentId,
|
||||||
|
body,
|
||||||
|
) => {
|
||||||
let resp;
|
let resp;
|
||||||
if (props.comment_id !== undefined) {
|
if (commentId !== undefined) {
|
||||||
resp = await octokit.issues.updateComment(props);
|
resp = await octokit.issues.updateComment({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
comment_id: commentId,
|
||||||
|
body,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
resp = await octokit.issues.createComment(props);
|
resp = await octokit.issues.createComment({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
issue_number: issueNumber,
|
||||||
|
body,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return resp.data.html_url;
|
return resp.data.html_url;
|
||||||
};
|
};
|
||||||
@@ -269,22 +307,38 @@ const parseJSON = (json) => {
|
|||||||
if (typeof parsedJson === "object") {
|
if (typeof parsedJson === "object") {
|
||||||
return parsedJson;
|
return parsedJson;
|
||||||
} else {
|
} else {
|
||||||
throw new Error("PR diff is not a valid theme JSON object.");
|
throw new IncorrectJsonFormatError(
|
||||||
|
"PR diff is not a valid theme JSON object.",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
let parsedJson = json
|
// Remove trailing commas (if any).
|
||||||
|
let parsedJson = json.replace(/(,\s*})/g, "}");
|
||||||
|
|
||||||
|
// Remove JS comments (if any).
|
||||||
|
parsedJson = parsedJson.replace(/\/\/[A-z\s]*\s/g, "");
|
||||||
|
|
||||||
|
// Fix incorrect open bracket (if any).
|
||||||
|
const splitJson = parsedJson
|
||||||
.split(/([\s\r\s]*}[\s\r\s]*,[\s\r\s]*)(?=[\w"-]+:)/)
|
.split(/([\s\r\s]*}[\s\r\s]*,[\s\r\s]*)(?=[\w"-]+:)/)
|
||||||
.filter((x) => typeof x !== "string" || !!x.trim());
|
.filter((x) => typeof x !== "string" || !!x.trim()); // Split json into array of strings and objects.
|
||||||
if (parsedJson[0].replace(/\s+/g, "") === "},") {
|
if (splitJson[0].replace(/\s+/g, "") === "},") {
|
||||||
parsedJson[0] = "},";
|
splitJson[0] = "},";
|
||||||
if (!/\s*}\s*,?\s*$/.test(parsedJson[1])) {
|
if (!/\s*}\s*,?\s*$/.test(splitJson[1])) {
|
||||||
parsedJson.push(parsedJson.shift());
|
splitJson.push(splitJson.shift());
|
||||||
} else {
|
} else {
|
||||||
parsedJson.shift();
|
splitJson.shift();
|
||||||
}
|
}
|
||||||
return Hjson.parse(parsedJson.join(""));
|
parsedJson = splitJson.join("");
|
||||||
} else {
|
}
|
||||||
throw error;
|
|
||||||
|
// Try to parse the fixed json.
|
||||||
|
try {
|
||||||
|
return Hjson.parse(parsedJson);
|
||||||
|
} catch (error) {
|
||||||
|
throw new IncorrectJsonFormatError(
|
||||||
|
`Theme JSON file could not be parsed: ${error.message}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -298,12 +352,13 @@ const themeNameAlreadyExists = (name) => {
|
|||||||
return themes[name] !== undefined;
|
return themes[name] !== undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const DRY_RUN = process.env.DRY_RUN === "true" || false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main function.
|
* Main function.
|
||||||
*/
|
*/
|
||||||
export const run = async (prNumber) => {
|
export const run = async () => {
|
||||||
try {
|
try {
|
||||||
const dryRun = process.env.DRY_RUN === "true" || false;
|
|
||||||
debug("Retrieve action information from context...");
|
debug("Retrieve action information from context...");
|
||||||
debug(`Context: ${inspect(github.context)}`);
|
debug(`Context: ${inspect(github.context)}`);
|
||||||
let commentBody = `
|
let commentBody = `
|
||||||
@@ -311,40 +366,50 @@ export const run = async (prNumber) => {
|
|||||||
\r${THEME_CONTRIB_GUIDELINESS}
|
\r${THEME_CONTRIB_GUIDELINESS}
|
||||||
`;
|
`;
|
||||||
const ccc = new ColorContrastChecker();
|
const ccc = new ColorContrastChecker();
|
||||||
const octokit = github.getOctokit(getGithubToken());
|
OCTOKIT = github.getOctokit(getGithubToken());
|
||||||
const pullRequestId = prNumber ? prNumber : getPrNumber();
|
PULL_REQUEST_ID = getPrNumber();
|
||||||
const commenter = getCommenter();
|
|
||||||
const { owner, repo } = getRepoInfo(github.context);
|
const { owner, repo } = getRepoInfo(github.context);
|
||||||
debug(`Owner: ${owner}`);
|
OWNER = owner;
|
||||||
debug(`Repo: ${repo}`);
|
REPO = repo;
|
||||||
|
const commenter = getCommenter();
|
||||||
|
PULL_REQUEST_ID = getPrNumber();
|
||||||
|
debug(`Owner: ${OWNER}`);
|
||||||
|
debug(`Repo: ${REPO}`);
|
||||||
debug(`Commenter: ${commenter}`);
|
debug(`Commenter: ${commenter}`);
|
||||||
|
|
||||||
// Retrieve the PR diff and preview-theme comment.
|
// Retrieve the PR diff and preview-theme comment.
|
||||||
debug("Retrieve PR diff...");
|
debug("Retrieve PR diff...");
|
||||||
const res = await octokit.pulls.get({
|
const res = await OCTOKIT.pulls.get({
|
||||||
owner,
|
owner: OWNER,
|
||||||
repo,
|
repo: REPO,
|
||||||
pull_number: pullRequestId,
|
pull_number: PULL_REQUEST_ID,
|
||||||
mediaType: {
|
mediaType: {
|
||||||
format: "diff",
|
format: "diff",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
debug("Retrieve preview-theme comment...");
|
debug("Retrieve preview-theme comment...");
|
||||||
const comment = await findComment(
|
const comment = await findComment(
|
||||||
octokit,
|
OCTOKIT,
|
||||||
pullRequestId,
|
PULL_REQUEST_ID,
|
||||||
owner,
|
OWNER,
|
||||||
repo,
|
REPO,
|
||||||
commenter,
|
commenter,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Retrieve theme changes from the PR diff.
|
// Retrieve theme changes from the PR diff.
|
||||||
debug("Retrieve themes...");
|
debug("Retrieve themes...");
|
||||||
const diff = parse(res.data);
|
const diff = parse(res.data);
|
||||||
|
|
||||||
|
// Retrieve all theme changes from the PR diff and convert to JSON.
|
||||||
|
debug("Retrieve theme changes...");
|
||||||
const content = diff
|
const content = diff
|
||||||
.find((file) => file.to === "themes/index.js")
|
.find((file) => file.to === "themes/index.js")
|
||||||
.chunks[0].changes.filter((c) => c.type === "add")
|
.chunks.map((chunk) =>
|
||||||
.map((c) => c.content.replace("+", ""))
|
chunk.changes
|
||||||
|
.filter((c) => c.type === "add")
|
||||||
|
.map((c) => c.content.replace("+", ""))
|
||||||
|
.join(""),
|
||||||
|
)
|
||||||
.join("");
|
.join("");
|
||||||
const themeObject = parseJSON(content);
|
const themeObject = parseJSON(content);
|
||||||
if (
|
if (
|
||||||
@@ -513,14 +578,15 @@ export const run = async (prNumber) => {
|
|||||||
// Create or update theme-preview comment.
|
// Create or update theme-preview comment.
|
||||||
debug("Create or update theme-preview comment...");
|
debug("Create or update theme-preview comment...");
|
||||||
let comment_url;
|
let comment_url;
|
||||||
if (!dryRun) {
|
if (!DRY_RUN) {
|
||||||
comment_url = await upsertComment(octokit, {
|
comment_url = await upsertComment(
|
||||||
comment_id: comment?.id,
|
OCTOKIT,
|
||||||
issue_number: pullRequestId,
|
PULL_REQUEST_ID,
|
||||||
owner,
|
REPO,
|
||||||
repo,
|
OWNER,
|
||||||
body: commentBody,
|
comment?.id,
|
||||||
});
|
commentBody,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
info(`DRY_RUN: Comment body: ${commentBody}`);
|
info(`DRY_RUN: Comment body: ${commentBody}`);
|
||||||
comment_url = "";
|
comment_url = "";
|
||||||
@@ -535,20 +601,20 @@ export const run = async (prNumber) => {
|
|||||||
const reviewReason = themesValid
|
const reviewReason = themesValid
|
||||||
? undefined
|
? undefined
|
||||||
: INVALID_REVIEW_COMMENT(comment_url);
|
: INVALID_REVIEW_COMMENT(comment_url);
|
||||||
if (!dryRun) {
|
if (!DRY_RUN) {
|
||||||
await addReview(
|
await addReview(
|
||||||
octokit,
|
OCTOKIT,
|
||||||
pullRequestId,
|
PULL_REQUEST_ID,
|
||||||
owner,
|
OWNER,
|
||||||
repo,
|
REPO,
|
||||||
reviewState,
|
reviewState,
|
||||||
reviewReason,
|
reviewReason,
|
||||||
);
|
);
|
||||||
await addRemoveLabel(
|
await addRemoveLabel(
|
||||||
octokit,
|
OCTOKIT,
|
||||||
pullRequestId,
|
PULL_REQUEST_ID,
|
||||||
owner,
|
OWNER,
|
||||||
repo,
|
REPO,
|
||||||
"invalid",
|
"invalid",
|
||||||
!themesValid,
|
!themesValid,
|
||||||
);
|
);
|
||||||
@@ -558,20 +624,22 @@ export const run = async (prNumber) => {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
debug("Set review state to `REQUEST_CHANGES` and add `invalid` label...");
|
debug("Set review state to `REQUEST_CHANGES` and add `invalid` label...");
|
||||||
if (!dryRun) {
|
if (!DRY_RUN) {
|
||||||
await addReview(
|
await addReview(
|
||||||
octokit,
|
OCTOKIT,
|
||||||
pullRequestId,
|
PULL_REQUEST_ID,
|
||||||
owner,
|
OWNER,
|
||||||
repo,
|
REPO,
|
||||||
"REQUEST_CHANGES",
|
"REQUEST_CHANGES",
|
||||||
error.message,
|
"**Something went wrong in the theme preview action:** `" +
|
||||||
|
error.message +
|
||||||
|
"`",
|
||||||
);
|
);
|
||||||
await addRemoveLabel(
|
await addRemoveLabel(
|
||||||
octokit,
|
OCTOKIT,
|
||||||
pullRequestId,
|
PULL_REQUEST_ID,
|
||||||
owner,
|
OWNER,
|
||||||
repo,
|
REPO,
|
||||||
"invalid",
|
"invalid",
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export BRANCH_NAME=updated-theme-readme
|
|||||||
git --version
|
git --version
|
||||||
git config --global user.email "no-reply@githubreadmestats.com"
|
git config --global user.email "no-reply@githubreadmestats.com"
|
||||||
git config --global user.name "GitHub Readme Stats Bot"
|
git config --global user.name "GitHub Readme Stats Bot"
|
||||||
|
git config --global --add safe.directory ${GITHUB_WORKSPACE}
|
||||||
git branch -d $BRANCH_NAME || true
|
git branch -d $BRANCH_NAME || true
|
||||||
git checkout -b $BRANCH_NAME
|
git checkout -b $BRANCH_NAME
|
||||||
git add --all
|
git add --all
|
||||||
|
|||||||
+25
-11
@@ -12,6 +12,11 @@ import {
|
|||||||
import { getStyles } from "../getStyles.js";
|
import { getStyles } from "../getStyles.js";
|
||||||
import { statCardLocales } from "../translations.js";
|
import { statCardLocales } from "../translations.js";
|
||||||
|
|
||||||
|
const CARD_MIN_WIDTH = 287;
|
||||||
|
const CARD_DEFAULT_WIDTH = 287;
|
||||||
|
const RANK_CARD_MIN_WIDTH = 420;
|
||||||
|
const RANK_CARD_DEFAULT_WIDTH = 450;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a stats card text item.
|
* Create a stats card text item.
|
||||||
*
|
*
|
||||||
@@ -218,11 +223,17 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
|||||||
When hide_rank=false, the minimum card_width is 340 px + the icon width (if show_icons=true).
|
When hide_rank=false, the minimum card_width is 340 px + the icon width (if show_icons=true).
|
||||||
Numbers are picked by looking at existing dimensions on production.
|
Numbers are picked by looking at existing dimensions on production.
|
||||||
*/
|
*/
|
||||||
const iconWidth = show_icons ? 16 : 0;
|
const iconWidth = show_icons ? 16 + /* padding */ 1 : 0;
|
||||||
const minCardWidth = hide_rank
|
const minCardWidth =
|
||||||
? clampValue(50 /* padding */ + calculateTextWidth() * 2, 270, Infinity)
|
(hide_rank
|
||||||
: 340 + iconWidth;
|
? clampValue(
|
||||||
const defaultCardWidth = hide_rank ? 270 : 495;
|
50 /* padding */ + calculateTextWidth() * 2,
|
||||||
|
CARD_MIN_WIDTH,
|
||||||
|
Infinity,
|
||||||
|
)
|
||||||
|
: RANK_CARD_MIN_WIDTH) + iconWidth;
|
||||||
|
const defaultCardWidth =
|
||||||
|
(hide_rank ? CARD_DEFAULT_WIDTH : RANK_CARD_DEFAULT_WIDTH) + iconWidth;
|
||||||
let width = isNaN(card_width) ? defaultCardWidth : card_width;
|
let width = isNaN(card_width) ? defaultCardWidth : card_width;
|
||||||
if (width < minCardWidth) {
|
if (width < minCardWidth) {
|
||||||
width = minCardWidth;
|
width = minCardWidth;
|
||||||
@@ -251,18 +262,21 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the right rank circle translation values such that the rank circle
|
* Calculates the right rank circle translation values such that the rank circle
|
||||||
* keeps respecting the padding.
|
* keeps respecting the following padding:
|
||||||
*
|
*
|
||||||
* width > 450: The default left padding of 50 px will be used.
|
* width > RANK_CARD_DEFAULT_WIDTH: The default right padding of 70 px will be used.
|
||||||
* width < 450: The left and right padding will shrink equally.
|
* width < RANK_CARD_DEFAULT_WIDTH: The left and right padding will be enlarged
|
||||||
|
* equally from a certain minimum at RANK_CARD_MIN_WIDTH.
|
||||||
*
|
*
|
||||||
* @returns {number} - Rank circle translation value.
|
* @returns {number} - Rank circle translation value.
|
||||||
*/
|
*/
|
||||||
const calculateRankXTranslation = () => {
|
const calculateRankXTranslation = () => {
|
||||||
if (width < 450) {
|
const minXTranslation = RANK_CARD_MIN_WIDTH + iconWidth - 70;
|
||||||
return width - 95 + (45 * (450 - 340)) / 110;
|
if (width > RANK_CARD_DEFAULT_WIDTH) {
|
||||||
|
const xMaxExpansion = minXTranslation + (450 - minCardWidth) / 2;
|
||||||
|
return xMaxExpansion + width - RANK_CARD_DEFAULT_WIDTH;
|
||||||
} else {
|
} else {
|
||||||
return width - 95;
|
return minXTranslation + (width - minCardWidth) / 2;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
import { langCardLocales } from "../translations.js";
|
import { langCardLocales } from "../translations.js";
|
||||||
|
|
||||||
const DEFAULT_CARD_WIDTH = 300;
|
const DEFAULT_CARD_WIDTH = 300;
|
||||||
const MIN_CARD_WIDTH = 230;
|
const MIN_CARD_WIDTH = 280;
|
||||||
const DEFAULT_LANGS_COUNT = 5;
|
const DEFAULT_LANGS_COUNT = 5;
|
||||||
const DEFAULT_LANG_COLOR = "#858585";
|
const DEFAULT_LANG_COLOR = "#858585";
|
||||||
const CARD_PADDING = 25;
|
const CARD_PADDING = 25;
|
||||||
@@ -76,10 +76,11 @@ const createProgressTextNode = ({ width, color, name, progress, index }) => {
|
|||||||
* @param {object} props Function properties.
|
* @param {object} props Function properties.
|
||||||
* @param {Lang} props.lang Programming language object.
|
* @param {Lang} props.lang Programming language object.
|
||||||
* @param {number} props.totalSize Total size of all languages.
|
* @param {number} props.totalSize Total size of all languages.
|
||||||
|
* @param {boolean} props.hideProgress Whether to hide percentage.
|
||||||
* @param {number} props.index Index of the programming language.
|
* @param {number} props.index Index of the programming language.
|
||||||
* @returns {string} Compact layout programming language SVG node.
|
* @returns {string} Compact layout programming language SVG node.
|
||||||
*/
|
*/
|
||||||
const createCompactLangNode = ({ lang, totalSize, index }) => {
|
const createCompactLangNode = ({ lang, totalSize, hideProgress, index }) => {
|
||||||
const percentage = ((lang.size / totalSize) * 100).toFixed(2);
|
const percentage = ((lang.size / totalSize) * 100).toFixed(2);
|
||||||
const staggerDelay = (index + 3) * 150;
|
const staggerDelay = (index + 3) * 150;
|
||||||
const color = lang.color || "#858585";
|
const color = lang.color || "#858585";
|
||||||
@@ -88,7 +89,7 @@ const createCompactLangNode = ({ lang, totalSize, index }) => {
|
|||||||
<g class="stagger" style="animation-delay: ${staggerDelay}ms">
|
<g class="stagger" style="animation-delay: ${staggerDelay}ms">
|
||||||
<circle cx="5" cy="6" r="5" fill="${color}" />
|
<circle cx="5" cy="6" r="5" fill="${color}" />
|
||||||
<text data-testid="lang-name" x="15" y="10" class='lang-name'>
|
<text data-testid="lang-name" x="15" y="10" class='lang-name'>
|
||||||
${lang.name} ${percentage}%
|
${lang.name} ${hideProgress ? "" : percentage + "%"}
|
||||||
</text>
|
</text>
|
||||||
</g>
|
</g>
|
||||||
`;
|
`;
|
||||||
@@ -100,9 +101,10 @@ const createCompactLangNode = ({ lang, totalSize, index }) => {
|
|||||||
* @param {object[]} props Function properties.
|
* @param {object[]} props Function properties.
|
||||||
* @param {Lang[]} props.langs Array of programming languages.
|
* @param {Lang[]} props.langs Array of programming languages.
|
||||||
* @param {number} props.totalSize Total size of all languages.
|
* @param {number} props.totalSize Total size of all languages.
|
||||||
|
* @param {boolean} props.hideProgress Whether to hide percentage.
|
||||||
* @returns {string} Programming languages SVG node.
|
* @returns {string} Programming languages SVG node.
|
||||||
*/
|
*/
|
||||||
const createLanguageTextNode = ({ langs, totalSize }) => {
|
const createLanguageTextNode = ({ langs, totalSize, hideProgress }) => {
|
||||||
const longestLang = getLongestLang(langs);
|
const longestLang = getLongestLang(langs);
|
||||||
const chunked = chunkArray(langs, langs.length / 2);
|
const chunked = chunkArray(langs, langs.length / 2);
|
||||||
const layouts = chunked.map((array) => {
|
const layouts = chunked.map((array) => {
|
||||||
@@ -111,6 +113,7 @@ const createLanguageTextNode = ({ langs, totalSize }) => {
|
|||||||
createCompactLangNode({
|
createCompactLangNode({
|
||||||
lang,
|
lang,
|
||||||
totalSize,
|
totalSize,
|
||||||
|
hideProgress,
|
||||||
index,
|
index,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -160,9 +163,10 @@ const renderNormalLayout = (langs, width, totalLanguageSize) => {
|
|||||||
* @param {Lang[]} langs Array of programming languages.
|
* @param {Lang[]} langs Array of programming languages.
|
||||||
* @param {number} width Card width.
|
* @param {number} width Card width.
|
||||||
* @param {number} totalLanguageSize Total size of all languages.
|
* @param {number} totalLanguageSize Total size of all languages.
|
||||||
|
* @param {boolean} hideProgress Whether to hide progress bar.
|
||||||
* @returns {string} Compact layout card SVG object.
|
* @returns {string} Compact layout card SVG object.
|
||||||
*/
|
*/
|
||||||
const renderCompactLayout = (langs, width, totalLanguageSize) => {
|
const renderCompactLayout = (langs, width, totalLanguageSize, hideProgress) => {
|
||||||
const paddingRight = 50;
|
const paddingRight = 50;
|
||||||
const offsetWidth = width - paddingRight;
|
const offsetWidth = width - paddingRight;
|
||||||
// progressOffset holds the previous language's width and used to offset the next language
|
// progressOffset holds the previous language's width and used to offset the next language
|
||||||
@@ -193,15 +197,21 @@ const renderCompactLayout = (langs, width, totalLanguageSize) => {
|
|||||||
.join("");
|
.join("");
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<mask id="rect-mask">
|
${
|
||||||
|
!hideProgress
|
||||||
|
? `
|
||||||
|
<mask id="rect-mask">
|
||||||
<rect x="0" y="0" width="${offsetWidth}" height="8" fill="white" rx="5"/>
|
<rect x="0" y="0" width="${offsetWidth}" height="8" fill="white" rx="5"/>
|
||||||
</mask>
|
</mask>
|
||||||
${compactProgressBar}
|
${compactProgressBar}
|
||||||
|
`
|
||||||
<g transform="translate(0, 25)">
|
: ""
|
||||||
|
}
|
||||||
|
<g transform="translate(0, ${hideProgress ? "0" : "25"})">
|
||||||
${createLanguageTextNode({
|
${createLanguageTextNode({
|
||||||
langs,
|
langs,
|
||||||
totalSize: totalLanguageSize,
|
totalSize: totalLanguageSize,
|
||||||
|
hideProgress: hideProgress,
|
||||||
})}
|
})}
|
||||||
</g>
|
</g>
|
||||||
`;
|
`;
|
||||||
@@ -276,6 +286,7 @@ const renderTopLanguages = (topLangs, options = {}) => {
|
|||||||
text_color,
|
text_color,
|
||||||
bg_color,
|
bg_color,
|
||||||
hide,
|
hide,
|
||||||
|
hide_progress,
|
||||||
theme,
|
theme,
|
||||||
layout,
|
layout,
|
||||||
custom_title,
|
custom_title,
|
||||||
@@ -305,11 +316,16 @@ const renderTopLanguages = (topLangs, options = {}) => {
|
|||||||
let height = calculateNormalLayoutHeight(langs.length);
|
let height = calculateNormalLayoutHeight(langs.length);
|
||||||
|
|
||||||
let finalLayout = "";
|
let finalLayout = "";
|
||||||
if (layout === "compact") {
|
if (layout === "compact" || hide_progress == true) {
|
||||||
width = width + 50; // padding
|
height =
|
||||||
height = calculateCompactLayoutHeight(langs.length);
|
calculateCompactLayoutHeight(langs.length) + (hide_progress ? -25 : 0);
|
||||||
|
|
||||||
finalLayout = renderCompactLayout(langs, width, totalLanguageSize);
|
finalLayout = renderCompactLayout(
|
||||||
|
langs,
|
||||||
|
width,
|
||||||
|
totalLanguageSize,
|
||||||
|
hide_progress,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
finalLayout = renderNormalLayout(langs, width, totalLanguageSize);
|
finalLayout = renderNormalLayout(langs, width, totalLanguageSize);
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
@@ -38,6 +38,7 @@ export type TopLangOptions = CommonOptions & {
|
|||||||
custom_title: string;
|
custom_title: string;
|
||||||
langs_count: number;
|
langs_count: number;
|
||||||
disable_animations: boolean;
|
disable_animations: boolean;
|
||||||
|
hide_progress: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type WakaTimeOptions = CommonOptions & {
|
type WakaTimeOptions = CommonOptions & {
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ const createTextNode = ({
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
name: label,
|
name: label,
|
||||||
progressBarBackgroundColor,
|
progressBarBackgroundColor,
|
||||||
|
delay: staggerDelay + 300,
|
||||||
});
|
});
|
||||||
|
|
||||||
return `
|
return `
|
||||||
@@ -276,11 +277,12 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
|
|||||||
} else {
|
} else {
|
||||||
finalLayout = flexLayout({
|
finalLayout = flexLayout({
|
||||||
items: filteredLanguages.length
|
items: filteredLanguages.length
|
||||||
? filteredLanguages.map((language) => {
|
? filteredLanguages.map((language, index) => {
|
||||||
return createTextNode({
|
return createTextNode({
|
||||||
id: language.name,
|
id: language.name,
|
||||||
label: language.name,
|
label: language.name,
|
||||||
value: language.text,
|
value: language.text,
|
||||||
|
index: index,
|
||||||
percent: language.percent,
|
percent: language.percent,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
progressBarColor: titleColor,
|
progressBarColor: titleColor,
|
||||||
@@ -321,7 +323,29 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
|
|||||||
card.setCSS(
|
card.setCSS(
|
||||||
`
|
`
|
||||||
${cssStyles}
|
${cssStyles}
|
||||||
|
@keyframes slideInAnimation {
|
||||||
|
from {
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
width: calc(100%-100px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@keyframes growWidthAnimation {
|
||||||
|
from {
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
.lang-name { font: 400 11px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${textColor} }
|
.lang-name { font: 400 11px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${textColor} }
|
||||||
|
#rect-mask rect{
|
||||||
|
animation: slideInAnimation 1s ease-in-out forwards;
|
||||||
|
}
|
||||||
|
.lang-progress{
|
||||||
|
animation: growWidthAnimation 0.6s ease-in-out forwards;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,7 @@
|
|||||||
"Ceylon": "#dfa535",
|
"Ceylon": "#dfa535",
|
||||||
"Chapel": "#8dc63f",
|
"Chapel": "#8dc63f",
|
||||||
"ChucK": "#3f8000",
|
"ChucK": "#3f8000",
|
||||||
|
"Circom": "#707575",
|
||||||
"Cirru": "#ccccff",
|
"Cirru": "#ccccff",
|
||||||
"Clarion": "#db901e",
|
"Clarion": "#db901e",
|
||||||
"Clarity": "#5546ff",
|
"Clarity": "#5546ff",
|
||||||
@@ -102,6 +103,7 @@
|
|||||||
"Csound Score": "#1a1a1a",
|
"Csound Score": "#1a1a1a",
|
||||||
"Cuda": "#3A4E3A",
|
"Cuda": "#3A4E3A",
|
||||||
"Curry": "#531242",
|
"Curry": "#531242",
|
||||||
|
"Cypher": "#34c0eb",
|
||||||
"Cython": "#fedf5b",
|
"Cython": "#fedf5b",
|
||||||
"D": "#ba595e",
|
"D": "#ba595e",
|
||||||
"DM": "#447265",
|
"DM": "#447265",
|
||||||
@@ -115,6 +117,7 @@
|
|||||||
"DirectX 3D File": "#aace60",
|
"DirectX 3D File": "#aace60",
|
||||||
"Dockerfile": "#384d54",
|
"Dockerfile": "#384d54",
|
||||||
"Dogescript": "#cca760",
|
"Dogescript": "#cca760",
|
||||||
|
"Dotenv": "#e5d559",
|
||||||
"Dylan": "#6c616e",
|
"Dylan": "#6c616e",
|
||||||
"E": "#ccce35",
|
"E": "#ccce35",
|
||||||
"ECL": "#8a1267",
|
"ECL": "#8a1267",
|
||||||
@@ -124,6 +127,7 @@
|
|||||||
"Earthly": "#2af0ff",
|
"Earthly": "#2af0ff",
|
||||||
"Easybuild": "#069406",
|
"Easybuild": "#069406",
|
||||||
"Ecere Projects": "#913960",
|
"Ecere Projects": "#913960",
|
||||||
|
"Ecmarkup": "#eb8131",
|
||||||
"EditorConfig": "#fff1f2",
|
"EditorConfig": "#fff1f2",
|
||||||
"Eiffel": "#4d6977",
|
"Eiffel": "#4d6977",
|
||||||
"Elixir": "#6e4a7e",
|
"Elixir": "#6e4a7e",
|
||||||
@@ -147,7 +151,7 @@
|
|||||||
"Forth": "#341708",
|
"Forth": "#341708",
|
||||||
"Fortran": "#4d41b1",
|
"Fortran": "#4d41b1",
|
||||||
"Fortran Free Form": "#4d41b1",
|
"Fortran Free Form": "#4d41b1",
|
||||||
"FreeBasic": "#867db1",
|
"FreeBasic": "#141AC9",
|
||||||
"FreeMarker": "#0050b2",
|
"FreeMarker": "#0050b2",
|
||||||
"Frege": "#00cafe",
|
"Frege": "#00cafe",
|
||||||
"Futhark": "#5f021f",
|
"Futhark": "#5f021f",
|
||||||
@@ -180,6 +184,7 @@
|
|||||||
"Go": "#00ADD8",
|
"Go": "#00ADD8",
|
||||||
"Go Checksums": "#00ADD8",
|
"Go Checksums": "#00ADD8",
|
||||||
"Go Module": "#00ADD8",
|
"Go Module": "#00ADD8",
|
||||||
|
"Godot Resource": "#355570",
|
||||||
"Golo": "#88562A",
|
"Golo": "#88562A",
|
||||||
"Gosu": "#82937f",
|
"Gosu": "#82937f",
|
||||||
"Grace": "#615f8b",
|
"Grace": "#615f8b",
|
||||||
@@ -190,6 +195,7 @@
|
|||||||
"Groovy": "#4298b8",
|
"Groovy": "#4298b8",
|
||||||
"Groovy Server Pages": "#4298b8",
|
"Groovy Server Pages": "#4298b8",
|
||||||
"HAProxy": "#106da9",
|
"HAProxy": "#106da9",
|
||||||
|
"HCL": "#844FBA",
|
||||||
"HLSL": "#aace60",
|
"HLSL": "#aace60",
|
||||||
"HOCON": "#9ff8ee",
|
"HOCON": "#9ff8ee",
|
||||||
"HTML": "#e34c26",
|
"HTML": "#e34c26",
|
||||||
@@ -215,6 +221,7 @@
|
|||||||
"Idris": "#b30000",
|
"Idris": "#b30000",
|
||||||
"Ignore List": "#000000",
|
"Ignore List": "#000000",
|
||||||
"ImageJ Macro": "#99AAFF",
|
"ImageJ Macro": "#99AAFF",
|
||||||
|
"Imba": "#16cec6",
|
||||||
"Inno Setup": "#264b99",
|
"Inno Setup": "#264b99",
|
||||||
"Io": "#a9188d",
|
"Io": "#a9188d",
|
||||||
"Ioke": "#078193",
|
"Ioke": "#078193",
|
||||||
@@ -222,6 +229,7 @@
|
|||||||
"Isabelle ROOT": "#FEFE00",
|
"Isabelle ROOT": "#FEFE00",
|
||||||
"J": "#9EEDFF",
|
"J": "#9EEDFF",
|
||||||
"JAR Manifest": "#b07219",
|
"JAR Manifest": "#b07219",
|
||||||
|
"JCL": "#d90e09",
|
||||||
"JFlex": "#DBCA00",
|
"JFlex": "#DBCA00",
|
||||||
"JSON": "#292929",
|
"JSON": "#292929",
|
||||||
"JSON with Comments": "#292929",
|
"JSON with Comments": "#292929",
|
||||||
@@ -244,9 +252,11 @@
|
|||||||
"Jsonnet": "#0064bd",
|
"Jsonnet": "#0064bd",
|
||||||
"Julia": "#a270ba",
|
"Julia": "#a270ba",
|
||||||
"Jupyter Notebook": "#DA5B0B",
|
"Jupyter Notebook": "#DA5B0B",
|
||||||
|
"Just": "#384d54",
|
||||||
"KRL": "#28430A",
|
"KRL": "#28430A",
|
||||||
"Kaitai Struct": "#773b37",
|
"Kaitai Struct": "#773b37",
|
||||||
"KakouneScript": "#6f8042",
|
"KakouneScript": "#6f8042",
|
||||||
|
"KerboScript": "#41adf0",
|
||||||
"KiCad Layout": "#2f4aab",
|
"KiCad Layout": "#2f4aab",
|
||||||
"KiCad Legacy Layout": "#2f4aab",
|
"KiCad Legacy Layout": "#2f4aab",
|
||||||
"KiCad Schematic": "#2f4aab",
|
"KiCad Schematic": "#2f4aab",
|
||||||
@@ -286,6 +296,7 @@
|
|||||||
"Mathematica": "#dd1100",
|
"Mathematica": "#dd1100",
|
||||||
"Max": "#c4a79c",
|
"Max": "#c4a79c",
|
||||||
"Mercury": "#ff2b2b",
|
"Mercury": "#ff2b2b",
|
||||||
|
"Mermaid": "#ff3670",
|
||||||
"Meson": "#007800",
|
"Meson": "#007800",
|
||||||
"Metal": "#8f14e9",
|
"Metal": "#8f14e9",
|
||||||
"MiniYAML": "#ff1111",
|
"MiniYAML": "#ff1111",
|
||||||
@@ -318,6 +329,10 @@
|
|||||||
"Nu": "#c9df40",
|
"Nu": "#c9df40",
|
||||||
"NumPy": "#9C8AF9",
|
"NumPy": "#9C8AF9",
|
||||||
"Nunjucks": "#3d8137",
|
"Nunjucks": "#3d8137",
|
||||||
|
"OASv2-json": "#85ea2d",
|
||||||
|
"OASv2-yaml": "#85ea2d",
|
||||||
|
"OASv3-json": "#85ea2d",
|
||||||
|
"OASv3-yaml": "#85ea2d",
|
||||||
"OCaml": "#3be133",
|
"OCaml": "#3be133",
|
||||||
"ObjectScript": "#424893",
|
"ObjectScript": "#424893",
|
||||||
"Objective-C": "#438eff",
|
"Objective-C": "#438eff",
|
||||||
@@ -327,14 +342,18 @@
|
|||||||
"Omgrofl": "#cabbff",
|
"Omgrofl": "#cabbff",
|
||||||
"Opal": "#f7ede0",
|
"Opal": "#f7ede0",
|
||||||
"Open Policy Agent": "#7d9199",
|
"Open Policy Agent": "#7d9199",
|
||||||
|
"OpenAPI Specification v2": "#85ea2d",
|
||||||
|
"OpenAPI Specification v3": "#85ea2d",
|
||||||
"OpenCL": "#ed2e2d",
|
"OpenCL": "#ed2e2d",
|
||||||
"OpenEdge ABL": "#5ce600",
|
"OpenEdge ABL": "#5ce600",
|
||||||
"OpenQASM": "#AA70FF",
|
"OpenQASM": "#AA70FF",
|
||||||
"OpenSCAD": "#e5cd45",
|
"OpenSCAD": "#e5cd45",
|
||||||
|
"Option List": "#476732",
|
||||||
"Org": "#77aa99",
|
"Org": "#77aa99",
|
||||||
"Oxygene": "#cdd0e3",
|
"Oxygene": "#cdd0e3",
|
||||||
"Oz": "#fab738",
|
"Oz": "#fab738",
|
||||||
"P4": "#7055b5",
|
"P4": "#7055b5",
|
||||||
|
"PDDL": "#0d00ff",
|
||||||
"PEG.js": "#234d6b",
|
"PEG.js": "#234d6b",
|
||||||
"PHP": "#4F5D95",
|
"PHP": "#4F5D95",
|
||||||
"PLSQL": "#dad8d8",
|
"PLSQL": "#dad8d8",
|
||||||
@@ -350,7 +369,9 @@
|
|||||||
"PicoLisp": "#6067af",
|
"PicoLisp": "#6067af",
|
||||||
"PigLatin": "#fcd7de",
|
"PigLatin": "#fcd7de",
|
||||||
"Pike": "#005390",
|
"Pike": "#005390",
|
||||||
|
"PlantUML": "#fbbd16",
|
||||||
"PogoScript": "#d80074",
|
"PogoScript": "#d80074",
|
||||||
|
"Polar": "#ae81ff",
|
||||||
"Portugol": "#f8bd00",
|
"Portugol": "#f8bd00",
|
||||||
"PostCSS": "#dc3a0c",
|
"PostCSS": "#dc3a0c",
|
||||||
"PostScript": "#da291c",
|
"PostScript": "#da291c",
|
||||||
@@ -366,6 +387,7 @@
|
|||||||
"Puppet": "#302B6D",
|
"Puppet": "#302B6D",
|
||||||
"PureBasic": "#5a6986",
|
"PureBasic": "#5a6986",
|
||||||
"PureScript": "#1D222D",
|
"PureScript": "#1D222D",
|
||||||
|
"Pyret": "#ee1e10",
|
||||||
"Python": "#3572A5",
|
"Python": "#3572A5",
|
||||||
"Python console": "#3572A5",
|
"Python console": "#3572A5",
|
||||||
"Python traceback": "#3572A5",
|
"Python traceback": "#3572A5",
|
||||||
@@ -414,6 +436,7 @@
|
|||||||
"Sass": "#a53b70",
|
"Sass": "#a53b70",
|
||||||
"Scala": "#c22d40",
|
"Scala": "#c22d40",
|
||||||
"Scaml": "#bd181a",
|
"Scaml": "#bd181a",
|
||||||
|
"Scenic": "#fdc700",
|
||||||
"Scheme": "#1e4aec",
|
"Scheme": "#1e4aec",
|
||||||
"Scilab": "#ca0f21",
|
"Scilab": "#ca0f21",
|
||||||
"Self": "#0579aa",
|
"Self": "#0579aa",
|
||||||
@@ -421,6 +444,7 @@
|
|||||||
"Shell": "#89e051",
|
"Shell": "#89e051",
|
||||||
"ShellCheck Config": "#cecfcb",
|
"ShellCheck Config": "#cecfcb",
|
||||||
"Shen": "#120F14",
|
"Shen": "#120F14",
|
||||||
|
"Simple File Verification": "#C9BFED",
|
||||||
"Singularity": "#64E6AD",
|
"Singularity": "#64E6AD",
|
||||||
"Slash": "#007eff",
|
"Slash": "#007eff",
|
||||||
"Slice": "#003fa2",
|
"Slice": "#003fa2",
|
||||||
@@ -428,6 +452,7 @@
|
|||||||
"SmPL": "#c94949",
|
"SmPL": "#c94949",
|
||||||
"Smalltalk": "#596706",
|
"Smalltalk": "#596706",
|
||||||
"Smarty": "#f0c040",
|
"Smarty": "#f0c040",
|
||||||
|
"Smithy": "#c44536",
|
||||||
"Solidity": "#AA6746",
|
"Solidity": "#AA6746",
|
||||||
"SourcePawn": "#f69e1d",
|
"SourcePawn": "#f69e1d",
|
||||||
"Squirrel": "#800000",
|
"Squirrel": "#800000",
|
||||||
@@ -478,6 +503,7 @@
|
|||||||
"Vim Script": "#199f4b",
|
"Vim Script": "#199f4b",
|
||||||
"Vim Snippet": "#199f4b",
|
"Vim Snippet": "#199f4b",
|
||||||
"Visual Basic .NET": "#945db7",
|
"Visual Basic .NET": "#945db7",
|
||||||
|
"Visual Basic 6.0": "#2c6353",
|
||||||
"Volt": "#1F1F1F",
|
"Volt": "#1F1F1F",
|
||||||
"Vue": "#41b883",
|
"Vue": "#41b883",
|
||||||
"Vyper": "#2980b9",
|
"Vyper": "#2980b9",
|
||||||
|
|||||||
@@ -424,6 +424,19 @@ const parseEmojis = (str) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get diff in minutes
|
||||||
|
* @param {Date} d1
|
||||||
|
* @param {Date} d2
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
const dateDiff = (d1, d2) => {
|
||||||
|
const date1 = new Date(d1);
|
||||||
|
const date2 = new Date(d2);
|
||||||
|
const diff = date1.getTime() - date2.getTime();
|
||||||
|
return Math.round(diff / (1000 * 60));
|
||||||
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
ERROR_CARD_LENGTH,
|
ERROR_CARD_LENGTH,
|
||||||
renderError,
|
renderError,
|
||||||
@@ -447,4 +460,5 @@ export {
|
|||||||
lowercaseTrim,
|
lowercaseTrim,
|
||||||
chunkArray,
|
chunkArray,
|
||||||
parseEmojis,
|
parseEmojis,
|
||||||
|
dateDiff,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -69,7 +69,29 @@ exports[`Test Render Wakatime Card should render correctly with compact layout 1
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@keyframes slideInAnimation {
|
||||||
|
from {
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
width: calc(100%-100px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@keyframes growWidthAnimation {
|
||||||
|
from {
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
.lang-name { font: 400 11px 'Segoe UI', Ubuntu, Sans-Serif; fill: #434d58 }
|
.lang-name { font: 400 11px 'Segoe UI', Ubuntu, Sans-Serif; fill: #434d58 }
|
||||||
|
#rect-mask rect{
|
||||||
|
animation: slideInAnimation 1s ease-in-out forwards;
|
||||||
|
}
|
||||||
|
.lang-progress{
|
||||||
|
animation: growWidthAnimation 0.6s ease-in-out forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -227,7 +249,29 @@ exports[`Test Render Wakatime Card should render correctly with compact layout w
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@keyframes slideInAnimation {
|
||||||
|
from {
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
width: calc(100%-100px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@keyframes growWidthAnimation {
|
||||||
|
from {
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
.lang-name { font: 400 11px 'Segoe UI', Ubuntu, Sans-Serif; fill: #434d58 }
|
.lang-name { font: 400 11px 'Segoe UI', Ubuntu, Sans-Serif; fill: #434d58 }
|
||||||
|
#rect-mask rect{
|
||||||
|
animation: slideInAnimation 1s ease-in-out forwards;
|
||||||
|
}
|
||||||
|
.lang-progress{
|
||||||
|
animation: growWidthAnimation 0.6s ease-in-out forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ const REPO = "curly-fiesta";
|
|||||||
const USER = "catelinemnemosyne";
|
const USER = "catelinemnemosyne";
|
||||||
const STATS_DATA = {
|
const STATS_DATA = {
|
||||||
name: "Cateline Mnemosyne",
|
name: "Cateline Mnemosyne",
|
||||||
totalPRs: 1,
|
totalPRs: 2,
|
||||||
totalCommits: 7,
|
totalCommits: 8,
|
||||||
totalIssues: 1,
|
totalIssues: 1,
|
||||||
totalStars: 1,
|
totalStars: 1,
|
||||||
contributedTo: 1,
|
contributedTo: 1,
|
||||||
rank: {
|
rank: {
|
||||||
level: "A+",
|
level: "A+",
|
||||||
score: 50.893750297869225,
|
score: 50.88831151384285,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,244 @@
|
|||||||
|
/**
|
||||||
|
* @file Tests for the status/pat-info cloud function.
|
||||||
|
*/
|
||||||
|
import dotenv from "dotenv";
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
import { jest } from "@jest/globals";
|
||||||
|
import axios from "axios";
|
||||||
|
import MockAdapter from "axios-mock-adapter";
|
||||||
|
import patInfo, { RATE_LIMIT_SECONDS } from "../api/status/pat-info.js";
|
||||||
|
|
||||||
|
const mock = new MockAdapter(axios);
|
||||||
|
|
||||||
|
const successData = {
|
||||||
|
data: {
|
||||||
|
rateLimit: {
|
||||||
|
remaining: 4986,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const faker = (query) => {
|
||||||
|
const req = {
|
||||||
|
query: { ...query },
|
||||||
|
};
|
||||||
|
const res = {
|
||||||
|
setHeader: jest.fn(),
|
||||||
|
send: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
return { req, res };
|
||||||
|
};
|
||||||
|
|
||||||
|
const rate_limit_error = {
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
type: "RATE_LIMITED",
|
||||||
|
message: "API rate limit exceeded for user ID.",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
data: {
|
||||||
|
rateLimit: {
|
||||||
|
resetAt: Date.now(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const other_error = {
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
type: "SOME_ERROR",
|
||||||
|
message: "This is a error",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const bad_credentials_error = {
|
||||||
|
message: "Bad credentials",
|
||||||
|
};
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
mock.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Test /api/status/pat-info", () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
// reset patenv first so that dotenv doesn't populate them with local envs
|
||||||
|
process.env = {};
|
||||||
|
process.env.PAT_1 = "testPAT1";
|
||||||
|
process.env.PAT_2 = "testPAT2";
|
||||||
|
process.env.PAT_3 = "testPAT3";
|
||||||
|
process.env.PAT_4 = "testPAT4";
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return only 'validPATs' if all PATs are valid", async () => {
|
||||||
|
mock
|
||||||
|
.onPost("https://api.github.com/graphql")
|
||||||
|
.replyOnce(200, rate_limit_error)
|
||||||
|
.onPost("https://api.github.com/graphql")
|
||||||
|
.reply(200, successData);
|
||||||
|
|
||||||
|
const { req, res } = faker({}, {});
|
||||||
|
await patInfo(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "application/json");
|
||||||
|
expect(res.send).toBeCalledWith(
|
||||||
|
JSON.stringify(
|
||||||
|
{
|
||||||
|
validPATs: ["PAT_2", "PAT_3", "PAT_4"],
|
||||||
|
expiredPATs: [],
|
||||||
|
exhaustedPATs: ["PAT_1"],
|
||||||
|
suspendedPATs: [],
|
||||||
|
errorPATs: [],
|
||||||
|
details: {
|
||||||
|
PAT_1: {
|
||||||
|
status: "exhausted",
|
||||||
|
remaining: 0,
|
||||||
|
resetIn: "0 minutes",
|
||||||
|
},
|
||||||
|
PAT_2: {
|
||||||
|
status: "valid",
|
||||||
|
remaining: 4986,
|
||||||
|
},
|
||||||
|
PAT_3: {
|
||||||
|
status: "valid",
|
||||||
|
remaining: 4986,
|
||||||
|
},
|
||||||
|
PAT_4: {
|
||||||
|
status: "valid",
|
||||||
|
remaining: 4986,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return `errorPATs` if a PAT causes an error to be thrown", async () => {
|
||||||
|
mock
|
||||||
|
.onPost("https://api.github.com/graphql")
|
||||||
|
.replyOnce(200, other_error)
|
||||||
|
.onPost("https://api.github.com/graphql")
|
||||||
|
.reply(200, successData);
|
||||||
|
|
||||||
|
const { req, res } = faker({}, {});
|
||||||
|
await patInfo(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "application/json");
|
||||||
|
expect(res.send).toBeCalledWith(
|
||||||
|
JSON.stringify(
|
||||||
|
{
|
||||||
|
validPATs: ["PAT_2", "PAT_3", "PAT_4"],
|
||||||
|
expiredPATs: [],
|
||||||
|
exhaustedPATs: [],
|
||||||
|
suspendedPATs: [],
|
||||||
|
errorPATs: ["PAT_1"],
|
||||||
|
details: {
|
||||||
|
PAT_1: {
|
||||||
|
status: "error",
|
||||||
|
error: {
|
||||||
|
type: "SOME_ERROR",
|
||||||
|
message: "This is a error",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
PAT_2: {
|
||||||
|
status: "valid",
|
||||||
|
remaining: 4986,
|
||||||
|
},
|
||||||
|
PAT_3: {
|
||||||
|
status: "valid",
|
||||||
|
remaining: 4986,
|
||||||
|
},
|
||||||
|
PAT_4: {
|
||||||
|
status: "valid",
|
||||||
|
remaining: 4986,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return `expiredPaths` if a PAT returns a 'Bad credentials' error", async () => {
|
||||||
|
mock
|
||||||
|
.onPost("https://api.github.com/graphql")
|
||||||
|
.replyOnce(404, bad_credentials_error)
|
||||||
|
.onPost("https://api.github.com/graphql")
|
||||||
|
.reply(200, successData);
|
||||||
|
|
||||||
|
const { req, res } = faker({}, {});
|
||||||
|
await patInfo(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "application/json");
|
||||||
|
expect(res.send).toBeCalledWith(
|
||||||
|
JSON.stringify(
|
||||||
|
{
|
||||||
|
validPATs: ["PAT_2", "PAT_3", "PAT_4"],
|
||||||
|
expiredPATs: ["PAT_1"],
|
||||||
|
exhaustedPATs: [],
|
||||||
|
suspendedPATs: [],
|
||||||
|
errorPATs: [],
|
||||||
|
details: {
|
||||||
|
PAT_1: {
|
||||||
|
status: "expired",
|
||||||
|
},
|
||||||
|
PAT_2: {
|
||||||
|
status: "valid",
|
||||||
|
remaining: 4986,
|
||||||
|
},
|
||||||
|
PAT_3: {
|
||||||
|
status: "valid",
|
||||||
|
remaining: 4986,
|
||||||
|
},
|
||||||
|
PAT_4: {
|
||||||
|
status: "valid",
|
||||||
|
remaining: 4986,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should throw an error if something goes wrong", async () => {
|
||||||
|
mock.onPost("https://api.github.com/graphql").networkError();
|
||||||
|
|
||||||
|
const { req, res } = faker({}, {});
|
||||||
|
await patInfo(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "application/json");
|
||||||
|
expect(res.send).toBeCalledWith("Something went wrong: Network Error");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should have proper cache when no error is thrown", async () => {
|
||||||
|
mock.onPost("https://api.github.com/graphql").reply(200, successData);
|
||||||
|
|
||||||
|
const { req, res } = faker({}, {});
|
||||||
|
await patInfo(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader.mock.calls).toEqual([
|
||||||
|
["Content-Type", "application/json"],
|
||||||
|
["Cache-Control", `max-age=0, s-maxage=${RATE_LIMIT_SECONDS}`],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should have proper cache when error is thrown", async () => {
|
||||||
|
mock.reset();
|
||||||
|
mock.onPost("https://api.github.com/graphql").networkError();
|
||||||
|
|
||||||
|
const { req, res } = faker({}, {});
|
||||||
|
await patInfo(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader.mock.calls).toEqual([
|
||||||
|
["Content-Type", "application/json"],
|
||||||
|
["Cache-Control", "no-store"],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -78,16 +78,17 @@ describe("Test renderStatsCard", () => {
|
|||||||
|
|
||||||
it("should render with custom width set", () => {
|
it("should render with custom width set", () => {
|
||||||
document.body.innerHTML = renderStatsCard(stats);
|
document.body.innerHTML = renderStatsCard(stats);
|
||||||
expect(document.querySelector("svg")).toHaveAttribute("width", "495");
|
expect(document.querySelector("svg")).toHaveAttribute("width", "450");
|
||||||
|
|
||||||
document.body.innerHTML = renderStatsCard(stats, { card_width: 400 });
|
document.body.innerHTML = renderStatsCard(stats, { card_width: 500 });
|
||||||
expect(document.querySelector("svg")).toHaveAttribute("width", "400");
|
expect(document.querySelector("svg")).toHaveAttribute("width", "500");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should render with custom width set and limit minimum width", () => {
|
it("should render with custom width set and limit minimum width", () => {
|
||||||
document.body.innerHTML = renderStatsCard(stats, { card_width: 1 });
|
document.body.innerHTML = renderStatsCard(stats, { card_width: 1 });
|
||||||
expect(document.querySelector("svg")).toHaveAttribute("width", "340");
|
expect(document.querySelector("svg")).toHaveAttribute("width", "420");
|
||||||
|
|
||||||
|
// Test default minimum card width without rank circle.
|
||||||
document.body.innerHTML = renderStatsCard(stats, {
|
document.body.innerHTML = renderStatsCard(stats, {
|
||||||
card_width: 1,
|
card_width: 1,
|
||||||
hide_rank: true,
|
hide_rank: true,
|
||||||
@@ -97,6 +98,7 @@ describe("Test renderStatsCard", () => {
|
|||||||
"305.81250000000006",
|
"305.81250000000006",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Test minimum card width with rank and icons.
|
||||||
document.body.innerHTML = renderStatsCard(stats, {
|
document.body.innerHTML = renderStatsCard(stats, {
|
||||||
card_width: 1,
|
card_width: 1,
|
||||||
hide_rank: true,
|
hide_rank: true,
|
||||||
@@ -104,22 +106,24 @@ describe("Test renderStatsCard", () => {
|
|||||||
});
|
});
|
||||||
expect(document.querySelector("svg")).toHaveAttribute(
|
expect(document.querySelector("svg")).toHaveAttribute(
|
||||||
"width",
|
"width",
|
||||||
"305.81250000000006",
|
"322.81250000000006",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Test minimum card width with icons but without rank.
|
||||||
document.body.innerHTML = renderStatsCard(stats, {
|
document.body.innerHTML = renderStatsCard(stats, {
|
||||||
card_width: 1,
|
card_width: 1,
|
||||||
hide_rank: false,
|
hide_rank: false,
|
||||||
show_icons: true,
|
show_icons: true,
|
||||||
});
|
});
|
||||||
expect(document.querySelector("svg")).toHaveAttribute("width", "356");
|
expect(document.querySelector("svg")).toHaveAttribute("width", "437");
|
||||||
|
|
||||||
|
// Test minimum card width without icons or rank.
|
||||||
document.body.innerHTML = renderStatsCard(stats, {
|
document.body.innerHTML = renderStatsCard(stats, {
|
||||||
card_width: 1,
|
card_width: 1,
|
||||||
hide_rank: false,
|
hide_rank: false,
|
||||||
show_icons: false,
|
show_icons: false,
|
||||||
});
|
});
|
||||||
expect(document.querySelector("svg")).toHaveAttribute("width", "340");
|
expect(document.querySelector("svg")).toHaveAttribute("width", "420");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should render default colors properly", () => {
|
it("should render default colors properly", () => {
|
||||||
@@ -312,7 +316,7 @@ describe("Test renderStatsCard", () => {
|
|||||||
|
|
||||||
expect(
|
expect(
|
||||||
document.body.getElementsByTagName("svg")[0].getAttribute("width"),
|
document.body.getElementsByTagName("svg")[0].getAttribute("width"),
|
||||||
).toBe("270");
|
).toBe("287");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should render translations", () => {
|
it("should render translations", () => {
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ describe("Test renderTopLanguages", () => {
|
|||||||
);
|
);
|
||||||
expect(queryAllByTestId(document.body, "lang-progress")[0]).toHaveAttribute(
|
expect(queryAllByTestId(document.body, "lang-progress")[0]).toHaveAttribute(
|
||||||
"width",
|
"width",
|
||||||
"120",
|
"100",
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(queryAllByTestId(document.body, "lang-name")[1]).toHaveTextContent(
|
expect(queryAllByTestId(document.body, "lang-name")[1]).toHaveTextContent(
|
||||||
@@ -224,7 +224,7 @@ describe("Test renderTopLanguages", () => {
|
|||||||
);
|
);
|
||||||
expect(queryAllByTestId(document.body, "lang-progress")[1]).toHaveAttribute(
|
expect(queryAllByTestId(document.body, "lang-progress")[1]).toHaveAttribute(
|
||||||
"width",
|
"width",
|
||||||
"120",
|
"100",
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(queryAllByTestId(document.body, "lang-name")[2]).toHaveTextContent(
|
expect(queryAllByTestId(document.body, "lang-name")[2]).toHaveTextContent(
|
||||||
@@ -232,7 +232,7 @@ describe("Test renderTopLanguages", () => {
|
|||||||
);
|
);
|
||||||
expect(queryAllByTestId(document.body, "lang-progress")[2]).toHaveAttribute(
|
expect(queryAllByTestId(document.body, "lang-progress")[2]).toHaveAttribute(
|
||||||
"width",
|
"width",
|
||||||
"60",
|
"50",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,194 @@
|
|||||||
|
/**
|
||||||
|
* @file Tests for the status/up cloud function.
|
||||||
|
*/
|
||||||
|
import { jest } from "@jest/globals";
|
||||||
|
import axios from "axios";
|
||||||
|
import MockAdapter from "axios-mock-adapter";
|
||||||
|
import up, { RATE_LIMIT_SECONDS } from "../api/status/up.js";
|
||||||
|
|
||||||
|
const mock = new MockAdapter(axios);
|
||||||
|
|
||||||
|
const successData = {
|
||||||
|
rateLimit: {
|
||||||
|
remaining: 4986,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const faker = (query) => {
|
||||||
|
const req = {
|
||||||
|
query: { ...query },
|
||||||
|
};
|
||||||
|
const res = {
|
||||||
|
setHeader: jest.fn(),
|
||||||
|
send: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
return { req, res };
|
||||||
|
};
|
||||||
|
|
||||||
|
const rate_limit_error = {
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
type: "RATE_LIMITED",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const bad_credentials_error = {
|
||||||
|
message: "Bad credentials",
|
||||||
|
};
|
||||||
|
|
||||||
|
const shields_up = {
|
||||||
|
schemaVersion: 1,
|
||||||
|
label: "Public Instance",
|
||||||
|
isError: true,
|
||||||
|
message: "up",
|
||||||
|
color: "brightgreen",
|
||||||
|
};
|
||||||
|
const shields_down = {
|
||||||
|
schemaVersion: 1,
|
||||||
|
label: "Public Instance",
|
||||||
|
isError: true,
|
||||||
|
message: "down",
|
||||||
|
color: "red",
|
||||||
|
};
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
mock.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Test /api/status/up", () => {
|
||||||
|
it("should return `true` if request was successful", async () => {
|
||||||
|
mock.onPost("https://api.github.com/graphql").replyOnce(200, successData);
|
||||||
|
|
||||||
|
const { req, res } = faker({}, {});
|
||||||
|
await up(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "application/json");
|
||||||
|
expect(res.send).toBeCalledWith(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return `false` if all PATs are rate limited", async () => {
|
||||||
|
mock.onPost("https://api.github.com/graphql").reply(200, rate_limit_error);
|
||||||
|
|
||||||
|
const { req, res } = faker({}, {});
|
||||||
|
await up(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "application/json");
|
||||||
|
expect(res.send).toBeCalledWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return JSON `true` if request was successful and type='json'", async () => {
|
||||||
|
mock.onPost("https://api.github.com/graphql").replyOnce(200, successData);
|
||||||
|
|
||||||
|
const { req, res } = faker({ type: "json" }, {});
|
||||||
|
await up(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "application/json");
|
||||||
|
expect(res.send).toBeCalledWith({ up: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return JSON `false` if all PATs are rate limited and type='json'", async () => {
|
||||||
|
mock.onPost("https://api.github.com/graphql").reply(200, rate_limit_error);
|
||||||
|
|
||||||
|
const { req, res } = faker({ type: "json" }, {});
|
||||||
|
await up(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "application/json");
|
||||||
|
expect(res.send).toBeCalledWith({ up: false });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return UP shields.io config if request was successful and type='shields'", async () => {
|
||||||
|
mock.onPost("https://api.github.com/graphql").replyOnce(200, successData);
|
||||||
|
|
||||||
|
const { req, res } = faker({ type: "shields" }, {});
|
||||||
|
await up(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "application/json");
|
||||||
|
expect(res.send).toBeCalledWith(shields_up);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return DOWN shields.io config if all PATs are rate limited and type='shields'", async () => {
|
||||||
|
mock.onPost("https://api.github.com/graphql").reply(200, rate_limit_error);
|
||||||
|
|
||||||
|
const { req, res } = faker({ type: "shields" }, {});
|
||||||
|
await up(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "application/json");
|
||||||
|
expect(res.send).toBeCalledWith(shields_down);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return `true` if the first PAT is rate limited but the second PATs works", async () => {
|
||||||
|
mock
|
||||||
|
.onPost("https://api.github.com/graphql")
|
||||||
|
.replyOnce(200, rate_limit_error)
|
||||||
|
.onPost("https://api.github.com/graphql")
|
||||||
|
.replyOnce(200, successData);
|
||||||
|
|
||||||
|
const { req, res } = faker({}, {});
|
||||||
|
await up(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "application/json");
|
||||||
|
expect(res.send).toBeCalledWith(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return `true` if the first PAT has 'Bad credentials' but the second PAT works", async () => {
|
||||||
|
mock
|
||||||
|
.onPost("https://api.github.com/graphql")
|
||||||
|
.replyOnce(404, bad_credentials_error)
|
||||||
|
.onPost("https://api.github.com/graphql")
|
||||||
|
.replyOnce(200, successData);
|
||||||
|
|
||||||
|
const { req, res } = faker({}, {});
|
||||||
|
await up(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "application/json");
|
||||||
|
expect(res.send).toBeCalledWith(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return `false` if all pats have 'Bad credentials'", async () => {
|
||||||
|
mock
|
||||||
|
.onPost("https://api.github.com/graphql")
|
||||||
|
.reply(404, bad_credentials_error);
|
||||||
|
|
||||||
|
const { req, res } = faker({}, {});
|
||||||
|
await up(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "application/json");
|
||||||
|
expect(res.send).toBeCalledWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should throw an error if the request fails", async () => {
|
||||||
|
mock.onPost("https://api.github.com/graphql").networkError();
|
||||||
|
|
||||||
|
const { req, res } = faker({}, {});
|
||||||
|
await up(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "application/json");
|
||||||
|
expect(res.send).toBeCalledWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should have proper cache when no error is thrown", async () => {
|
||||||
|
mock.onPost("https://api.github.com/graphql").replyOnce(200, successData);
|
||||||
|
|
||||||
|
const { req, res } = faker({}, {});
|
||||||
|
await up(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader.mock.calls).toEqual([
|
||||||
|
["Content-Type", "application/json"],
|
||||||
|
["Cache-Control", `max-age=0, s-maxage=${RATE_LIMIT_SECONDS}`],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should have proper cache when error is thrown", async () => {
|
||||||
|
mock.onPost("https://api.github.com/graphql").networkError();
|
||||||
|
|
||||||
|
const { req, res } = faker({}, {});
|
||||||
|
await up(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader.mock.calls).toEqual([
|
||||||
|
["Content-Type", "application/json"],
|
||||||
|
["Cache-Control", "no-store"],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -18,6 +18,27 @@ export const themes = {
|
|||||||
text_color: "417E87",
|
text_color: "417E87",
|
||||||
bg_color: "ffffff00",
|
bg_color: "ffffff00",
|
||||||
},
|
},
|
||||||
|
shadow_red: {
|
||||||
|
title_color: "9A0000",
|
||||||
|
text_color: "444",
|
||||||
|
icon_color: "4F0000",
|
||||||
|
border_color: "4F0000",
|
||||||
|
bg_color: "ffffff00",
|
||||||
|
},
|
||||||
|
shadow_green: {
|
||||||
|
title_color: "007A00",
|
||||||
|
text_color: "444",
|
||||||
|
icon_color: "003D00",
|
||||||
|
border_color: "003D00",
|
||||||
|
bg_color: "ffffff00",
|
||||||
|
},
|
||||||
|
shadow_blue: {
|
||||||
|
title_color: "00779A",
|
||||||
|
text_color: "444",
|
||||||
|
icon_color: "004450",
|
||||||
|
border_color: "004490",
|
||||||
|
bg_color: "ffffff00",
|
||||||
|
},
|
||||||
dark: {
|
dark: {
|
||||||
title_color: "fff",
|
title_color: "fff",
|
||||||
icon_color: "79ff97",
|
icon_color: "79ff97",
|
||||||
@@ -374,6 +395,27 @@ export const themes = {
|
|||||||
border_color: "170F0C",
|
border_color: "170F0C",
|
||||||
bg_color: "170F0C",
|
bg_color: "170F0C",
|
||||||
},
|
},
|
||||||
|
one_dark_pro: {
|
||||||
|
title_color: "61AFEF",
|
||||||
|
text_color: "E5C06E",
|
||||||
|
icon_color: "C678DD",
|
||||||
|
border_color: "3B4048",
|
||||||
|
bg_color: "23272E",
|
||||||
|
},
|
||||||
|
rose: {
|
||||||
|
title_color: "8d192b",
|
||||||
|
text_color: "862931",
|
||||||
|
icon_color: "B71F36",
|
||||||
|
border_color: "e9d8d4",
|
||||||
|
bg_color: "e9d8d4",
|
||||||
|
},
|
||||||
|
holi_theme: {
|
||||||
|
title_color: "5FABEE",
|
||||||
|
text_color: "D6E7FF",
|
||||||
|
icon_color: "5FABEE",
|
||||||
|
border_color: "85A4C0",
|
||||||
|
bg_color: "030314",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default themes;
|
export default themes;
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
"functions": {
|
"functions": {
|
||||||
"api/*.js": {
|
"api/*.js": {
|
||||||
"memory": 128,
|
"memory": 128,
|
||||||
"maxDuration": 30
|
"maxDuration": 10
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"redirects": [
|
"redirects": [
|
||||||
|
|||||||
Reference in New Issue
Block a user