From fbaa6d17a563ed680726f927a2dd5690b05d7817 Mon Sep 17 00:00:00 2001 From: codebanditssss Date: Wed, 3 Jun 2026 21:57:38 +0530 Subject: [PATCH] feat: add github repo stats helper --- frontend/src/landing/lib/github-repo.ts | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 frontend/src/landing/lib/github-repo.ts diff --git a/frontend/src/landing/lib/github-repo.ts b/frontend/src/landing/lib/github-repo.ts new file mode 100644 index 000000000..801a703ad --- /dev/null +++ b/frontend/src/landing/lib/github-repo.ts @@ -0,0 +1,58 @@ +export interface GitHubRepoStats { + stars: number; + forks: number; + openIssues: number; + watchers: number; +} + +const FALLBACK_STATS: GitHubRepoStats = { + stars: 6295, + forks: 853, + openIssues: 622, + watchers: 21, +}; + +export async function getGitHubRepoStats(): Promise { + try { + const response = await fetch( + "https://api.github.com/repos/ComposioHQ/agent-orchestrator", + { + next: { revalidate: 3600 }, + headers: { + Accept: "application/vnd.github+json", + "User-Agent": "ao-website", + }, + }, + ); + + if (!response.ok) { + return FALLBACK_STATS; + } + + const data = (await response.json()) as { + stargazers_count?: number; + forks_count?: number; + open_issues_count?: number; + subscribers_count?: number; + }; + + return { + stars: data.stargazers_count ?? FALLBACK_STATS.stars, + forks: data.forks_count ?? FALLBACK_STATS.forks, + openIssues: data.open_issues_count ?? FALLBACK_STATS.openIssues, + watchers: data.subscribers_count ?? FALLBACK_STATS.watchers, + }; + } catch { + return FALLBACK_STATS; + } +} + +export function formatCompactNumber(value: number): string { + if (value >= 1_000_000) { + return `${(value / 1_000_000).toFixed(1)}m`; + } + if (value >= 1_000) { + return `${(value / 1_000).toFixed(1)}k`; + } + return String(value); +}