forked from mirrored/github-readme-stats
change logic as per the request
This commit is contained in:
@@ -17,6 +17,7 @@ module.exports = async (req, res) => {
|
||||
hide_border,
|
||||
hide_rank,
|
||||
show_icons,
|
||||
show_forks,
|
||||
count_private,
|
||||
include_all_commits,
|
||||
line_height,
|
||||
@@ -61,6 +62,7 @@ module.exports = async (req, res) => {
|
||||
hide_title: parseBoolean(hide_title),
|
||||
hide_border: parseBoolean(hide_border),
|
||||
hide_rank: parseBoolean(hide_rank),
|
||||
show_forks: parseBoolean(show_forks),
|
||||
include_all_commits: parseBoolean(include_all_commits),
|
||||
line_height,
|
||||
title_color,
|
||||
|
||||
@@ -78,6 +78,14 @@ To hide any specific stats, you can pass a query parameter `?hide=` with comma s
|
||||

|
||||
```
|
||||
|
||||
### Show total forked repository count
|
||||
|
||||
To show forked repository count, you can pass a query parameter `show_forks=true`.
|
||||
|
||||
```md
|
||||

|
||||
```
|
||||
|
||||
### 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 +128,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 +139,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 +149,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)_
|
||||
|
||||
+12
-5
@@ -51,7 +51,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
||||
totalPRs,
|
||||
contributedTo,
|
||||
rank,
|
||||
totalForkRepositories
|
||||
totalForkRepositories,
|
||||
} = stats;
|
||||
const {
|
||||
hide = [],
|
||||
@@ -60,6 +60,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
||||
hide_border = false,
|
||||
hide_rank = false,
|
||||
include_all_commits = false,
|
||||
show_forks = false,
|
||||
line_height = 25,
|
||||
title_color,
|
||||
icon_color,
|
||||
@@ -86,6 +87,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
||||
label: "Total Stars",
|
||||
value: totalStars,
|
||||
id: "stars",
|
||||
isShowEnable: true,
|
||||
},
|
||||
commits: {
|
||||
icon: icons.commits,
|
||||
@@ -94,40 +96,45 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
||||
}`,
|
||||
value: totalCommits,
|
||||
id: "commits",
|
||||
isShowEnable: true,
|
||||
},
|
||||
prs: {
|
||||
icon: icons.prs,
|
||||
label: "Total PRs",
|
||||
value: totalPRs,
|
||||
id: "prs",
|
||||
isShowEnable: true,
|
||||
},
|
||||
issues: {
|
||||
icon: icons.issues,
|
||||
label: "Total Issues",
|
||||
value: totalIssues,
|
||||
id: "issues",
|
||||
isShowEnable: true,
|
||||
},
|
||||
contribs: {
|
||||
icon: icons.contribs,
|
||||
label: "Contributed to",
|
||||
value: contributedTo,
|
||||
id: "contribs",
|
||||
isShowEnable: true,
|
||||
},
|
||||
forks: {
|
||||
icon: icons.fork,
|
||||
label: "Total Forks",
|
||||
value: totalForkRepositories,
|
||||
id: "forks",
|
||||
isShowEnable: show_forks,
|
||||
},
|
||||
};
|
||||
|
||||
// filter out hidden stats defined by user & create the text nodes
|
||||
const statItems = Object.keys(STATS)
|
||||
.filter((key) => !hide.includes(key))
|
||||
.map((key, index) =>
|
||||
const statItems = Object.entries(STATS)
|
||||
.filter((item) => !hide.includes(item[0]) && item[1].isShowEnable)
|
||||
.map((item, index) =>
|
||||
// create the text nodes, and pass index so that we can calculate the line spacing
|
||||
createTextNode({
|
||||
...STATS[key],
|
||||
...STATS[item[0]],
|
||||
index,
|
||||
showIcons: show_icons,
|
||||
shiftValuePos: !include_all_commits,
|
||||
|
||||
@@ -18,7 +18,7 @@ describe("Test renderStatsCard", () => {
|
||||
totalPRs: 400,
|
||||
contributedTo: 500,
|
||||
rank: { level: "A+", score: 40 },
|
||||
totalForkRepositories: 3
|
||||
totalForkRepositories: 3,
|
||||
};
|
||||
|
||||
it("should render correctly", () => {
|
||||
@@ -30,12 +30,11 @@ describe("Test renderStatsCard", () => {
|
||||
|
||||
expect(
|
||||
document.body.getElementsByTagName("svg")[0].getAttribute("height")
|
||||
).toBe("220");
|
||||
).toBe("195");
|
||||
expect(getByTestId(document.body, "stars").textContent).toBe("100");
|
||||
expect(getByTestId(document.body, "commits").textContent).toBe("200");
|
||||
expect(getByTestId(document.body, "issues").textContent).toBe("300");
|
||||
expect(getByTestId(document.body, "prs").textContent).toBe("400");
|
||||
expect(getByTestId(document.body, "forks").textContent).toBe("3");
|
||||
expect(getByTestId(document.body, "contribs").textContent).toBe("500");
|
||||
expect(queryByTestId(document.body, "card-bg")).toBeInTheDocument();
|
||||
expect(queryByTestId(document.body, "rank-circle")).toBeInTheDocument();
|
||||
@@ -57,7 +56,7 @@ describe("Test renderStatsCard", () => {
|
||||
|
||||
it("should hide individual stats", () => {
|
||||
document.body.innerHTML = renderStatsCard(stats, {
|
||||
hide: ["issues", "prs", "contribs", "forks"],
|
||||
hide: ["issues", "prs", "contribs"],
|
||||
});
|
||||
|
||||
expect(
|
||||
@@ -69,7 +68,6 @@ describe("Test renderStatsCard", () => {
|
||||
expect(queryByTestId(document.body, "issues")).toBeNull();
|
||||
expect(queryByTestId(document.body, "prs")).toBeNull();
|
||||
expect(queryByTestId(document.body, "contribs")).toBeNull();
|
||||
expect(queryByTestId(document.body, "forks")).toBeNull();
|
||||
});
|
||||
|
||||
it("should hide_rank", () => {
|
||||
@@ -212,4 +210,11 @@ describe("Test renderStatsCard", () => {
|
||||
queryByTestId(document.body, "stars").previousElementSibling // the label
|
||||
).not.toHaveAttribute("x");
|
||||
});
|
||||
|
||||
it("should render properly with show_forks flag", () => {
|
||||
document.body.innerHTML = renderStatsCard(stats, { show_forks: false });
|
||||
expect(queryByTestId(document.body, "forks")).toBeNull();
|
||||
document.body.innerHTML = renderStatsCard(stats, { show_forks: true });
|
||||
expect(queryByTestId(document.body, "forks")).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user