Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
190 linesCodeBlameRaw
1import type { User, Viewer } from "./identity";
2import type { RepoPath } from "./repos";
3import type { Result } from "./result";
4
5/**
6 * Events, delivered to the addresses a repository or a workspace registers.
7 * Mirrors `crates/contracts/src/webhooks.rs`.
8 */
9
10/** Every event a webhook can be sent, in the order people are shown them. */
11export const EVENT_TYPES = [
12 "git.push",
13 "git.deleted",
14 "branch.renamed",
15 "repo.created",
16 "repo.forked",
17 "repo.updated",
18 "repo.visibility_changed",
19 "repo.renamed",
20 "repo.transferred",
21 "repo.default_branch_changed",
22 "repo.archived",
23 "repo.unarchived",
24 "repo.deleted",
25 "repo.restored",
26 "repo.purged",
27 "repo.collaborator_added",
28 "repo.collaborator_removed",
29 "repo.collaborator_role_changed",
30 "team.created",
31 "team.edited",
32 "team.deleted",
33 "team.member_added",
34 "team.member_role_changed",
35 "team.member_removed",
36 "team.repo_added",
37 "team.repo_role_changed",
38 "team.repo_removed",
39 "workspace.member_joined",
40 "ruleset.created",
41 "ruleset.updated",
42 "ruleset.deleted",
43 "issue.opened",
44 "issue.updated",
45 "issue.assigned",
46 "issue.labeled",
47 "issue.unlabeled",
48 "issue.milestoned",
49 "issue.demilestoned",
50 "issue.closed",
51 "issue.reopened",
52 "comment.created",
53 "comment.edited",
54 "comment.deleted",
55 "pull.opened",
56 "pull.ready",
57 "pull.updated",
58 "pull.merge_requested",
59 "pull.merged",
60 "pull.closed",
61 "pull.reopened",
62 "pull.converted_to_draft",
63 "pull.assigned",
64 "pull.review_requested",
65 "pull.review_request_removed",
66 "pull.labeled",
67 "pull.unlabeled",
68 "pull.milestoned",
69 "pull.demilestoned",
70 "pull.base_changed",
71 "pull.stalled",
72 "pull.resumed",
73 "release.created",
74 "release.published",
75 "release.released",
76 "release.prereleased",
77 "release.edited",
78 "release.unpublished",
79 "release.deleted",
80 "checks.completed",
81 "status.created",
82 "check_run.created",
83 "check_run.completed",
84 "check_run.rerequested",
85 "check_run.requested_action",
86 "check_suite.completed",
87 "check_suite.rerequested",
88 "workflow.completed",
89 "deployment.succeeded",
90 "deployment.failed",
91 "deployment.created",
92 "deployment_status.created",
93 "queue.changed",
94 "integration.failed",
95 "integration.passed",
96 "decision.recorded",
97 "session.appended",
98 "session.started",
99 "session.ended",
100 "session.progressed",
101 "work.claimed",
102 "work.released",
103 "work.claim_expired",
104 "work.handoff_requested",
105 "dependency.changed",
106 "overlap.detected",
107 "package.published",
108 "package.version_deleted",
109 "package.deleted",
110 "package.visibility_changed",
111 "secret_scanning_alert.created",
112 "secret_scanning_alert.fixed",
113 "secret_scanning_alert.dismissed",
114 "secret_scanning_alert.reopened",
115 "secret_scanning.bypass_requested",
116 "secret_scanning.bypass_reviewed",
117 "code_scanning_alert.created",
118 "code_scanning_alert.fixed",
119 "code_scanning_alert.dismissed",
120 "code_scanning_alert.reopened",
121 "vulnerability_alert.created",
122 "vulnerability_alert.fixed",
123 "vulnerability_alert.dismissed",
124 "secret_scanning_alert.summary",
125 "code_scanning_alert.summary",
126 "vulnerability_alert.reopened",
127 "vulnerability_alert.summary",
128 "security_advisory.published",
129 "security_advisory.withdrawn",
130 "security_advisory.reported",
131] as const;
132
133/**
134 * Event types webhooks were once offered that g1t no longer sends (from
135 * g1t's own agents, since removed). A webhook saved with one still reads;
136 * saving its list again leaves them out. Mirrors `RETIRED_EVENT_TYPES`.
137 */
138export const RETIRED_EVENT_TYPES: readonly string[] = ["agent.asked", "review.completed"];
139
140export type Hook = {
141 id: string;
142 scope: "repo" | "workspace";
143 workspace: string;
144 /** For a repository's webhook: `owner/name`. */
145 repo: string | null;
146 url: string;
147 /** Event types, or `["*"]` for all. */
148 events: string[];
149 active: boolean;
150 secretHint: string;
151 createdBy: string;
152 createdAt: string;
153 lastStatus: "delivered" | "pending" | "failed" | null;
154 lastDeliveredAt: string | null;
155};
156
157export type HookDelivery = {
158 id: string;
159 hookId: string;
160 eventId: string;
161 event: string;
162 status: "pending" | "delivered" | "failed";
163 attempts: number;
164 responseStatus: number | null;
165 responseBody: string | null;
166 error: string | null;
167 durationMs: number | null;
168 /** The JSON that was sent. */
169 payload: string;
170 createdAt: string;
171 deliveredAt: string | null;
172 nextAttemptAt: string | null;
173};
174
175/** A repository's webhooks, or with `repo` left out, the workspace's own. */
176export type HookOwner = { workspace: string; repo?: RepoPath };
177
178export interface WebhooksApi {
179 list(viewer: Viewer, owner: HookOwner): Promise<Result<Hook[]>>;
180 create(
181 actor: User,
182 owner: HookOwner,
183 input: { url: string; events?: string[]; secret?: string },
184 ): Promise<Result<{ hook: Hook; secret: string | null }>>;
185 update(actor: User, owner: HookOwner, id: string, input: { url?: string; events?: string[]; active?: boolean }): Promise<Result<Hook>>;
186 delete(actor: User, owner: HookOwner, id: string): Promise<Result<boolean>>;
187 ping(actor: User, owner: HookOwner, id: string): Promise<Result<HookDelivery>>;
188 deliveries(viewer: Viewer, owner: HookOwner, id: string): Promise<Result<HookDelivery[]>>;
189 redeliver(actor: User, owner: HookOwner, deliveryId: string): Promise<Result<HookDelivery>>;
190}