chadtmiller.com/pds.js
An atproto PDS in JavaScript, for Cloudflare Workers and Node
0
0
import { useQuery } from '@tanstack/react-query';
import { CheckDisclosure } from '#/components/molecules/check-disclosure.jsx';
import { EmptyState } from '#/components/molecules/empty-state.jsx';
import {
checkLook,
latestPerWorkflow,
loadChecks,
summarize,
summaryWords,
} from '#/lib/checks.js';
import { cn } from '#/lib/utils.js';
/**
* What the runner said about the commit this pull request ends on.
*
* The tip and nothing else, because this is the tab a reader opens to answer
* whether the work is ready, and that is a question about the tip. An earlier
* commit's runs are not lost: a commit the branch still carries says what its
* run said on the conversation and on its own page. What this does drop is a
* run against a commit a force-push replaced, which names something that is
* not in the branch and cannot be acted on.
*
* The runs come from the pull request rather than from this account's own
* repository: the runner checks the branch on the server that holds it, so
* the run names that copy. The runner itself comes from the repository's
* config, which is the one thing that says whose runs to read.
*/
export function PullChecks({ repo, checks, tip, space }) {
// Only for the runner, so the log behind a run can be fetched. The query
// key is the one the checks page uses, so the two share a read.
const { data } = useQuery({
queryKey: ['checks', repo, space ?? ''],
queryFn: () => loadChecks(repo, space),
});
const runs = latestPerWorkflow(checks.filter((run) => run.sha === tip));
if (runs.length === 0) {
return (
<div className="px-(--gutter) py-8">
<EmptyState
title="No checks on this commit"
description={
checks.length > 0
? 'The runner has checked this branch before but not what it ends on now. It may not have seen the last push yet.'
: "This repository's runner has published nothing about this branch. It may name no runner, or the runner may not watch this copy."
}
/>
</div>
);
}
const summary = summarize(runs);
const look = checkLook(summary?.status);
return (
<div className="px-(--gutter) py-4">
<section className="overflow-hidden rounded-md border border-border">
<div className="flex flex-wrap items-center gap-x-2.5 gap-y-1 border-border border-b bg-muted px-4 py-2.5">
<look.Icon className={cn('size-4 shrink-0', look.className)} />
<span className="font-semibold text-[13px] text-foreground">
{summaryWords(summary, runs)}
</span>
<code className="ml-auto font-mono text-[12px] text-faint">
{tip.slice(0, 8)}
</code>
</div>
{runs.map((run) => (
<CheckDisclosure
key={run.rkey ?? run.startedAt}
runner={data?.runner}
check={run}
runHref={
run.rkey
? `/${encodeURIComponent(repo)}/checks/${encodeURIComponent(run.rkey)}`
: undefined
}
/>
))}
</section>
</div>
);
}