~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/pds.js

An atproto PDS in JavaScript, for Cloudflare Workers and Node

0
0
main
49 lines · 1.6 KB Raw History
import { useQuery } from '@tanstack/react-query';
import { Link } from '#/components/atoms/link.jsx';
import {
  checkLook,
  loadChecks,
  summarize,
  summaryWords,
} from '#/lib/checks.js';
import { cn } from '#/lib/utils.js';

/**
 * How one commit's checks ended, as a fact in its header: the mark, the
 * words, and the way to the run that says why.
 *
 * A commit page is about the diff. What the runner did belongs to the run's
 * own page, which holds the log, so this says the one thing a reader wants
 * on the way past and links to the rest.
 *
 * Nothing is drawn when the repository names no runner, or the runner has
 * not reported on this commit.
 */
export function CommitCheckLine({ repo, sha, className, space }) {
  const { data } = useQuery({
    queryKey: ['checks', repo, space ?? ''],
    queryFn: () => loadChecks(repo, space),
  });
  const latest = data?.bySha.get(sha) ?? [];
  const summary = summarize(latest);
  if (!summary) return null;

  const look = checkLook(summary.status);
  // One workflow has a page of its own. Several have no one page but the
  // listing, which gathers every run under the commit it ran against.
  const only = latest.length === 1 && latest[0].rkey;
  const at = `/${encodeURIComponent(repo)}/checks`;

  return (
    <Link
      href={only ? `${at}/${encodeURIComponent(only)}` : at}
      className={cn(
        'flex items-center gap-1.5 text-faint no-underline hover:text-foreground',
        className,
      )}
    >
      <look.Icon className={cn('size-3.5 shrink-0', look.className)} />
      {summaryWords(summary, latest)}
    </Link>
  );
}