Skip to content
299 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Plan: the inbox, then channels and apps, instead of discussions1//! The webhooks service: events, delivered to the addresses a repository or
2//! a workspace registers.
3//!
4//! Every event g1t publishes can be delivered: an HTTPS `POST` of JSON,
5//! signed with the webhook's secret in `X-G1t-Signature-256`, and retried
6//! with growing waits when the receiver does not answer with a 2xx. Each
7//! delivery is kept, with what was sent and what came back, and can be sent
8//! again.
9//!
10//! Mirrors `packages/contracts/src/webhooks.ts`.
11
12use serde::{Deserialize, Serialize};
13
14use crate::repos::RepoPath;
15use crate::{User, Viewer};
16
17/// Every event a webhook can be sent, in the order people are shown them.
Security tells people the way they can live with. Each scan publishes one summary event per alert type (secret_scanning_alert.summary, code_scanning_alert.summary, vulnerability_alert.summary: what it opened, by severity, what it fixed, what is open now, the worst new alert and the newest one's title, with the owners and security managers to tell) beside the per-alert events webhooks keep, so the inbox holds one thread per repository and alert type that the next scan brings up to date instead of one item per finding, and the ids are capped at 200 while the counts are not. Critical and high alerts and a refused push reach the inbox at once (and toast like a mention, as the new security notification kind); medium and low wait for each person's security digest, one inbox item and email per workspace, daily or weekly as they choose in their notification settings, at once, or never; a scan that opened nothing refreshes the thread quietly ("2 of 3 fixed") and marks it done when nothing is left open; and security alerts are emailed by default. A repository can turn alerts for secrets found in its history off while push protection stays on. Reporting arrives: security advisories (G1TSA ids, drafts published and withdrawn by Admins and security managers, visible to anyone who can see the repository once published) and private vulnerability reporting (a repository setting; anyone who can see it may report, signed out with an email on a public one, five a day each, and the owners and security managers are told at once), each with its RPC methods, REST routes under /repos/{owner}/{name}/security/advisories and /security/reports, MCP actions, scopes and reference examples.18pub const EVENT_TYPES: [&str; 112] = [
Plan: the inbox, then channels and apps, instead of discussions19 "git.push",
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look20 "branch.renamed",
Plan: the inbox, then channels and apps, instead of discussions21 "repo.created",
22 "repo.forked",
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look23 "repo.updated",
24 "repo.visibility_changed",
25 "repo.renamed",
26 "repo.transferred",
27 "repo.default_branch_changed",
28 "repo.archived",
29 "repo.unarchived",
30 "repo.deleted",
31 "repo.restored",
32 "repo.purged",
33 "repo.collaborator_added",
34 "repo.collaborator_removed",
35 "repo.collaborator_role_changed",
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar36 "team.created",
37 "team.edited",
38 "team.deleted",
39 "team.member_added",
40 "team.member_role_changed",
41 "team.member_removed",
42 "team.repo_added",
43 "team.repo_role_changed",
44 "team.repo_removed",
@g1t welcomes you when you join a workspace, and that is the one introduction any agent makes. Identity now says when a person becomes a member, workspace.member_joined, by invitation, by an invite code, or by creating the workspace, and webhooks can hear it; the agents service hears it too, and for anyone who joined, never the creator, the workspace's @g1t opens your direct message and says in its own voice who it is, what to ask it, how agents answer, and where things are, once per person per workspace and charged to @g1t like any reply, with a fixed welcome when no model can be used. The agents, workspaces, authentication and webhooks guides say so.45 "workspace.member_joined",
Merge rulesets: branch and tag rules, agent-first, enforced on push and merge46 "ruleset.created",
47 "ruleset.updated",
48 "ruleset.deleted",
Plan: the inbox, then channels and apps, instead of discussions49 "issue.opened",
50 "issue.updated",
51 "issue.assigned",
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar52 "issue.labeled",
53 "issue.unlabeled",
54 "issue.milestoned",
55 "issue.demilestoned",
Plan: the inbox, then channels and apps, instead of discussions56 "issue.closed",
57 "issue.reopened",
58 "comment.created",
Merge Actions: cross-repo workflows and actions, release and deployment triggers, step timeouts59 "comment.edited",
60 "comment.deleted",
Plan: the inbox, then channels and apps, instead of discussions61 "pull.opened",
62 "pull.ready",
63 "pull.updated",
64 "pull.merge_requested",
65 "pull.merged",
66 "pull.closed",
Merge Actions: cross-repo workflows and actions, release and deployment triggers, step timeouts67 "pull.reopened",
68 "pull.converted_to_draft",
Events: review requests, assignments, stops and deployments are published69 "pull.assigned",
70 "pull.review_requested",
71 "pull.review_request_removed",
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar72 "pull.labeled",
73 "pull.unlabeled",
74 "pull.milestoned",
75 "pull.demilestoned",
76 "pull.base_changed",
Events: review requests, assignments, stops and deployments are published77 "pull.stalled",
78 "pull.resumed",
Merge Actions: cross-repo workflows and actions, release and deployment triggers, step timeouts79 "release.created",
80 "release.published",
81 "release.released",
82 "release.prereleased",
83 "release.edited",
84 "release.unpublished",
85 "release.deleted",
Plan: the inbox, then channels and apps, instead of discussions86 "agent.asked",
87 "checks.completed",
Merge checks: statuses and check runs on every commit88 "status.created",
89 "check_run.created",
90 "check_run.completed",
91 "check_run.rerequested",
92 "check_run.requested_action",
93 "check_suite.completed",
94 "check_suite.rerequested",
Plan: the inbox, then channels and apps, instead of discussions95 "review.completed",
96 "workflow.completed",
Events: review requests, assignments, stops and deployments are published97 "deployment.succeeded",
98 "deployment.failed",
Merge branch 'main' into worktree-agent-a69aeabc4b0deeb9799 "deployment.created",
100 "deployment_status.created",
Plan: the inbox, then channels and apps, instead of discussions101 "queue.changed",
102 "session.appended",
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member103 "package.published",
104 "package.version_deleted",
105 "package.deleted",
106 "package.visibility_changed",
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar107 "secret_scanning_alert.created",
108 "secret_scanning_alert.fixed",
109 "secret_scanning_alert.dismissed",
110 "secret_scanning_alert.reopened",
111 "secret_scanning.bypass_requested",
112 "secret_scanning.bypass_reviewed",
113 "code_scanning_alert.created",
114 "code_scanning_alert.fixed",
115 "code_scanning_alert.dismissed",
116 "code_scanning_alert.reopened",
117 "vulnerability_alert.created",
118 "vulnerability_alert.fixed",
119 "vulnerability_alert.dismissed",
Security tells people the way they can live with. Each scan publishes one summary event per alert type (secret_scanning_alert.summary, code_scanning_alert.summary, vulnerability_alert.summary: what it opened, by severity, what it fixed, what is open now, the worst new alert and the newest one's title, with the owners and security managers to tell) beside the per-alert events webhooks keep, so the inbox holds one thread per repository and alert type that the next scan brings up to date instead of one item per finding, and the ids are capped at 200 while the counts are not. Critical and high alerts and a refused push reach the inbox at once (and toast like a mention, as the new security notification kind); medium and low wait for each person's security digest, one inbox item and email per workspace, daily or weekly as they choose in their notification settings, at once, or never; a scan that opened nothing refreshes the thread quietly ("2 of 3 fixed") and marks it done when nothing is left open; and security alerts are emailed by default. A repository can turn alerts for secrets found in its history off while push protection stays on. Reporting arrives: security advisories (G1TSA ids, drafts published and withdrawn by Admins and security managers, visible to anyone who can see the repository once published) and private vulnerability reporting (a repository setting; anyone who can see it may report, signed out with an email on a public one, five a day each, and the owners and security managers are told at once), each with its RPC methods, REST routes under /repos/{owner}/{name}/security/advisories and /security/reports, MCP actions, scopes and reference examples.120 "secret_scanning_alert.summary",
121 "code_scanning_alert.summary",
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar122 "vulnerability_alert.reopened",
Security tells people the way they can live with. Each scan publishes one summary event per alert type (secret_scanning_alert.summary, code_scanning_alert.summary, vulnerability_alert.summary: what it opened, by severity, what it fixed, what is open now, the worst new alert and the newest one's title, with the owners and security managers to tell) beside the per-alert events webhooks keep, so the inbox holds one thread per repository and alert type that the next scan brings up to date instead of one item per finding, and the ids are capped at 200 while the counts are not. Critical and high alerts and a refused push reach the inbox at once (and toast like a mention, as the new security notification kind); medium and low wait for each person's security digest, one inbox item and email per workspace, daily or weekly as they choose in their notification settings, at once, or never; a scan that opened nothing refreshes the thread quietly ("2 of 3 fixed") and marks it done when nothing is left open; and security alerts are emailed by default. A repository can turn alerts for secrets found in its history off while push protection stays on. Reporting arrives: security advisories (G1TSA ids, drafts published and withdrawn by Admins and security managers, visible to anyone who can see the repository once published) and private vulnerability reporting (a repository setting; anyone who can see it may report, signed out with an email on a public one, five a day each, and the owners and security managers are told at once), each with its RPC methods, REST routes under /repos/{owner}/{name}/security/advisories and /security/reports, MCP actions, scopes and reference examples.123 "vulnerability_alert.summary",
124 "security_advisory.published",
125 "security_advisory.withdrawn",
126 "security_advisory.reported",
Merge branch 'mirroring' into artifacts-mode127 "mirror.unreachable",
128 "mirror.reachable",
129 "mirror.state_changed",
130 "mirror.moved_in",
Plan: the inbox, then channels and apps, instead of discussions131];
132
133/// What a webhook belongs to.
134#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
135#[serde(rename_all = "snake_case")]
136pub enum HookScope {
137 /// One repository's events.
138 Repo,
139 /// The events of every repository in a workspace.
140 Workspace,
141}
142
143#[derive(Clone, Debug, Serialize, Deserialize)]
144#[serde(rename_all = "camelCase")]
145pub struct Hook {
146 pub id: String,
147 pub scope: HookScope,
148 pub workspace: String,
149 /// For a repository's webhook: `owner/name`.
150 pub repo: Option<String>,
151 pub url: String,
152 /// The event types it is sent, or `["*"]` for all.
153 pub events: Vec<String>,
154 pub active: bool,
155 /// The last four characters of its secret.
156 pub secret_hint: String,
157 pub created_by: String,
158 /// RFC 3339.
159 pub created_at: String,
160 /// How its latest delivery went: `delivered`, `pending` or `failed`.
161 pub last_status: Option<String>,
162 pub last_delivered_at: Option<String>,
163}
164
165/// One event sent, or being sent, to a webhook.
166#[derive(Clone, Debug, Serialize, Deserialize)]
167#[serde(rename_all = "camelCase")]
168pub struct HookDelivery {
169 pub id: String,
170 pub hook_id: String,
171 /// The event's id, or empty for a ping.
172 pub event_id: String,
173 pub event: String,
174 /// `pending` while it will be tried again, `delivered`, or `failed` once
175 /// it has been tried as often as it will be.
176 pub status: String,
177 pub attempts: u32,
178 /// The receiver's HTTP status, the last time it answered.
179 pub response_status: Option<u16>,
180 /// The start of what it answered.
181 pub response_body: Option<String>,
182 /// Why the last attempt failed, when the receiver could not be reached.
183 pub error: Option<String>,
184 pub duration_ms: Option<u32>,
185 /// The JSON that was sent.
186 pub payload: String,
187 /// RFC 3339.
188 pub created_at: String,
189 pub delivered_at: Option<String>,
190 pub next_attempt_at: Option<String>,
191}
192
193/// Which webhooks a call is about: a repository's, or with `repo` left out,
194/// the workspace's own.
195#[derive(Clone, Debug, Serialize, Deserialize)]
196pub struct HookOwner {
197 pub workspace: String,
198 #[serde(default)]
199 pub repo: Option<RepoPath>,
200}
201
202/// `list`. Returns `Outcome<Vec<Hook>>`. Members of the workspace only.
203#[derive(Debug, Serialize, Deserialize)]
204pub struct ListArgs {
205 pub viewer: Viewer,
206 #[serde(flatten)]
207 pub owner: HookOwner,
208}
209
210/// `create`. Returns `Outcome<CreatedHook>`. Members, for a repository's
211/// webhooks; owners, for the workspace's.
212#[derive(Debug, Serialize, Deserialize)]
213pub struct CreateArgs {
214 pub actor: User,
215 #[serde(flatten)]
216 pub owner: HookOwner,
217 pub url: String,
218 /// Event types, or `["*"]` for all. All when empty.
219 #[serde(default)]
220 pub events: Vec<String>,
221 /// Made by g1t when left out.
222 #[serde(default)]
223 pub secret: Option<String>,
224}
225
226#[derive(Clone, Debug, Serialize, Deserialize)]
227pub struct CreatedHook {
228 pub hook: Hook,
229 /// The secret, when g1t made it: shown this once.
230 pub secret: Option<String>,
231}
232
233/// `update`: only the fields given change. Returns `Outcome<Hook>`.
234#[derive(Debug, Serialize, Deserialize)]
235pub struct UpdateArgs {
236 pub actor: User,
237 #[serde(flatten)]
238 pub owner: HookOwner,
239 pub id: String,
240 #[serde(default)]
241 pub url: Option<String>,
242 #[serde(default)]
243 pub events: Option<Vec<String>>,
244 #[serde(default)]
245 pub active: Option<bool>,
246}
247
248/// `delete` (returns `Outcome<bool>`) and `ping` (sends a `ping` event and
249/// returns `Outcome<HookDelivery>`).
250#[derive(Debug, Serialize, Deserialize)]
251pub struct HookArgs {
252 pub actor: User,
253 #[serde(flatten)]
254 pub owner: HookOwner,
255 pub id: String,
256}
257
258/// `deliveries`: a webhook's latest deliveries, newest first. Returns
259/// `Outcome<Vec<HookDelivery>>`.
260#[derive(Debug, Serialize, Deserialize)]
261pub struct DeliveriesArgs {
262 pub viewer: Viewer,
263 #[serde(flatten)]
264 pub owner: HookOwner,
265 pub id: String,
266}
267
268/// `redeliver`: sends a delivery's payload again, as a new delivery.
269/// Returns `Outcome<HookDelivery>`.
270#[derive(Debug, Serialize, Deserialize)]
271#[serde(rename_all = "camelCase")]
272pub struct RedeliverArgs {
273 pub actor: User,
274 #[serde(flatten)]
275 pub owner: HookOwner,
276 pub delivery_id: String,
277}
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look278
279#[cfg(test)]
280mod tests {
281 use super::EVENT_TYPES;
282
283 /// The TypeScript mirror lists the same events, in the same order.
284 #[test]
285 fn the_typescript_mirror_lists_the_same_events() {
286 let ts = include_str!("../../../packages/contracts/src/webhooks.ts");
287 let list = ts
288 .split_once("export const EVENT_TYPES = [")
289 .and_then(|(_, rest)| rest.split_once("] as const"))
290 .map(|(list, _)| list)
291 .expect("EVENT_TYPES in webhooks.ts");
292 let mirrored: Vec<&str> = list
293 .split(',')
294 .map(|item| item.trim().trim_matches('"'))
295 .filter(|item| !item.is_empty())
296 .collect();
297 assert_eq!(mirrored, EVENT_TYPES);
298 }
299}

This file's history is long; its oldest lines are credited to the oldest commit read.