/** * One commit: its message, who wrote and committed it, its parents, the * people its trailers name (each a link to their page), and, when the * platform landed it, the landing's ask, answer and verdict. Below, the * files it changed against its first parent: a plain list from the * server, which the browser replaces with the file tree and the diffs * (`drawing`, from `client-code.tsx`). Unified by default; `?style=split` * sets the sides apart. */ import type { ChangedFile, CommitDiff, CommitView as Commit, Signature, } from "@repo/protocol/domain/code"; import { CreditRole } from "@repo/protocol/domain/credit"; import { Handle } from "@repo/protocol/ids"; import type { ProjectName } from "@repo/protocol/ids"; import { Match, Option, Schema } from "effect"; import type { DateTime } from "effect"; import type { ReactNode } from "react"; import { ProjectNav } from "../project/project-nav.tsx"; import { ID, LABEL, LINK } from "../shared/classes.ts"; import { HandleLink } from "../shared/handle.tsx"; import { PageShell } from "../shared/layout.tsx"; import { OutcomeView } from "../shared/outcome.tsx"; import { answerPath, askPath } from "../shared/paths.ts"; import { When } from "../shared/time.tsx"; import { askOf } from "../why/rows.ts"; import { blobHref, commitHref, shortSha, treeHref } from "./paths.ts"; const isRole = Schema.is(CreditRole); const isHandle = Schema.is(Handle); /** Each change as its mark says it. */ const statusWords = Match.type().pipe( Match.when("added", () => ({ mark: "A", words: "added" })), Match.when("modified", () => ({ mark: "M", words: "modified" })), Match.when("deleted", () => ({ mark: "D", words: "deleted" })), Match.exhaustive ); /** The body without the trailer lines shown apart below it. */ const bodyWithoutTrailers = (commit: Commit) => { const trailers = new Set( commit.trailers.map(({ key, value }) => `${key}: ${value}`) ); return commit.body .split("\n") .filter((line) => !trailers.has(line.trim())) .join("\n") .trim(); }; const Person = ({ label, now, signature, }: { readonly label: string; readonly now: DateTime.Utc; readonly signature: Signature; }) => (
{label}
{signature.name}{" "}
); /** * The person a credit trailer names on a landing: its value's handle, * before any ` ` (`Asked-by: ines-v `). Only the * platform's own landings name its people; an imported commit's * `Signed-off-by:` names someone elsewhere, never a page here. */ const personIn = (landed: boolean, name: string, value: string) => { const handle = value.replace(/\s*<[^>]*>$/u, ""); return landed && isRole(name) && isHandle(handle) ? handle : undefined; }; /** A trailer: a landing's credit links the person; any other reads as written. */ const Trailer = ({ landed, name, value, }: { readonly landed: boolean; readonly name: string; readonly value: string; }) => { const person = personIn(landed, name, value); return (
  • {name}:{" "} {person === undefined ? value : }
  • ); }; /** The changed files by path, each linking its new version (or its old one, deleted). */ export const ChangedList = ({ commit, files, project, }: { readonly commit: Commit; readonly files: readonly ChangedFile[]; readonly project: ProjectName; }) => (
      {files.map((file) => { const { mark, words } = statusWords(file.status); const at = file.status === "deleted" ? commit.parents[0] : commit.sha; return (
    • {mark} {at === undefined ? ( {file.path} ) : ( {file.path} )}
    • ); })}
    ); export const CommitView = ({ diff, drawing, now, project, split = false, }: { readonly diff: CommitDiff; /** * The browser's file tree and diffs, holding `ChangedList` as their * fallback; the list alone when absent. */ readonly drawing?: ReactNode; readonly now: DateTime.Utc; readonly project: ProjectName; /** `?style=split`: old and new side by side. */ readonly split?: boolean; }) => { const { commit, files, truncated } = diff; const { landing } = commit; const linked = landing === undefined ? undefined : Option.getOrUndefined(askOf(landing)); const body = bodyWithoutTrailers(commit); const here = commitHref(project, commit.sha); return (

    commit {commit.sha} ·{" "} Browse files

    {body === "" ? null : (
                {body}
              
    )}
    {commit.parents.length === 1 ? "Parent" : "Parents"}
    {commit.parents.length === 0 ? "none: the first commit" : commit.parents.map((parent) => ( {shortSha(parent)} ))}
    {commit.trailers.length === 0 ? null : (

    Trailers

      {commit.trailers.map(({ key, value }) => ( ))}
    )}
    {landing === undefined ? (

    The platform did not land this commit: it came in with the history the project adopted (before adoption).

    ) : (

    Landing

    {linked === undefined ? null : ( <>
    {linked.kind === "opened" ? "Opened" : "Ask"}
    {linked.ask}
    {linked.kind === "opened" ? null : ( )} )}
    Author
    Landed
    {landing.verdict === undefined ? null : ( )}
    )}

    {files.length} {files.length === 1 ? "file" : "files"} changed

    {split ? ( Unified ) : ( Split )}

    {truncated ? (

    This commit is too large to show whole: its files are listed by path, without their changes.

    ) : null} {drawing === undefined || truncated ? ( ) : ( drawing )}
    ); };