Skip to content

Commit f2efd60

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 7fbc3d0 commit f2efd60

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

backend/src/fetchers/stats.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ const fetchStats = async (
408408
if (include_merged_pull_requests) {
409409
stats.totalPRsMerged = user.mergedPullRequests.totalCount;
410410
stats.mergedPRsPercentage =
411-
(user.mergedPullRequests.totalCount / user.pullRequests.totalCount) * 100;
411+
(user.mergedPullRequests.totalCount / user.pullRequests.totalCount) *
412+
100 || 0;
412413
}
413414
stats.totalReviews = user.reviews.totalPullRequestReviewContributions;
414415
stats.totalIssues = user.openIssues.totalCount + user.closedIssues.totalCount;

backend/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: {
@@ -512,4 +522,37 @@ describe("Test fetchStats", () => {
512522
rank,
513523
});
514524
});
525+
526+
it("should return correct data when user don't have any pull requests", async () => {
527+
mock.reset();
528+
mock
529+
.onPost("https://api.github.com/graphql")
530+
.reply(200, data_without_pull_requests);
531+
const stats = await fetchStats("anuraghazra", false, [], true);
532+
const rank = calculateRank({
533+
all_commits: false,
534+
commits: 100,
535+
prs: 0,
536+
reviews: 50,
537+
issues: 200,
538+
repos: 5,
539+
stars: 300,
540+
followers: 100,
541+
});
542+
543+
expect(stats).toStrictEqual({
544+
contributedTo: 61,
545+
name: "Anurag Hazra",
546+
totalCommits: 100,
547+
totalIssues: 200,
548+
totalPRs: 0,
549+
totalPRsMerged: 0,
550+
mergedPRsPercentage: 0,
551+
totalReviews: 50,
552+
totalStars: 300,
553+
totalDiscussionsStarted: 0,
554+
totalDiscussionsAnswered: 0,
555+
rank,
556+
});
557+
});
515558
});

0 commit comments

Comments
 (0)