Compare commits

..
Author SHA1 Message Date
anuraghazra ee8d6a895d chore: add codecov.yml
Test / build (push) Canceled after 0s
2020-07-22 23:43:00 +05:30
anuraghazra 81ef90a96f docs: added codecov badge 2020-07-22 23:00:46 +05:30
anuraghazra 829b779f88 chore: added coverage in vercelignore 2020-07-22 22:56:37 +05:30
anuraghazra 7a6e608254 fix: workflow file 2020-07-22 22:51:30 +05:30
anuraghazra f84b708401 fix: workflow file 2020-07-22 22:50:38 +05:30
anuraghazra cf9dd0a715 chore: test codecov 2020-07-22 22:48:43 +05:30
21 changed files with 85 additions and 187 deletions
+1 -1
View File
@@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ["https://www.paypal.me/anuraghazra", "https://www.buymeacoffee.com/anuraghazra"] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
custom: ["https://www.paypal.me/anuraghazra"] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
-2
View File
@@ -2,6 +2,4 @@
.env
node_modules
package-lock.json
*.lock
.vscode/
coverage
+1 -2
View File
@@ -2,7 +2,6 @@ require("dotenv").config();
const {
renderError,
parseBoolean,
parseArray,
clampValue,
CONSTANTS,
} = require("../src/utils");
@@ -45,7 +44,7 @@ module.exports = async (req, res) => {
res.send(
renderStatsCard(stats, {
hide: parseArray(hide),
hide: JSON.parse(hide || "[]"),
show_icons: parseBoolean(show_icons),
hide_title: parseBoolean(hide_title),
hide_border: parseBoolean(hide_border),
+2 -3
View File
@@ -4,7 +4,6 @@ const {
parseBoolean,
clampValue,
CONSTANTS,
logger,
} = require("../src/utils");
const fetchRepo = require("../src/fetchRepo");
const renderRepoCard = require("../src/renderRepoCard");
@@ -29,7 +28,7 @@ module.exports = async (req, res) => {
try {
repoData = await fetchRepo(username, repo);
} catch (err) {
logger.error(err);
console.log(err);
return res.send(renderError(err.message));
}
@@ -53,7 +52,7 @@ module.exports = async (req, res) => {
}
res.setHeader("Cache-Control", `public, max-age=${cacheSeconds}`);
res.send(
renderRepoCard(repoData, {
title_color,
+2 -3
View File
@@ -3,7 +3,6 @@ const {
renderError,
clampValue,
parseBoolean,
parseArray,
CONSTANTS,
} = require("../src/utils");
const fetchTopLanguages = require("../src/fetchTopLanguages");
@@ -12,7 +11,7 @@ const renderTopLanguages = require("../src/renderTopLanguages");
module.exports = async (req, res) => {
const {
username,
hide,
hide_langs_below,
hide_title,
card_width,
title_color,
@@ -44,7 +43,7 @@ module.exports = async (req, res) => {
theme,
hide_title: parseBoolean(hide_title),
card_width: parseInt(card_width, 10),
hide: parseArray(hide),
hide_langs_below: parseFloat(hide_langs_below, 10),
title_color,
text_color,
bg_color,
-3
View File
@@ -7,7 +7,4 @@ coverage:
range: "70...100"
status:
project:
default:
threshold: 5
patch: false
-6
View File
@@ -15,15 +15,9 @@
"axios": "^0.19.2",
"axios-mock-adapter": "^1.18.1",
"css-to-object": "^1.1.0",
"husky": "^4.2.5",
"jest": "^26.1.0"
},
"dependencies": {
"dotenv": "^8.2.0"
},
"husky": {
"hooks": {
"pre-commit": "npm test"
}
}
}
+23 -23
View File
@@ -57,12 +57,12 @@ _Note: Ranks are calculated based on user's stats, see [src/calculateRank.js](./
### Hiding individual stats
To hide any specific stats, you can pass a query parameter `?hide=` with comma seperated values.
To hide any specific stats, you can pass a query parameter `?hide=` with an array of items you wanna hide.
> Options: `&hide=stars,commits,prs,issues,contribs`
> Options: `&hide=["stars","commits","prs","issues","contribs"]`
```md
![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=contribs,prs])
![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=["contribs","prs"])
```
### Showing icons
@@ -97,21 +97,21 @@ You can customize the appearance of your `Stats Card` or `Repo Card` however you
Customization Options:
| Option | type | description | Stats Card (default) | Repo Card (default) | Top Lang Card (default) |
| ------------- | --------- | ------------------------------------ | -------------------- | ------------------- | ----------------------- |
| title_color | hex color | title color | 2f80ed | 2f80ed | 2f80ed |
| text_color | hex color | body color | 333 | 333 | 333 |
| icon_color | hex color | icon color | 4c71f2 | 586069 | 586069 |
| bg_color | hex color | card bg color | FFFEFE | FFFEFE | FFFEFE |
| line_height | number | control the line-height between text | 30 | N/A | N/A |
| hide | CSV | hides the items specified | undefined | N/A | undefined |
| hide_rank | boolean | hides the ranking | false | N/A | N/A |
| hide_title | boolean | hides the stats title | false | N/A | false |
| hide_border | boolean | hides the stats card border | false | N/A | N/A |
| show_owner | boolean | shows owner name in repo card | N/A | false | N/A |
| show_icons | boolean | shows icons | false | N/A | N/A |
| theme | string | sets inbuilt theme | 'default' | 'default_repocard' | 'default |
| cache_seconds | number | manually set custom cache control | 1800 | 1800 | '1800' |
| Option | type | description | Stats Card (default) | Repo Card (default) | Top Lang Card (default) |
| ---------------- | --------- | ---------------------------------------------- | -------------------- | ------------------- | ----------------------- |
| title_color | hex color | title color | 2f80ed | 2f80ed | 2f80ed |
| text_color | hex color | body color | 333 | 333 | 333 |
| icon_color | hex color | icon color | 4c71f2 | 586069 | 586069 |
| bg_color | hex color | card bg color | FFFEFE | FFFEFE | FFFEFE |
| line_height | number | control the line-height between text | 30 | N/A | N/A |
| hide_rank | boolean | hides the ranking | false | N/A | N/A |
| hide_title | boolean | hides the stats title | false | N/A | false |
| hide_border | boolean | hides the stats card border | false | N/A | N/A |
| show_owner | boolean | shows owner name in repo card | N/A | false | N/A |
| show_icons | boolean | shows icons | false | N/A | N/A |
| theme | string | sets inbuilt theme | 'default' | 'default_repocard' | 'default |
| cache_seconds | number | manually set custom cache control | 1800 | 1800 | '1800' |
| hide_langs_below | number | hide langs below certain threshold (lang card) | N/A | N/A | undefined |
> Note on cache: Repo cards have default cache of 30mins (1800 seconds) if the fork count & star count is less than 1k otherwise it's 2hours (7200). Also note that cache is clamped to minimum of 30min and maximum of 24hours
@@ -155,12 +155,12 @@ Endpoint: `api/top-langs?username=anuraghazra`
[![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra)](https://github.com/anuraghazra/github-readme-stats)
```
### Hide individual languages
### Hide languages below certain threshold
You can use `?hide=language1,language2` parameter to hide individual languages.
You can use `?hide_langs_below=NUMBER` parameter to hide languages below a specified threshold percentage.
```md
[![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra&hide=javascript,html])](https://github.com/anuraghazra/github-readme-stats)
[![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra&hide_langs_below=1)](https://github.com/anuraghazra/github-readme-stats)
```
### Demo
@@ -177,11 +177,11 @@ You can use `?hide=language1,language2` parameter to hide individual languages.
- Hiding specific stats
![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=contribs,issues])
![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=["contribs","issues"])
- Showing icons
![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=issues&show_icons=true)
![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=["issues"]&show_icons=true)
- Themes
-1
View File
@@ -10,7 +10,6 @@ const fetcher = (variables, token) => {
nameWithOwner
isPrivate
isArchived
isTemplate
stargazers {
totalCount
}
+2 -2
View File
@@ -1,4 +1,4 @@
const { request, logger } = require("./utils");
const { request } = require("./utils");
const retryer = require("./retryer");
const calculateRank = require("./calculateRank");
require("dotenv").config();
@@ -61,7 +61,7 @@ async function fetchStats(username) {
let res = await retryer(fetcher, { login: username });
if (res.data.errors) {
logger.error(res.data.errors);
console.log(res.data.errors);
throw Error(res.data.errors[0].message || "Could not fetch user");
}
+2 -2
View File
@@ -1,4 +1,4 @@
const { request, logger } = require("./utils");
const { request } = require("./utils");
const retryer = require("./retryer");
require("dotenv").config();
@@ -38,7 +38,7 @@ async function fetchTopLanguages(username) {
let res = await retryer(fetcher, { login: username });
if (res.data.errors) {
logger.error(res.data.errors);
console.log(res.data.errors);
throw Error(res.data.errors[0].message || "Could not fetch user");
}
+18 -35
View File
@@ -14,7 +14,6 @@ const renderRepoCard = (repo, options = {}) => {
primaryLanguage,
stargazers,
isArchived,
isTemplate,
forkCount,
} = repo;
const {
@@ -27,8 +26,8 @@ const renderRepoCard = (repo, options = {}) => {
} = options;
const header = show_owner ? nameWithOwner : name;
const langName = (primaryLanguage && primaryLanguage.name) || "Unspecified";
const langColor = (primaryLanguage && primaryLanguage.color) || "#333";
const langName = primaryLanguage ? primaryLanguage.name : "Unspecified";
const langColor = primaryLanguage ? primaryLanguage.color : "#333";
const height = 120;
const shiftText = langName.length > 15 ? 0 : 30;
@@ -50,30 +49,22 @@ const renderRepoCard = (repo, options = {}) => {
const totalStars = kFormatter(stargazers.totalCount);
const totalForks = kFormatter(forkCount);
const getBadgeSVG = (label) => `
<g data-testid="badge" class="badge" transform="translate(320, 38)">
<rect stroke="${textColor}" stroke-width="1" width="70" height="20" x="-12" y="-14" ry="10" rx="10"></rect>
<text
x="23" y="-5"
alignment-baseline="central"
dominant-baseline="central"
text-anchor="middle"
fill="${textColor}"
>
${label}
</text>
</g>
`;
const svgLanguage = primaryLanguage
const archiveBadge = isArchived
? `
<g data-testid="primary-lang" transform="translate(30, 100)">
<circle data-testid="lang-color" cx="0" cy="-5" r="6" fill="${langColor}" />
<text data-testid="lang-name" class="gray" x="15">${langName}</text>
<g data-testid="archive-badge" class="archive-badge" transform="translate(320, 38)">
<rect stroke="${textColor}" stroke-width="1" width="70" height="20" x="-12" y="-14" ry="10" rx="10"></rect>
<text fill="${textColor}">Archived</text>
</g>
`
: "";
const svgLanguage = `
<g transform="translate(30, 100)">
<circle data-testid="lang-color" cx="0" cy="-5" r="6" fill="${langColor}" />
<text data-testid="lang" class="gray" x="15">${langName}</text>
</g>
`;
const svgStars =
stargazers.totalCount > 0 &&
`
@@ -99,30 +90,22 @@ const renderRepoCard = (repo, options = {}) => {
.description { font: 400 13px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${textColor} }
.gray { font: 400 12px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${textColor} }
.icon { fill: ${iconColor} }
.badge { font: 600 11px 'Segoe UI', Ubuntu, Sans-Serif; }
.badge rect { opacity: 0.2 }
.archive-badge { font: 600 12px 'Segoe UI', Ubuntu, Sans-Serif; }
.archive-badge rect { opacity: 0.2 }
</style>
<rect data-testid="card-bg" x="0.5" y="0.5" width="399" height="99%" rx="4.5" fill="${bgColor}" stroke="#E4E2E2"/>
<svg class="icon" x="25" y="25" viewBox="0 0 16 16" version="1.1" width="16" height="16">
${icons.contribs}
</svg>
<text x="50" y="38" class="header">${header}</text>
${archiveBadge}
${
isTemplate
? getBadgeSVG("Template")
: isArchived
? getBadgeSVG("Archived")
: ""
}
<text x="50" y="38" class="header">${header}</text>
<text class="description" x="25" y="70">${encodeHTML(desc)}</text>
${svgLanguage}
<g transform="translate(${primaryLanguage ? 155 - shiftText : 25}, 100)">
<g transform="translate(${155 - shiftText}, 100)">
${FlexLayout({ items: [svgStars, svgForks], gap: 65 }).join("")}
</g>
+9 -19
View File
@@ -23,8 +23,6 @@ const createProgressNode = ({ width, color, name, progress }) => {
`;
};
const lowercaseTrim = (name) => name.toLowerCase().trim();
const renderTopLanguages = (topLangs, options = {}) => {
const {
hide_title,
@@ -32,32 +30,24 @@ const renderTopLanguages = (topLangs, options = {}) => {
title_color,
text_color,
bg_color,
hide,
hide_langs_below,
theme,
} = options;
let langs = Object.values(topLangs);
let langsToHide = {};
// populate langsToHide map for quick lookup
// while filtering out
if (hide) {
hide.forEach((langName) => {
langsToHide[lowercaseTrim(langName)] = true;
});
}
// filter out langauges to be hidden
langs = langs
.sort((a, b) => b.size - a.size)
.filter((lang) => {
return !langsToHide[lowercaseTrim(lang.name)];
});
const totalSize = langs.reduce((acc, curr) => {
return acc + curr.size;
}, 0);
// hide langs
langs = langs
.sort((a, b) => b.size - a.size)
.filter((lang) => {
if (!hide_langs_below) return true;
return (lang.size / totalSize) * 100 > hide_langs_below;
});
// returns theme based colors with proper overrides and defaults
const { titleColor, textColor, bgColor } = getCardColors({
title_color,
+3 -5
View File
@@ -1,11 +1,9 @@
const { logger } = require("./utils");
const retryer = async (fetcher, variables, retries = 0) => {
if (retries > 7) {
throw new Error("Maximum retries exceeded");
}
try {
logger.log(`Trying PAT_${retries + 1}`);
console.log(`Trying PAT_${retries + 1}`);
// try to fetch with the first token since RETRIES is 0 index i'm adding +1
let response = await fetcher(
@@ -20,7 +18,7 @@ const retryer = async (fetcher, variables, retries = 0) => {
// if rate limit is hit increase the RETRIES and recursively call the retryer
// with username, and current RETRIES
if (isRateExceeded) {
logger.log(`PAT_${retries + 1} Failed`);
console.log(`PAT_${retries + 1} Failed`);
retries++;
// directly return from the function
return retryer(fetcher, variables, retries);
@@ -34,7 +32,7 @@ const retryer = async (fetcher, variables, retries = 0) => {
const isBadCredential = err.response.data && err.response.data.message === "Bad credentials";
if (isBadCredential) {
logger.log(`PAT_${retries + 1} Failed`);
console.log(`PAT_${retries + 1} Failed`);
retries++;
// directly return from the function
return retryer(fetcher, variables, retries);
-12
View File
@@ -44,11 +44,6 @@ function parseBoolean(value) {
}
}
function parseArray(str) {
if (!str) return [];
return str.split(",");
}
function clampValue(number, min, max) {
return Math.max(min, Math.min(number, max));
}
@@ -121,11 +116,6 @@ function getCardColors({
return { titleColor, iconColor, textColor, bgColor };
}
const fn = () => {};
// return console instance based on the environment
const logger =
process.env.NODE_ENV !== "test" ? console : { log: fn, error: fn };
const CONSTANTS = {
THIRTY_MINUTES: 1800,
TWO_HOURS: 7200,
@@ -138,12 +128,10 @@ module.exports = {
encodeHTML,
isValidHexColor,
request,
parseArray,
parseBoolean,
fallbackColor,
FlexLayout,
getCardColors,
clampValue,
logger,
CONSTANTS,
};
+1 -1
View File
@@ -98,7 +98,7 @@ describe("Test /api/", () => {
const { req, res } = faker(
{
username: "anuraghazra",
hide: "issues,prs,contribs",
hide: `["issues","prs","contribs"]`,
show_icons: true,
hide_border: true,
line_height: 100,
-1
View File
@@ -17,7 +17,6 @@ const data_repo = {
name: "TypeScript",
},
forkCount: 100,
isTemplate: false
},
};
+14 -50
View File
@@ -33,7 +33,7 @@ describe("Test renderRepoCard", () => {
);
expect(queryByTestId(document.body, "stargazers")).toHaveTextContent("38k");
expect(queryByTestId(document.body, "forkcount")).toHaveTextContent("100");
expect(queryByTestId(document.body, "lang-name")).toHaveTextContent(
expect(queryByTestId(document.body, "lang")).toHaveTextContent(
"TypeScript"
);
expect(queryByTestId(document.body, "lang-color")).toHaveAttribute(
@@ -82,7 +82,6 @@ describe("Test renderRepoCard", () => {
},
});
expect(queryByTestId(document.body, "primary-lang")).toBeInTheDocument();
expect(document.getElementsByTagName("g")[1]).toHaveAttribute(
"transform",
"translate(155, 100)"
@@ -103,30 +102,6 @@ describe("Test renderRepoCard", () => {
);
});
it("should hide language if primaryLanguage is null & fallback to correct values", () => {
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
primaryLanguage: null,
});
expect(queryByTestId(document.body, "primary-lang")).toBeNull();
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
primaryLanguage: { color: null, name: null },
});
expect(queryByTestId(document.body, "primary-lang")).toBeInTheDocument();
expect(queryByTestId(document.body, "lang-color")).toHaveAttribute(
"fill",
"#333"
);
expect(queryByTestId(document.body, "lang-name")).toHaveTextContent(
"Unspecified"
);
});
it("should render default colors properly", () => {
document.body.innerHTML = renderRepoCard(data_repo.repository);
@@ -242,6 +217,17 @@ describe("Test renderRepoCard", () => {
);
});
it("should render archive badge if repo is archived", () => {
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
isArchived: true,
});
expect(queryByTestId(document.body, "archive-badge")).toHaveTextContent(
"Archived"
);
});
it("should not render star count or fork count if either of the are zero", () => {
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
@@ -249,7 +235,7 @@ describe("Test renderRepoCard", () => {
});
expect(queryByTestId(document.body, "stargazers")).toBeNull();
expect(queryByTestId(document.body, "forkcount")).toBeInTheDocument();
expect(queryByTestId(document.body, "forkcount")).toBeDefined();
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
@@ -257,7 +243,7 @@ describe("Test renderRepoCard", () => {
forkCount: 0,
});
expect(queryByTestId(document.body, "stargazers")).toBeInTheDocument();
expect(queryByTestId(document.body, "stargazers")).toBeDefined();
expect(queryByTestId(document.body, "forkcount")).toBeNull();
document.body.innerHTML = renderRepoCard({
@@ -269,26 +255,4 @@ describe("Test renderRepoCard", () => {
expect(queryByTestId(document.body, "stargazers")).toBeNull();
expect(queryByTestId(document.body, "forkcount")).toBeNull();
});
it("should render badges", () => {
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
isArchived: true,
});
expect(queryByTestId(document.body, "badge")).toHaveTextContent("Archived");
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
isTemplate: true,
});
expect(queryByTestId(document.body, "badge")).toHaveTextContent("Template");
});
it("should not render template", () => {
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
});
expect(queryByTestId(document.body, "badge")).toBeNull();
});
});
+1 -1
View File
@@ -55,7 +55,7 @@ describe("Test renderStatsCard", () => {
it("should hide individual stats", () => {
document.body.innerHTML = renderStatsCard(stats, {
hide: ["issues", "prs", "contribs"],
hide: "['issues', 'prs', 'contribs']",
});
expect(
+5 -13
View File
@@ -58,26 +58,18 @@ describe("Test renderTopLanguages", () => {
);
});
it("should hide languages when hide is passed", () => {
it("should hide_langs_below", () => {
document.body.innerHTML = renderTopLanguages(langs, {
hide: ["HTML"],
hide_langs_below: 34,
});
expect(queryAllByTestId(document.body, "lang-name")[0]).toBeInTheDocument(
"javascript"
"HTML"
);
expect(queryAllByTestId(document.body, "lang-name")[1]).toBeInTheDocument(
"css"
);
expect(queryAllByTestId(document.body, "lang-name")[2]).not.toBeDefined();
// multiple languages passed
document.body.innerHTML = renderTopLanguages(langs, {
hide: ["HTML","css"],
});
expect(queryAllByTestId(document.body, "lang-name")[0]).toBeInTheDocument(
"javascript"
);
expect(queryAllByTestId(document.body, "lang-name")[1]).not.toBeDefined();
expect(queryAllByTestId(document.body, "lang-name")[2]).not.toBeDefined();
});
it("should resize the height correctly depending on langs", () => {
+1 -2
View File
@@ -1,9 +1,8 @@
require("@testing-library/jest-dom");
const retryer = require("../src/retryer");
const { logger } = require("../src/utils");
const fetcher = jest.fn((variables, token) => {
logger.log(variables, token);
console.log(variables, token);
return new Promise((res, rej) => res({ data: "ok" }));
});