Skip to content
refs
History
113 lines · 4.7 KBRaw
1import type { Id, Outcome, Timestamp } from "./common.ts";
2
3export type CiRunState = "queued" | "waiting_image" | "running" | "waiting_approval" | "succeeded" | "failed" | "cancelled" | "timed_out";
4export type CiJobState = "pending" | "waiting_image" | "waiting_approval" | "queued" | "running" | "succeeded" | "failed" | "skipped" | "cancelled" | "timed_out";
5export type CiTrigger = "push" | "pull_request" | "manual";
6
7export interface CiRunSummary {
8 readonly id: string;
9 readonly sha: string;
10 /** The branch the run checked out, without `refs/heads/`. */
11 readonly branch: string;
12 readonly trigger: CiTrigger;
13 readonly pull: number | null;
14 readonly state: CiRunState;
15 readonly trusted: boolean;
16 /** Why the run is trusted or not, in one sentence. */
17 readonly trustReason: string;
18 readonly actor: { readonly kind: "human" | "agent" | "system"; readonly name: string | null };
19 readonly supersededBy: string | null;
20 readonly createdAt: Timestamp;
21 readonly endedAt: Timestamp | null;
22}
23
24/** 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. */
25export type CommitCheck = { readonly state: "failed" | "running" | "succeeded"; readonly label: string; readonly href: string };
26
27export interface CiJob {
28 readonly name: string;
29 readonly state: CiJobState;
30 readonly reason: string | null;
31 readonly environment: string | null;
32 readonly image: string;
33 readonly steps: readonly string[];
34 readonly exitCode: number | null;
35 readonly failedStep: number | null;
36 readonly startedAt: Timestamp | null;
37 readonly endedAt: Timestamp | null;
38}
39
40export interface CiRunDetail extends CiRunSummary {
41 readonly jobs: readonly CiJob[];
42}
43
44/** The output of one step. Step 0 sets the job up; step n is the job's step n. Times are in milliseconds. */
45export interface CiStepLog {
46 readonly step: number;
47 readonly text: string;
48 readonly startedAt: number | null;
49 readonly endedAt: number | null;
50}
51
52export interface CiSecret {
53 readonly name: string;
54 /** Null for a repository or organization secret. */
55 readonly environment: string | null;
56 readonly updatedAt: Timestamp;
57 readonly updatedBy: string;
58}
59
60export interface CiEnvironment {
61 readonly name: string;
62 readonly requiresApproval: boolean;
63 readonly waitSeconds: number;
64 /** Branch patterns that may deploy to it. Empty allows every branch. */
65 readonly branches: readonly string[];
66}
67
68export interface CiSecretInput {
69 readonly name: string;
70 readonly value: string;
71 readonly environment: string | null;
72}
73
74/** The CI runs of one repository. Who can see the repository can see its runs and their masked logs. */
75export interface RepoCi {
76 /** True when the actor may start and cancel runs. */
77 readonly canRun: boolean;
78 /** True when the actor may approve a job. Only a person with write access may; an agent never may. */
79 readonly canApprove: boolean;
80 runs(query?: { readonly pull?: number; readonly sha?: string; readonly limit?: number }): Promise<CiRunSummary[]>;
81 /** Throws `not_found` when the run is not this repository's. */
82 run(id: string): Promise<CiRunDetail>;
83 /** The masked output of one job, split by step, and the sequence number of the run's last log line. */
84 logs(id: string, job: string): Promise<{ readonly steps: readonly CiStepLog[]; readonly seq: number }>;
85 /** A server-sent event stream of `status` and `log` events for one run. */
86 events(id: string): Promise<Response>;
87 /** Starts a run on the tip of a branch. A person's run is trusted; an agent's run is not. */
88 start(branch: string): Promise<Outcome<{ readonly runId: string }>>;
89 decide(id: string, job: string, decision: "approved" | "rejected"): Promise<Outcome>;
90 cancel(id: string): Promise<Outcome>;
91}
92
93/** A repository's CI settings: its secrets, its environments, and the branches whose pushes get every secret. */
94export interface CiSettings {
95 secrets(): Promise<CiSecret[]>;
96 /** Creates or replaces a secret. The value is sealed at once and never shown again. */
97 setSecret(input: CiSecretInput): Promise<Outcome>;
98 deleteSecret(name: string, environment: string | null): Promise<Outcome>;
99 environments(): Promise<CiEnvironment[]>;
100 saveEnvironment(input: CiEnvironment): Promise<Outcome>;
101 /** Deletes the environment and its secrets. */
102 deleteEnvironment(name: string): Promise<Outcome>;
103 protectedBranches(): Promise<string[]>;
104 setProtectedBranches(patterns: readonly string[]): Promise<Outcome>;
105}
106
107/** Secrets every repository of a namespace can use. A repository or environment secret of the same name wins. */
108export interface NamespaceSecrets {
109 readonly namespace: string;
110 list(): Promise<CiSecret[]>;
111 setSecret(input: Omit<CiSecretInput, "environment">): Promise<Outcome>;
112 deleteSecret(name: Id): Promise<Outcome>;
113}