mirror of
https://github.com/Snigdha-OS/Snigdha-OS.github.io.git
synced 2025-09-07 13:15:17 +02:00
🐛 fix: repository count
This commit is contained in:
@@ -19,17 +19,28 @@ export function StatsSection() {
|
|||||||
|
|
||||||
const fetchGitHubStats = async (username: string) => {
|
const fetchGitHubStats = async (username: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`https://api.github.com/users/${username}`);
|
const userResponse = await fetch(`https://api.github.com/users/${username}`);
|
||||||
const userData = await response.json();
|
const userData = await userResponse.json();
|
||||||
|
|
||||||
const reposResponse = await fetch(userData.repos_url);
|
const repos = [];
|
||||||
const reposData = await reposResponse.json();
|
let page = 1;
|
||||||
|
|
||||||
const starsCount = reposData.reduce((acc: number, repo: any) => acc + repo.stargazers_count, 0);
|
// Fetch all repositories using pagination
|
||||||
|
while (true) {
|
||||||
|
const reposResponse = await fetch(
|
||||||
|
`https://api.github.com/users/${username}/repos?per_page=100&page=${page}`
|
||||||
|
);
|
||||||
|
const reposPage = await reposResponse.json();
|
||||||
|
if (reposPage.length === 0) break;
|
||||||
|
repos.push(...reposPage);
|
||||||
|
page++;
|
||||||
|
}
|
||||||
|
|
||||||
|
const starsCount = repos.reduce((acc: number, repo: any) => acc + repo.stargazers_count, 0);
|
||||||
|
|
||||||
setStats([
|
setStats([
|
||||||
{ label: "Followers", value: `${userData.followers}`, icon: Users },
|
{ label: "Followers", value: `${userData.followers}`, icon: Users },
|
||||||
{ label: "Repositories", value: `${reposData.length}`, icon: Wrench },
|
{ label: "Repositories", value: `${repos.length}`, icon: Wrench },
|
||||||
{ label: "Stars", value: `${starsCount}`, icon: Star },
|
{ label: "Stars", value: `${starsCount}`, icon: Star },
|
||||||
]);
|
]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Reference in New Issue
Block a user