243 lines · 8.1 KB
import { Link } from "@tanstack/react-router";
import { CommitAuthor } from "./CommitAuthor";
import { Markdown } from "~/ui/Markdown";
import { Panel } from "~/ui/Panel";
import { RelativeTime } from "~/ui/RelativeTime";
import { StatusDot } from "~/ui/StatusDot";
import { buttonClass } from "~/ui/Button";
import { Breadcrumbs } from "./RefNavigation";
import { RefSwitcher } from "./RefSwitcher";
import { useLastCommits } from "~/hooks/use-last-commits";
import type { CommitSummary, StatusState, TreeEntry } from "~/lib/types";
import type { CommitBrief } from "~/lib/code-intel";

type Props = {
  owner: string;
  repo: string;
  gitRef: { kind: string; name: string; sha: string };
  path: string;
  entries: TreeEntry[];
  commit: CommitSummary & { authorAccount: string | null };
  commitStatus: StatusState | null;
  /** Latest workflow run for the commit; the status dot links to it, else to the commit's checks. */
  commitRun: number | null;
  readme: { path: string; html: string | null; text: string | null } | null;
  branches: string[];
  tags: string[];
  canWrite: boolean;
  /** The viewer may boot editor containers here (write access, containers on, plan includes them). */
  containersAllowed: boolean;
};

function EntryCommit({ commit }: { commit: CommitBrief | null | undefined }) {
  if (commit === undefined) return <span className="ml-auto h-3 w-24 animate-pulse rounded bg-gray-900" />;
  if (commit === null) return null;
  return (
    <span className="ml-auto flex min-w-0 items-center gap-3 font-sans text-xs text-gray-500">
      <span className="hidden max-w-md truncate md:inline">{commit.subject}</span>
      <span className="shrink-0">
        <RelativeTime timestamp={commit.committedAt} />
      </span>