File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff line change @@ -43,6 +43,16 @@ const data_stats = {
4343const data_year2003 = JSON . parse ( JSON . stringify ( data_stats ) ) ;
4444data_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+
4656const 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} ) ;
You can’t perform that action at this time.
0 commit comments