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