Skip to content

Commit c59f2a8

Browse files
webdev-mohdamirqwerty541
authored andcommitted
fix: display correct data when user don't have any pull requests (anuraghazra#4452)
* Fix: When user doesn't have any PR, it's Merged PRs Percentage is NAN (fixes anuraghazra#4449) * review --------- Co-authored-by: Alexandr <[email protected]>
1 parent abe30ee commit c59f2a8

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/fetchers/stats.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ const fetchStats = async (
306306
if (include_merged_pull_requests) {
307307
stats.totalPRsMerged = user.mergedPullRequests.totalCount;
308308
stats.mergedPRsPercentage =
309-
(user.mergedPullRequests.totalCount / user.pullRequests.totalCount) * 100;
309+
(user.mergedPullRequests.totalCount / user.pullRequests.totalCount) *
310+
100 || 0;
310311
}
311312
stats.totalReviews = user.reviews.totalPullRequestReviewContributions;
312313
stats.totalIssues = user.openIssues.totalCount + user.closedIssues.totalCount;

tests/fetchStats.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ const data_stats = {
4343
const data_year2003 = JSON.parse(JSON.stringify(data_stats));
4444
data_year2003.data.user.commits.totalCommitContributions = 428;
4545

46+
const data_without_pull_requests = {
47+
data: {
48+
user: {
49+
...data_stats.data.user,
50+
pullRequests: { totalCount: 0 },
51+
mergedPullRequests: { totalCount: 0 },
52+
},
53+
},
54+
};
55+
4656
const data_repo = {
4757
data: {
4858
user: {
@@ -471,4 +481,37 @@ describe("Test fetchStats", () => {
471481
rank,
472482
});
473483
});
484+
485+
it("should return correct data when user don't have any pull requests", async () => {
486+
mock.reset();
487+
mock
488+
.onPost("https://api.github.com/graphql")
489+
.reply(200, data_without_pull_requests);
490+
const stats = await fetchStats("anuraghazra", false, [], true);
491+
const rank = calculateRank({
492+
all_commits: false,
493+
commits: 100,
494+
prs: 0,
495+
reviews: 50,
496+
issues: 200,
497+
repos: 5,
498+
stars: 300,
499+
followers: 100,
500+
});
501+
502+
expect(stats).toStrictEqual({
503+
contributedTo: 61,
504+
name: "Anurag Hazra",
505+
totalCommits: 100,
506+
totalIssues: 200,
507+
totalPRs: 0,
508+
totalPRsMerged: 0,
509+
mergedPRsPercentage: 0,
510+
totalReviews: 50,
511+
totalStars: 300,
512+
totalDiscussionsStarted: 0,
513+
totalDiscussionsAnswered: 0,
514+
rank,
515+
});
516+
});
474517
});

0 commit comments

Comments
 (0)