import { gitContributors } from "@/client"; import type { ContributorStats } from "@/client"; import { RepoHeader } from "@/components/repository/header"; import { useQuery } from "@tanstack/react-query"; import { Hash, Loader2, Mail, Calendar } from "lucide-react"; import { useParams } from "react-router-dom"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; function formatDate(ts: number | null | undefined): string { if (!ts) return "—"; return new Date(ts * 1000).toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric", }); } function ContributorCard({ c }: { c: ContributorStats }) { const initials = c.name ? c.name .split(/\s+/) .slice(0, 2) .map((p) => p[0]) .join("") .toUpperCase() : c.email[0].toUpperCase(); return (
{initials}

{c.name || "—"}

{c.email}
{c.commits.toLocaleString()}
{formatDate(c.last_commit_at)}
); } export const RepoContributors = () => { const { namespace, repoName } = useParams<{ namespace: string; repoName: string }>(); const { data, isLoading } = useQuery({ queryKey: ["repo-contributors", namespace, repoName], queryFn: async () => { if (!namespace || !repoName) return null; const resp = await gitContributors({ path: { namespace, repo: repoName } }); return resp.data?.data ?? null; }, enabled: !!namespace && !!repoName, staleTime: 60 * 1000, }); const contributors: ContributorStats[] = data?.contributors ?? []; const total: number = data?.total ?? 0; if (isLoading) { return (
); } return ( <>

Contributors

{total} contributor{total !== 1 ? "s" : ""} — sorted by commit count

{contributors.length === 0 ? (

No contributors found

This repository has no commits yet.

) : (
{contributors.map((c) => ( ))}
)}
); };