g1t/apps/web/app/components/checks.tsx

35 lines1,454 bytesCodeBlame
1import { CircleCheck, CircleX, LoaderCircle, TriangleAlert } from "lucide-react";
2
3import type { CheckStatus } from "@g1t/contracts";
4
5/**
6 * What a pull request's own check status says. A pull request's checks are
7 * the workflows run on it (see the merge box); this is set when the merge
8 * queue took it out, and on older pull requests, by commands their issue
9 * once had run.
10 */
11const LABELS: Record<CheckStatus, string> = {
12 queued: "Checks queued",
13 running: "Checks running",
14 passed: "Checks passed",
15 failed: "Failed in the merge queue",
16 errored: "Checks could not run",
17};
18
19export function CheckIcon({ status, size = 15 }: { status: CheckStatus; size?: number }) {
20 if (status === "passed") return <CircleCheck size={size} className="shrink-0 text-accent" />;
21 if (status === "failed") return <CircleX size={size} className="shrink-0 text-danger" />;
22 if (status === "errored") return <TriangleAlert size={size} className="shrink-0 text-muted" />;
23 return <LoaderCircle size={size} className="shrink-0 animate-spin text-info" />;
24}
25
26/** The state of a pull request's checks at a glance, for lists. */
27export function CheckBadge({ status }: { status: CheckStatus | null }) {
28 if (!status) return null;
29 return (
30 <span className="flex shrink-0 items-center gap-1 text-xs text-muted" title={LABELS[status]}>
31 <CheckIcon status={status} size={13} />
32 <span className="sr-only">{LABELS[status]}</span>
33 </span>
34 );
35}