diff --git a/contributors/contributors.js b/contributors/contributors.js index c7af093..6ffb5f7 100644 --- a/contributors/contributors.js +++ b/contributors/contributors.js @@ -6,6 +6,20 @@ const repoUrl = `https://api.github.com/repos/${repoOwner}/${repoName}`; async function fetchContributorData() { try { + // Fetch all contributors using pagination + const contributors = await fetchAllContributors(); + + // Fetch repository data (stars, forks, etc.) + const repoRes = await fetch(repoUrl); + const repoData = await repoRes.json(); + + // Render stats + renderStats(repoData, contributors); + + // Render contributors + renderContributors(contributors); + + // Fetch repository data to get star and fork counts const repoRes = await fetch(repoUrl); const repoData = await repoRes.json(); @@ -65,6 +79,7 @@ async function fetchContributorData() { `).join(''); + } catch (error) { console.error("Error fetching data:", error); } @@ -72,7 +87,55 @@ async function fetchContributorData() { } +// Fetch all contributors across multiple pages +async function fetchAllContributors() { + let contributors = []; + let page = 1; + let response; + + do { + response = await fetch(`${contributorsUrl}?page=${page}&per_page=100`); + const contributorsData = await response.json(); + contributors.push(...contributorsData); + page++; + } while (response.headers.get('link') && response.headers.get('link').includes('rel="next"')); // Check for "next" link in the header + + return contributors; +} + +// Render stats like total contributions, stars, forks, etc. +function renderStats(repoData, contributors) { + const statsGrid = document.getElementById("statsGrid"); + + statsGrid.innerHTML = ` +
Contributors
Total Contributions
GitHub Stars
Forks