48 lines · 1.3 KB
import type { CommitSummary } from "./types";

export type CommitBrief = Pick<CommitSummary, "sha" | "shortSha" | "subject" | "authorName" | "committedAt">;

export function toBrief(commit: CommitSummary): CommitBrief {
  return {
    sha: commit.sha,
    shortSha: commit.shortSha,
    subject: commit.subject,
    authorName: commit.authorName,
    committedAt: commit.committedAt,
  };
}

/** A run of consecutive final-version lines (0-based `start`) attributed to one commit. */
export type BlameRange = { start: number; count: number; sha: string };

export type BlameResult = {
  lines: string[];
  ranges: BlameRange[];
  commits: Record<string, CommitBrief>;
};

export type CodeSearchHit = {
  owner: string;
  repo: string;
  ref: string;
  path: string;
  snippet: string;
};

export const SNIPPET_OPEN = "\u0001";
export const SNIPPET_CLOSE = "\u0002";

export type NotebookOutput = { id: number } & (
  | { kind: "text"; text: string; stderr: boolean }
  | { kind: "image"; mime: string; data: string }
  | { kind: "error"; text: string }
);