g1t/packages/contracts/src/automations.ts

47 lines1,396 bytesCodeBlame
1import type { User, Viewer } from "./identity";
2import type { RepoPath } from "./repos";
3import type { Result } from "./result";
4
5/**
6 * Rules in a repository's `.g1t/automations/` that act when something
7 * happens. Mirrors `crates/contracts/src/automations.rs`.
8 */
9
10export type StepResult = { step: string; ok: boolean; detail: string };
11
12export type AutomationRun = {
13 id: string;
14 automationId: string;
15 name: string;
16 /** An event type, `schedule` or `manual`. */
17 event: string;
18 number: number | null;
19 status: "running" | "succeeded" | "failed" | "skipped";
20 reason: string | null;
21 steps: StepResult[];
22 actor: string | null;
23 startedAt: string;
24};
25
26export type Automation = {
27 id: string;
28 repo: string;
29 path: string;
30 name: string;
31 /** What starts it, in words. */
32 trigger: string;
33 conditions: string[];
34 steps: string[];
35 enabled: boolean;
36 /** Why its file cannot be used. */
37 error: string | null;
38 manual: boolean;
39 lastRun: AutomationRun | null;
40};
41
42export interface AutomationsApi {
43 list(repo: RepoPath, viewer: Viewer): Promise<Result<Automation[]>>;
44 runs(repo: RepoPath, viewer: Viewer, automation?: string): Promise<Result<AutomationRun[]>>;
45 run(actor: User, repo: RepoPath, id: string, number?: number): Promise<Result<AutomationRun>>;
46 setEnabled(actor: User, repo: RepoPath, id: string, enabled: boolean): Promise<Result<Automation>>;
47}