Blame · Line-by-line history
gates.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 9989d86 | 1 | import { fetchJSON, postJSON } from './client'; |
| 2 | ||
| 3 | export type GateRunStatus = 'pending' | 'running' | 'passed' | 'failed' | 'error'; | |
| 4 | ||
| 5 | export interface GateRun { | |
| 6 | id: string; | |
| 7 | repositoryId: string; | |
| 8 | repoOwner: string; | |
| 9 | repoName: string; | |
| 10 | commitSha: string; | |
| 11 | branch: string; | |
| 12 | status: GateRunStatus; | |
| 13 | output: string | null; | |
| 14 | aiRepaired: boolean; | |
| 15 | repairedCommitSha: string | null; | |
| 16 | triggeredBy: string | null; | |
| 17 | startedAt: string; | |
| 18 | completedAt: string | null; | |
| 19 | createdAt: string; | |
| 20 | } | |
| 21 | ||
| 22 | export interface GateRepoSummary { | |
| 23 | repoOwner: string; | |
| 24 | repoName: string; | |
| 25 | latestRun: GateRun | null; | |
| 26 | totalRuns: number; | |
| 27 | passedRuns: number; | |
| 28 | failedRuns: number; | |
| 29 | } | |
| 30 | ||
| 31 | export interface GateSettings { | |
| 32 | gateTestEnabled: boolean; | |
| 33 | autoRepairEnabled: boolean; | |
| 34 | blockMergeOnFail: boolean; | |
| 35 | } | |
| 36 | ||
| 37 | /** List gate runs for a repository. */ | |
| 38 | export async function listGateRuns( | |
| 39 | owner: string, | |
| 40 | repo: string, | |
| 41 | page = 1, | |
| 42 | ): Promise<GateRun[]> { | |
| 43 | return fetchJSON<GateRun[]>( | |
| 44 | `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/gates?json=1&page=${page}`, | |
| 45 | ); | |
| 46 | } | |
| 47 | ||
| 48 | /** Get a single gate run. */ | |
| 49 | export async function getGateRun( | |
| 50 | owner: string, | |
| 51 | repo: string, | |
| 52 | runId: string, | |
| 53 | ): Promise<GateRun> { | |
| 54 | return fetchJSON<GateRun>( | |
| 55 | `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/gates/${encodeURIComponent(runId)}?json=1`, | |
| 56 | ); | |
| 57 | } | |
| 58 | ||
| 59 | /** Get gate summary for a repository. */ | |
| 60 | export async function getGateSummary( | |
| 61 | owner: string, | |
| 62 | repo: string, | |
| 63 | ): Promise<GateRepoSummary> { | |
| 64 | return fetchJSON<GateRepoSummary>( | |
| 65 | `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/gates/summary?json=1`, | |
| 66 | ); | |
| 67 | } | |
| 68 | ||
| 69 | /** Manually trigger a gate run on the default branch. */ | |
| 70 | export async function triggerGateRun( | |
| 71 | owner: string, | |
| 72 | repo: string, | |
| 73 | ): Promise<GateRun> { | |
| 74 | return postJSON<GateRun>( | |
| 75 | `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/gates/run`, | |
| 76 | {}, | |
| 77 | ); | |
| 78 | } | |
| 79 | ||
| 80 | /** Get gate settings for a repository. */ | |
| 81 | export async function getGateSettings( | |
| 82 | owner: string, | |
| 83 | repo: string, | |
| 84 | ): Promise<GateSettings> { | |
| 85 | return fetchJSON<GateSettings>( | |
| 86 | `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/gates/settings?json=1`, | |
| 87 | ); | |
| 88 | } | |
| 89 | ||
| 90 | /** Get the gate status for the current HEAD of a repository. */ | |
| 91 | export async function getLatestGateStatus( | |
| 92 | owner: string, | |
| 93 | repo: string, | |
| 94 | ): Promise<GateRun | null> { | |
| 95 | try { | |
| 96 | const runs = await listGateRuns(owner, repo, 1); | |
| 97 | return runs.length > 0 ? runs[0] : null; | |
| 98 | } catch { | |
| 99 | return null; | |
| 100 | } | |
| 101 | } | |
| 102 | ||
| 103 | /** List gate runs across all repos for the authenticated user (dashboard summary). */ | |
| 104 | export async function listAllGateRuns(username: string): Promise<GateRun[]> { | |
| 105 | return fetchJSON<GateRun[]>( | |
| 106 | `/api/users/${encodeURIComponent(username)}/gates?json=1`, | |
| 107 | ); | |
| 108 | } |