import type { Id, Outcome, Timestamp } from "./common.ts"; export type CiRunState = "queued" | "waiting_image" | "running" | "waiting_approval" | "succeeded" | "failed" | "cancelled" | "timed_out"; export type CiJobState = "pending" | "waiting_image" | "waiting_approval" | "queued" | "running" | "succeeded" | "failed" | "skipped" | "cancelled" | "timed_out"; export type CiTrigger = "push" | "pull_request" | "manual"; export interface CiRunSummary { readonly id: string; readonly sha: string; /** The branch the run checked out, without `refs/heads/`. */ readonly branch: string; readonly trigger: CiTrigger; readonly pull: number | null; readonly state: CiRunState; readonly trusted: boolean; /** Why the run is trusted or not, in one sentence. */ readonly trustReason: string; readonly actor: { readonly kind: "human" | "agent" | "system"; readonly name: string | null }; readonly supersededBy: string | null; readonly createdAt: Timestamp; readonly endedAt: Timestamp | null; } /** The result of every run of one commit, for the dot beside it: red when one failed, amber while one runs, green when all succeeded. */ export type CommitCheck = { readonly state: "failed" | "running" | "succeeded"; readonly label: string; readonly href: string }; export interface CiJob { readonly name: string; readonly state: CiJobState; readonly reason: string | null; readonly environment: string | null; readonly image: string; readonly steps: readonly string[]; readonly exitCode: number | null; readonly failedStep: number | null; readonly startedAt: Timestamp | null; readonly endedAt: Timestamp | null; } export interface CiRunDetail extends CiRunSummary { readonly jobs: readonly CiJob[]; } /** The output of one step. Step 0 sets the job up; step n is the job's step n. Times are in milliseconds. */ export interface CiStepLog { readonly step: number; readonly text: string; readonly startedAt: number | null; readonly endedAt: number | null; } export interface CiSecret { readonly name: string; /** Null for a repository or organization secret. */ readonly environment: string | null; readonly updatedAt: Timestamp; readonly updatedBy: string; } export interface CiEnvironment { readonly name: string; readonly requiresApproval: boolean; readonly waitSeconds: number; /** Branch patterns that may deploy to it. Empty allows every branch. */ readonly branches: readonly string[]; } export interface CiSecretInput { readonly name: string; readonly value: string; readonly environment: string | null; } /** The CI runs of one repository. Who can see the repository can see its runs and their masked logs. */ export interface RepoCi { /** True when the actor may start and cancel runs. */ readonly canRun: boolean; /** True when the actor may approve a job. Only a person with write access may; an agent never may. */ readonly canApprove: boolean; runs(query?: { readonly pull?: number; readonly sha?: string; readonly limit?: number }): Promise; /** Throws `not_found` when the run is not this repository's. */ run(id: string): Promise; /** The masked output of one job, split by step, and the sequence number of the run's last log line. */ logs(id: string, job: string): Promise<{ readonly steps: readonly CiStepLog[]; readonly seq: number }>; /** A server-sent event stream of `status` and `log` events for one run. */ events(id: string): Promise; /** Starts a run on the tip of a branch. A person's run is trusted; an agent's run is not. */ start(branch: string): Promise>; decide(id: string, job: string, decision: "approved" | "rejected"): Promise; cancel(id: string): Promise; } /** A repository's CI settings: its secrets, its environments, and the branches whose pushes get every secret. */ export interface CiSettings { secrets(): Promise; /** Creates or replaces a secret. The value is sealed at once and never shown again. */ setSecret(input: CiSecretInput): Promise; deleteSecret(name: string, environment: string | null): Promise; environments(): Promise; saveEnvironment(input: CiEnvironment): Promise; /** Deletes the environment and its secrets. */ deleteEnvironment(name: string): Promise; protectedBranches(): Promise; setProtectedBranches(patterns: readonly string[]): Promise; } /** Secrets every repository of a namespace can use. A repository or environment secret of the same name wins. */ export interface NamespaceSecrets { readonly namespace: string; list(): Promise; setSecret(input: Omit): Promise; deleteSecret(name: Id): Promise; }