import { useQuery } from '@tanstack/react-query'; import { CheckStatus } from '#/components/molecules/check-status.jsx'; import { loadChecks, loadRefChecks, summarize } from '#/lib/checks.js'; /** * The badge for the commit at the tip of a ref. The runner keeps a record * naming the latest run of each workflow for one ref, so this costs one * record read whatever the history's length. The run listing behind the other * badges reads a bounded number of pages, and a repository with more runs * than that loses its oldest badges. * * Both sources are filtered to the tip commit. A ref whose newest run is * against an earlier commit shows no badge, rather than reporting another * commit's result beside this one's sha. */ export function RefCheckStatus({ repo, refName, sha, className, space }) { const { data } = useQuery({ queryKey: ['ref-checks', repo, refName, space ?? ''], queryFn: () => loadRefChecks(repo, refName, space), }); const { data: listing } = useQuery({ queryKey: ['checks', repo, space ?? ''], queryFn: () => loadChecks(repo, space), }); const named = (data?.runs ?? []).filter((run) => run.sha === sha); const latest = named.length > 0 ? named : (listing?.bySha.get(sha) ?? []); return ( ); }