forked from mirrored/github-readme-stats
fix(#287): number of forks now available
This commit is contained in:
+9
-1
@@ -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;
|
||||
|
||||
@@ -51,6 +51,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
||||
totalPRs,
|
||||
contributedTo,
|
||||
rank,
|
||||
totalForkRepositories
|
||||
} = stats;
|
||||
const {
|
||||
hide = [],
|
||||
@@ -112,6 +113,12 @@ 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
|
||||
|
||||
+5
-2
@@ -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,
|
||||
|
||||
@@ -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
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@ describe("Test renderStatsCard", () => {
|
||||
totalPRs: 400,
|
||||
contributedTo: 500,
|
||||
rank: { level: "A+", score: 40 },
|
||||
totalForkRepositories: 3
|
||||
};
|
||||
|
||||
it("should render correctly", () => {
|
||||
@@ -29,11 +30,12 @@ describe("Test renderStatsCard", () => {
|
||||
|
||||
expect(
|
||||
document.body.getElementsByTagName("svg")[0].getAttribute("height")
|
||||
).toBe("195");
|
||||
).toBe("220");
|
||||
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();
|
||||
@@ -55,7 +57,7 @@ describe("Test renderStatsCard", () => {
|
||||
|
||||
it("should hide individual stats", () => {
|
||||
document.body.innerHTML = renderStatsCard(stats, {
|
||||
hide: ["issues", "prs", "contribs"],
|
||||
hide: ["issues", "prs", "contribs", "forks"],
|
||||
});
|
||||
|
||||
expect(
|
||||
@@ -67,6 +69,7 @@ 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", () => {
|
||||
|
||||
+1
-1
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user