pr_01m47d24b0e6n91zwymwxg0vpx/packages/contracts/src/automations.ts
| 1 | import type { User, Viewer } from "./identity"; |
| 2 | import type { RepoPath } from "./repos"; |
| 3 | import 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 | |
| 10 | export type StepResult = { step: string; ok: boolean; detail: string }; |
| 11 | |
| 12 | export 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 | |
| 26 | export 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 | |
| 42 | export 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 | } |