@@ -551,39 +551,34 @@ <h1 class="text-5xl font-bold mb-4" id="mainTitle">Our Amazing Contributors</h1>
551
551
timeout = setTimeout ( ( ) => func . apply ( this , args ) , wait ) ;
552
552
} ;
553
553
}
554
-
554
+
555
555
async function fetchGitHubData ( ) {
556
556
const headers = {
557
557
'Authorization' : `token ${ config . github . token } ` ,
558
- 'Accept' : 'application/vnd.github.v3 +json'
558
+ 'Accept' : 'application/vnd.github.inertia-preview +json'
559
559
} ;
560
560
561
561
try {
562
- // Fetch data only for the specific repository
563
- const [ repoData , contributors , prs ] = await Promise . all ( [
562
+ // Fetch data for the specific repository
563
+ const [ repoData , contributors , prs , projects ] = await Promise . all ( [
564
564
fetch ( `${ config . github . apiUrl } /repos/${ config . github . owner } /${ config . github . repo } ` , { headers } )
565
565
. then ( res => res . json ( ) ) ,
566
566
fetch ( `${ config . github . apiUrl } /repos/${ config . github . owner } /${ config . github . repo } /contributors` , { headers } )
567
567
. then ( res => res . json ( ) ) ,
568
568
fetch ( `${ config . github . apiUrl } /repos/${ config . github . owner } /${ config . github . repo } /pulls?state=all` , { headers } )
569
+ . then ( res => res . json ( ) ) ,
570
+ fetch ( `${ config . github . apiUrl } /repos/${ config . github . owner } /${ config . github . repo } /projects` , { headers } )
569
571
. then ( res => res . json ( ) )
570
572
] ) ;
571
573
572
574
// Check if the specific repository is archived or active
573
- const isActive = repoData . archived === false ;
574
- const activeProjectsCount = isActive ? 1 : 0 ;
575
-
576
- // Fetch commits from the default branch
577
- const defaultBranch = repoData . default_branch || 'main' ; // Fallback to 'main' if not provided
578
- const commits = await fetch (
579
- `${ config . github . apiUrl } /repos/${ config . github . owner } /${ config . github . repo } /commits?sha=${ defaultBranch } ` ,
580
- { headers }
581
- ) . then ( res => res . json ( ) ) ;
575
+ const isActive = ! repoData . archived ;
582
576
583
- const defaultBranchCommitsCount = Array . isArray ( commits ) ? commits . length : 0 ;
577
+ // Fetch total commit count from the repoData
578
+ const defaultBranchCommitsCount = repoData . commits || await getCommitCount ( repoData . default_branch ) ;
579
+ // Count the number of projects associated with the repository
580
+ const projectCount = Array . isArray ( projects ) ? projects . length : 0 ;
584
581
585
-
586
-
587
582
state . allContributors = contributors ;
588
583
updateFilterCounts ( contributors ) ;
589
584
@@ -595,7 +590,7 @@ <h1 class="text-5xl font-bold mb-4" id="mainTitle">Our Amazing Contributors</h1>
595
590
} ,
596
591
contributors . length ,
597
592
prs . length ,
598
- activeProjectsCount
593
+ projectCount
599
594
) ;
600
595
renderFilterButtons ( contributors . length ) ;
601
596
renderContributors ( contributors ) ;
@@ -605,6 +600,30 @@ <h1 class="text-5xl font-bold mb-4" id="mainTitle">Our Amazing Contributors</h1>
605
600
}
606
601
}
607
602
603
+ async function getCommitCount ( branch ) {
604
+ const headers = {
605
+ 'Authorization' : `token ${ config . github . token } ` ,
606
+ 'Accept' : 'application/vnd.github.v3+json'
607
+ } ;
608
+ const url = `${ config . github . apiUrl } /repos/${ config . github . owner } /${ config . github . repo } /commits?sha=${ branch } &per_page=100` ;
609
+ let page = 1 ;
610
+ let totalCommits = 0 ;
611
+
612
+ while ( true ) {
613
+ const response = await fetch ( `${ url } &page=${ page } ` , { headers } ) ;
614
+ const commits = await response . json ( ) ;
615
+
616
+ if ( ! Array . isArray ( commits ) || commits . length === 0 ) {
617
+ break ;
618
+ }
619
+
620
+ totalCommits += commits . length ;
621
+ page += 1 ;
622
+ }
623
+
624
+ return totalCommits ;
625
+ }
626
+
608
627
function renderStats ( repoData , contributorsCount , prsCount , activeProjectsCount ) {
609
628
const stats = [
610
629
{
@@ -634,7 +653,7 @@ <h1 class="text-5xl font-bold mb-4" id="mainTitle">Our Amazing Contributors</h1>
634
653
if ( ! statsContainer ) return ;
635
654
636
655
statsContainer . innerHTML = stats . map ( stat => createStatCard ( stat ) ) . join ( '' ) ;
637
- }
656
+ }
638
657
639
658
function createStatCard ( stat ) {
640
659
return `
0 commit comments