Compare commits

...
7 Commits
Author SHA1 Message Date
rjoydip c006a40f92 Merge branch 'master' into issue#287 2020-08-07 10:16:33 +05:30
rjoydip 1e2131b19b log changed as per request 2020-08-06 15:44:57 +05:30
rjoydip be47a1240a doc update 2020-08-05 12:48:41 +05:30
rjoydip b63c10f545 change logic as per the request 2020-08-05 12:37:01 +05:30
rjoydip 7d83fa413d doc updated 2020-08-04 12:57:50 +05:30
rjoydip d114fd8caf Merge branch 'master' into issue#287 2020-08-02 15:50:40 +05:30
rjoydip 0e830c0cc3 fix(#287): number of forks now available 2020-08-02 15:41:16 +05:30
8 changed files with 57 additions and 10 deletions
+2
View File
@@ -13,6 +13,7 @@ module.exports = async (req, res) => {
const {
username,
hide,
show_stats,
hide_title,
hide_border,
hide_rank,
@@ -57,6 +58,7 @@ module.exports = async (req, res) => {
res.send(
renderStatsCard(stats, {
hide: parseArray(hide),
show_stats: parseArray(show_stats),
show_icons: parseBoolean(show_icons),
hide_title: parseBoolean(hide_title),
hide_border: parseBoolean(hide_border),
+17 -5
View File
@@ -70,7 +70,7 @@ _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 separated values.
To hide any specific stats, you can pass a query parameter `hide=` with comma separated values.
> Options: `&hide=stars,commits,prs,issues,contribs`
@@ -78,6 +78,18 @@ To hide any specific stats, you can pass a query parameter `?hide=` with comma s
![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=contribs,prs)
```
### Showing individual stats
To hide any specific stats, you can pass a query parameter `show_stats=` with comma separated values.
> Options: `&show_stats=stars,commits,prs,issues,contribs`
```md
![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_stats=forks)
```
Note: `show_stats` is more prioritize than `hide`. That means if you add `prs` in both `&hide=prs` and `show_stats=prs` then pull request status will display.
### Adding private contributions count to total commits count
You can add the count of all your private contributions to the total commits count by using the query parameter `?count_private=true`.
@@ -120,7 +132,7 @@ You can look at a preview for [all available themes](./themes/README.md) or chec
You can customize the appearance of your `Stats Card` or `Repo Card` however you want with URL params.
#### Common Options:
#### Common Options
- `title_color` - Card's title color _(hex color)_
- `text_color` - Body text color _(hex color)_
@@ -131,7 +143,7 @@ You can customize the appearance of your `Stats Card` or `Repo Card` however you
> 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
#### Stats Card Exclusive Options:
#### Stats Card Exclusive Options
- `hide` - Hide's the specified items from stats _(Comma seperated values)_
- `hide_title` - _(boolean)_
@@ -141,11 +153,11 @@ You can customize the appearance of your `Stats Card` or `Repo Card` however you
- `count_private` - Count private commits _(boolean)_
- `line_height` - Sets the line-height between text _(number)_
#### Repo Card Exclusive Options:
#### Repo Card Exclusive Options
- `show_owner` - Show the owner name of the repo _(boolean)_
#### Language Card Exclusive Options:
#### Language Card Exclusive Options
- `hide` - Hide the languages specified from the card _(Comma seperated values)_
- `hide_title` - _(boolean)_
+11 -1
View File
@@ -51,9 +51,11 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
totalPRs,
contributedTo,
rank,
totalForkRepositories,
} = stats;
const {
hide = [],
show_stats = [],
show_icons = false,
hide_title = false,
hide_border = false,
@@ -67,6 +69,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
theme = "default",
} = options;
const new_hide = hide.concat(["forks"]);
const lheight = parseInt(line_height, 10);
// returns theme based colors with proper overrides and defaults
@@ -112,11 +115,18 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
value: contributedTo,
id: "contribs",
},
forks: {
icon: icons.fork,
label: "Total Forks",
value: totalForkRepositories,
id: "forks",
},
};
// filter out hidden stats defined by user & create the text nodes
const statItems = Object.keys(STATS)
.filter((key) => !hide.includes(key))
.filter((key) => !new_hide.includes(key))
.concat(show_stats)
.map((key, index) =>
// create the text nodes, and pass index so that we can calculate the line spacing
createTextNode({
+9 -1
View File
@@ -6,6 +6,9 @@ const githubUsernameRegex = require("github-username-regex");
require("dotenv").config();
const getRepositoriesArgs = (isFork = false) =>
`first: 100, ownerAffiliations: OWNER, isFork: ${isFork}, orderBy: {direction: DESC, field: STARGAZERS}`;
const fetcher = (variables, token) => {
return request(
{
@@ -30,7 +33,10 @@ const fetcher = (variables, token) => {
followers {
totalCount
}
repositories(first: 100, ownerAffiliations: OWNER, isFork: false, orderBy: {direction: DESC, field: STARGAZERS}) {
forkRepositories: repositories(${getRepositoriesArgs(true)}) {
totalCount
}
repositories(${getRepositoriesArgs()}) {
totalCount
nodes {
stargazers {
@@ -98,6 +104,7 @@ async function fetchStats(
totalStars: 0,
contributedTo: 0,
rank: { level: "C", score: 0 },
totalForkRepositories: 0
};
let res = await retryer(fetcher, { login: username });
@@ -117,6 +124,7 @@ async function fetchStats(
stats.name = user.name || user.login;
stats.totalIssues = user.issues.totalCount;
stats.totalForkRepositories = user.forkRepositories.totalCount;
stats.totalCommits =
contributionCount.totalCommitContributions + experimental_totalCommits;
+5 -2
View File
@@ -14,6 +14,7 @@ const stats = {
totalPRs: 400,
contributedTo: 500,
rank: null,
totalForkRepositories: 3
};
stats.rank = calculateRank({
totalCommits: stats.totalCommits,
@@ -37,6 +38,7 @@ const data = {
pullRequests: { totalCount: stats.totalPRs },
issues: { totalCount: stats.totalIssues },
followers: { totalCount: 0 },
forkRepositories: { totalCount: stats.totalForkRepositories },
repositories: {
totalCount: 1,
nodes: [{ stargazers: { totalCount: 100 } }],
@@ -106,7 +108,7 @@ describe("Test /api/", () => {
const { req, res } = faker(
{
username: "anuraghazra",
hide: "issues,prs,contribs",
hide: "issues,prs,contribs,forks",
show_icons: true,
hide_border: true,
line_height: 100,
@@ -123,7 +125,7 @@ describe("Test /api/", () => {
expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml");
expect(res.send).toBeCalledWith(
renderStatsCard(stats, {
hide: ["issues", "prs", "contribs"],
hide: ["issues", "prs", "contribs", "forks"],
show_icons: true,
hide_border: true,
line_height: 100,
@@ -207,6 +209,7 @@ describe("Test /api/", () => {
{
...stats,
totalCommits: stats.totalCommits + 100,
totalForkRepositories: 3,
rank: calculateRank({
totalCommits: stats.totalCommits + 100,
totalRepos: 1,
+4
View File
@@ -16,6 +16,7 @@ const data = {
pullRequests: { totalCount: 300 },
issues: { totalCount: 200 },
followers: { totalCount: 100 },
forkRepositories: { totalCount: 3 },
repositories: {
totalCount: 5,
nodes: [
@@ -70,6 +71,7 @@ describe("Test fetchStats", () => {
totalPRs: 300,
totalStars: 400,
rank,
totalForkRepositories: 3
});
});
@@ -103,6 +105,7 @@ describe("Test fetchStats", () => {
totalPRs: 300,
totalStars: 400,
rank,
totalForkRepositories: 3
});
});
@@ -131,6 +134,7 @@ describe("Test fetchStats", () => {
totalPRs: 300,
totalStars: 400,
rank,
totalForkRepositories: 3
});
});
});
+8
View File
@@ -18,6 +18,7 @@ describe("Test renderStatsCard", () => {
totalPRs: 400,
contributedTo: 500,
rank: { level: "A+", score: 40 },
totalForkRepositories: 3,
};
it("should render correctly", () => {
@@ -209,4 +210,11 @@ describe("Test renderStatsCard", () => {
queryByTestId(document.body, "stars").previousElementSibling // the label
).not.toHaveAttribute("x");
});
it("should render properly with show_stats flag", () => {
document.body.innerHTML = renderStatsCard(stats, {});
expect(queryByTestId(document.body, "forks")).toBeNull();
document.body.innerHTML = renderStatsCard(stats, { show_stats: "forks,others" });
expect(queryByTestId(document.body, "forks")).toBeDefined();
});
});
+1 -1
View File
@@ -32,7 +32,7 @@ describe("Test utils.js", () => {
expect(
queryByTestId(document.body, "message").children[0]
).toHaveTextContent(/Something went wrong/gim);
expect(queryByTestId(document.body, "message").children[1]).toBeEmpty(2);
expect(queryByTestId(document.body, "message").children[1]).toBeEmptyDOMElement(2);
// Secondary message
document.body.innerHTML = renderError(