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.

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