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.

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