Skip to content

Commit 3ac209d

Browse files
Add PR and Issues to card
1 parent d5fdfe1 commit 3ac209d

File tree

9 files changed

+132
-11
lines changed

9 files changed

+132
-11
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ body:
1515
required: true
1616
- type: textarea
1717
attributes:
18-
label: Expected behavior
18+
label: Expected behaviour
1919
description:
2020
A clear and concise description of what you expected to happen.
2121
- type: textarea

api/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default async (req, res) => {
1919
card_width,
2020
hide_rank,
2121
show_icons,
22+
count_private,
2223
include_all_commits,
2324
line_height,
2425
title_color,
@@ -52,6 +53,7 @@ export default async (req, res) => {
5253
try {
5354
const stats = await fetchStats(
5455
username,
56+
parseBoolean(count_private),
5557
parseBoolean(include_all_commits),
5658
parseArray(exclude_repo),
5759
);

api/pin.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export default async (req, res) => {
2020
bg_color,
2121
theme,
2222
show_owner,
23+
show_stars,
24+
show_forks,
25+
show_issues,
26+
show_pull_requests,
2327
cache_seconds,
2428
locale,
2529
border_radius,
@@ -55,9 +59,13 @@ export default async (req, res) => {
5559
*/
5660
const stars = repoData.starCount;
5761
const forks = repoData.forkCount;
58-
const isBothOver1K = stars > 1000 && forks > 1000;
59-
const isBothUnder1 = stars < 1 && forks < 1;
60-
if (!cache_seconds && (isBothOver1K || isBothUnder1)) {
62+
const issues = repoData.issuesCount;
63+
const pullRequests = repoData.pullRequestsCount;
64+
const isAllOver1K =
65+
stars > 1000 && forks > 1000 && issues > 1000 && pullRequests > 1000;
66+
const isAllUnder1 =
67+
stars < 1 && forks < 1 && issues < 1 && pullRequests < 1;
68+
if (!cache_seconds && (isAllOver1K || isAllUnder1)) {
6169
cacheSeconds = CONSTANTS.FOUR_HOURS;
6270
}
6371

@@ -79,6 +87,10 @@ export default async (req, res) => {
7987
border_radius,
8088
border_color,
8189
show_owner: parseBoolean(show_owner),
90+
show_stars: parseBoolean(show_stars),
91+
show_forks: parseBoolean(show_forks),
92+
show_issues: parseBoolean(show_issues),
93+
show_pull_requests: parseBoolean(show_pull_requests),
8294
locale: locale ? locale.toLowerCase() : null,
8395
}),
8496
);

src/cards/repo-card.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ const renderRepoCard = (repo, options = {}) => {
9696
isTemplate,
9797
starCount,
9898
forkCount,
99+
issuesCount,
100+
pullRequestsCount,
99101
} = repo;
100102
const {
101103
hide_border = false,
@@ -108,6 +110,10 @@ const renderRepoCard = (repo, options = {}) => {
108110
border_radius,
109111
border_color,
110112
locale,
113+
show_stars = true,
114+
show_forks = true,
115+
show_issues = false,
116+
show_pull_requests = false,
111117
} = options;
112118

113119
const lineHeight = 10;
@@ -146,15 +152,34 @@ const renderRepoCard = (repo, options = {}) => {
146152

147153
const totalStars = kFormatter(starCount);
148154
const totalForks = kFormatter(forkCount);
155+
const totalIssues = kFormatter(issuesCount);
156+
const totalPullRequests = kFormatter(pullRequestsCount);
157+
149158
const svgStars = iconWithLabel(icons.star, totalStars, "stargazers");
150159
const svgForks = iconWithLabel(icons.fork, totalForks, "forkcount");
151-
152-
const starAndForkCount = flexLayout({
153-
items: [svgLanguage, svgStars, svgForks],
160+
const svgIssues = iconWithLabel(icons.issues, totalIssues, "issuescount");
161+
const svgPullRequests = iconWithLabel(
162+
icons.prs,
163+
totalPullRequests,
164+
"pullrequestscount",
165+
);
166+
167+
const counters = flexLayout({
168+
items: [
169+
svgLanguage,
170+
...(show_stars ? [svgStars] : []),
171+
...(show_forks ? [svgForks] : []),
172+
...(show_issues ? [svgIssues] : []),
173+
...(show_pull_requests ? [svgPullRequests] : []),
174+
],
154175
sizes: [
155176
measureText(langName, 12),
156-
ICON_SIZE + measureText(`${totalStars}`, 12),
157-
ICON_SIZE + measureText(`${totalForks}`, 12),
177+
...(show_stars ? [ICON_SIZE + measureText(`${totalStars}`, 12)] : []),
178+
...(show_forks ? [ICON_SIZE + measureText(`${totalForks}`, 12)] : []),
179+
...(show_issues ? [ICON_SIZE + measureText(`${totalIssues}`, 12)] : []),
180+
...(show_pull_requests
181+
? [ICON_SIZE + measureText(`${totalPullRequests}`, 12)]
182+
: []),
158183
],
159184
gap: 25,
160185
}).join("");
@@ -195,7 +220,7 @@ const renderRepoCard = (repo, options = {}) => {
195220
</text>
196221
197222
<g transform="translate(30, ${height - 75})">
198-
${starAndForkCount}
223+
${counters}
199224
</g>
200225
`);
201226
};

src/fetchers/repo-fetcher.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ const fetcher = (variables, token) => {
2828
id
2929
name
3030
}
31-
forkCount
31+
forkCount,
32+
openIssues: issues(states: OPEN) {
33+
totalCount
34+
},
35+
openPullRequests: pullRequests(states:OPEN) {
36+
totalCount
37+
}
3238
}
3339
query getRepo($login: String!, $repo: String!) {
3440
user(login: $login) {
@@ -85,6 +91,8 @@ const fetchRepo = async (username, reponame) => {
8591
return {
8692
...data.user.repository,
8793
starCount: data.user.repository.stargazers.totalCount,
94+
issuesCount: data.user.repository.openIssues.totalCount,
95+
pullRequestsCount: data.user.repository.openPullRequests.totalCount,
8896
};
8997
}
9098

@@ -98,6 +106,8 @@ const fetchRepo = async (username, reponame) => {
98106
return {
99107
...data.organization.repository,
100108
starCount: data.organization.repository.stargazers.totalCount,
109+
issuesCount: data.organization.repository.openIssues.totalCount,
110+
pullRequestsCount: data.organization.repository.openPullRequests.totalCount,
101111
};
102112
}
103113
};

tests/api.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,38 @@ describe("Test /api/", () => {
238238
}
239239
});
240240

241+
it("should add private contributions", async () => {
242+
const { req, res } = faker(
243+
{
244+
username: "anuraghazra",
245+
count_private: true,
246+
},
247+
data_stats,
248+
);
249+
250+
await api(req, res);
251+
252+
expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml");
253+
expect(res.send).toBeCalledWith(
254+
renderStatsCard(
255+
{
256+
...stats,
257+
totalCommits: stats.totalCommits + 100,
258+
rank: calculateRank({
259+
totalCommits: stats.totalCommits + 100,
260+
totalRepos: 1,
261+
followers: 0,
262+
contributions: stats.contributedTo,
263+
stargazers: stats.totalStars,
264+
prs: stats.totalPRs,
265+
issues: stats.totalIssues,
266+
}),
267+
},
268+
{},
269+
),
270+
);
271+
});
272+
241273
it("should allow changing ring_color", async () => {
242274
const { req, res } = faker(
243275
{

tests/fetchRepo.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ const data_repo = {
1515
name: "TypeScript",
1616
},
1717
forkCount: 100,
18+
openIssues: {
19+
totalCount: 45,
20+
},
21+
openPullRequests: {
22+
totalCount: 10,
23+
},
1824
},
1925
};
2026

@@ -47,6 +53,8 @@ describe("Test fetchRepo", () => {
4753
expect(repo).toStrictEqual({
4854
...data_repo.repository,
4955
starCount: data_repo.repository.stargazers.totalCount,
56+
issuesCount: data_repo.repository.openIssues.totalCount,
57+
pullRequestsCount: data_repo.repository.openPullRequests.totalCount,
5058
});
5159
});
5260

@@ -57,6 +65,8 @@ describe("Test fetchRepo", () => {
5765
expect(repo).toStrictEqual({
5866
...data_repo.repository,
5967
starCount: data_repo.repository.stargazers.totalCount,
68+
issuesCount: data_repo.repository.openIssues.totalCount,
69+
pullRequestsCount: data_repo.repository.openPullRequests.totalCount,
6070
});
6171
});
6272

tests/pin.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ const data_repo = {
2121
name: "TypeScript",
2222
},
2323
forkCount: 100,
24+
openIssues: {
25+
totalCount: 45,
26+
},
27+
openPullRequests: {
28+
totalCOunt: 10,
29+
},
2430
isTemplate: false,
2531
},
2632
};
@@ -59,6 +65,8 @@ describe("Test /api/pin", () => {
5965
renderRepoCard({
6066
...data_repo.repository,
6167
starCount: data_repo.repository.stargazers.totalCount,
68+
issuesCount: data_repo.repository.openIssues.totalCount,
69+
pullRequestsCount: data_repo.repository.openPullRequests.totalCount,
6270
}),
6371
);
6472
});
@@ -89,6 +97,8 @@ describe("Test /api/pin", () => {
8997
{
9098
...data_repo.repository,
9199
starCount: data_repo.repository.stargazers.totalCount,
100+
issuesCount: data_repo.repository.openIssues.totalCount,
101+
pullRequestsCount: data_repo.repository.openPullRequests.totalCount,
92102
},
93103
{ ...req.query },
94104
),

tests/renderRepoCard.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const data_repo = {
1818
},
1919
starCount: 38000,
2020
forkCount: 100,
21+
issuesCount: 4500,
22+
pullRequestsCount: 10,
2123
},
2224
};
2325

@@ -52,6 +54,24 @@ describe("Test renderRepoCard", () => {
5254
);
5355
});
5456

57+
it("should display issues count", () => {
58+
document.body.innerHTML = renderRepoCard(data_repo.repository, {
59+
show_issues: true,
60+
});
61+
expect(queryByTestId(document.body, "issuescount")).toHaveTextContent(
62+
"4.5k",
63+
);
64+
});
65+
66+
it("should display pull requests count", () => {
67+
document.body.innerHTML = renderRepoCard(data_repo.repository, {
68+
show_pull_requests: true,
69+
});
70+
expect(queryByTestId(document.body, "pullrequestscount")).toHaveTextContent(
71+
"10",
72+
);
73+
});
74+
5575
it("should trim header", () => {
5676
document.body.innerHTML = renderRepoCard({
5777
...data_repo.repository,

0 commit comments

Comments
 (0)