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.
| The statement is a month at a time, a line per kind of charge | 1 | //! 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 | ||
| 12 | use serde::{Deserialize, Serialize}; | |
| 13 | ||
| 14 | use crate::repos::RepoPath; | |
| 15 | use crate::{User, Viewer}; | |
| 16 | ||
| 17 | /// Every event a webhook can be sent, in the order people are shown them. | |
| Merge branch 'claude/cool-newton-7nm8r9' (#36): real GitHub Actions on g1t, managed deploy workflows, g1t/deploy and the Sysbox runner 0.2.0. The merge keeps both sides' webhook events and API operations, says agent images need tar, guards the job engine's stop to Unix so the runner builds on Windows again, and keeps the moves tests' previews from going idle as the calendar passes their fixture's date. | 18 | pub const EVENT_TYPES: [&str; 113] = [ |
| The statement is a month at a time, a line per kind of charge | 19 | "git.push", |
| Merge branch 'claude/cool-newton-7nm8r9' (#36): real GitHub Actions on g1t, managed deploy workflows, g1t/deploy and the Sysbox runner 0.2.0. The merge keeps both sides' webhook events and API operations, says agent images need tar, guards the job engine's stop to Unix so the runner builds on Windows again, and keeps the moves tests' previews from going idle as the calendar passes their fixture's date. | 20 | "git.deleted", |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 21 | "branch.renamed", |
| The statement is a month at a time, a line per kind of charge | 22 | "repo.created", |
| 23 | "repo.forked", | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 24 | "repo.updated", |
| 25 | "repo.visibility_changed", | |
| 26 | "repo.renamed", | |
| 27 | "repo.transferred", | |
| 28 | "repo.default_branch_changed", | |
| 29 | "repo.archived", | |
| 30 | "repo.unarchived", | |
| 31 | "repo.deleted", | |
| 32 | "repo.restored", | |
| 33 | "repo.purged", | |
| 34 | "repo.collaborator_added", | |
| 35 | "repo.collaborator_removed", | |
| 36 | "repo.collaborator_role_changed", | |
| Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar | 37 | "team.created", |
| 38 | "team.edited", | |
| 39 | "team.deleted", | |
| 40 | "team.member_added", | |
| 41 | "team.member_role_changed", | |
| 42 | "team.member_removed", | |
| 43 | "team.repo_added", | |
| 44 | "team.repo_role_changed", | |
| 45 | "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. | 46 | "workspace.member_joined", |
| Merge rulesets: branch and tag rules, agent-first, enforced on push and merge | 47 | "ruleset.created", |
| 48 | "ruleset.updated", | |
| 49 | "ruleset.deleted", | |
| The statement is a month at a time, a line per kind of charge | 50 | "issue.opened", |
| 51 | "issue.updated", | |
| 52 | "issue.assigned", | |
| Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar | 53 | "issue.labeled", |
| 54 | "issue.unlabeled", | |
| 55 | "issue.milestoned", | |
| 56 | "issue.demilestoned", | |
| The statement is a month at a time, a line per kind of charge | 57 | "issue.closed", |
| 58 | "issue.reopened", | |
| 59 | "comment.created", | |
| Merge Actions: cross-repo workflows and actions, release and deployment triggers, step timeouts | 60 | "comment.edited", |
| 61 | "comment.deleted", | |
| The statement is a month at a time, a line per kind of charge | 62 | "pull.opened", |
| 63 | "pull.ready", | |
| 64 | "pull.updated", | |
| 65 | "pull.merge_requested", | |
| 66 | "pull.merged", | |
| 67 | "pull.closed", | |
| Merge Actions: cross-repo workflows and actions, release and deployment triggers, step timeouts | 68 | "pull.reopened", |
| 69 | "pull.converted_to_draft", | |
| Events: review requests, assignments, stops and deployments are published | 70 | "pull.assigned", |
| 71 | "pull.review_requested", | |
| 72 | "pull.review_request_removed", | |
| Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar | 73 | "pull.labeled", |
| 74 | "pull.unlabeled", | |
| 75 | "pull.milestoned", | |
| 76 | "pull.demilestoned", | |
| 77 | "pull.base_changed", | |
| Events: review requests, assignments, stops and deployments are published | 78 | "pull.stalled", |
| 79 | "pull.resumed", | |
| Merge Actions: cross-repo workflows and actions, release and deployment triggers, step timeouts | 80 | "release.created", |
| 81 | "release.published", | |
| 82 | "release.released", | |
| 83 | "release.prereleased", | |
| 84 | "release.edited", | |
| 85 | "release.unpublished", | |
| 86 | "release.deleted", | |
| The statement is a month at a time, a line per kind of charge | 87 | "agent.asked", |
| 88 | "checks.completed", | |
| Merge checks: statuses and check runs on every commit | 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", | |
| The statement is a month at a time, a line per kind of charge | 96 | "review.completed", |
| 97 | "workflow.completed", | |
| Events: review requests, assignments, stops and deployments are published | 98 | "deployment.succeeded", |
| 99 | "deployment.failed", | |
| Merge branch 'main' into worktree-agent-a69aeabc4b0deeb97 | 100 | "deployment.created", |
| 101 | "deployment_status.created", | |
| The statement is a month at a time, a line per kind of charge | 102 | "queue.changed", |
| 103 | "session.appended", | |
| Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member | 104 | "package.published", |
| 105 | "package.version_deleted", | |
| 106 | "package.deleted", | |
| 107 | "package.visibility_changed", | |
| Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar | 108 | "secret_scanning_alert.created", |
| 109 | "secret_scanning_alert.fixed", | |
| 110 | "secret_scanning_alert.dismissed", | |
| 111 | "secret_scanning_alert.reopened", | |
| 112 | "secret_scanning.bypass_requested", | |
| 113 | "secret_scanning.bypass_reviewed", | |
| 114 | "code_scanning_alert.created", | |
| 115 | "code_scanning_alert.fixed", | |
| 116 | "code_scanning_alert.dismissed", | |
| 117 | "code_scanning_alert.reopened", | |
| 118 | "vulnerability_alert.created", | |
| 119 | "vulnerability_alert.fixed", | |
| 120 | "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. | 121 | "secret_scanning_alert.summary", |
| 122 | "code_scanning_alert.summary", | |
| Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar | 123 | "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. | 124 | "vulnerability_alert.summary", |
| 125 | "security_advisory.published", | |
| 126 | "security_advisory.withdrawn", | |
| 127 | "security_advisory.reported", | |
| Merge branch 'mirroring' into artifacts-mode | 128 | "mirror.unreachable", |
| 129 | "mirror.reachable", | |
| 130 | "mirror.state_changed", | |
| 131 | "mirror.moved_in", | |
| The statement is a month at a time, a line per kind of charge | 132 | ]; |
| 133 | ||
| 134 | /// What a webhook belongs to. | |
| 135 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
| 136 | #[serde(rename_all = "snake_case")] | |
| 137 | pub enum HookScope { | |
| 138 | /// One repository's events. | |
| 139 | Repo, | |
| 140 | /// The events of every repository in a workspace. | |
| 141 | Workspace, | |
| 142 | } | |
| 143 | ||
| 144 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 145 | #[serde(rename_all = "camelCase")] | |
| 146 | pub struct Hook { | |
| 147 | pub id: String, | |
| 148 | pub scope: HookScope, | |
| 149 | pub workspace: String, | |
| 150 | /// For a repository's webhook: `owner/name`. | |
| 151 | pub repo: Option<String>, | |
| 152 | pub url: String, | |
| 153 | /// The event types it is sent, or `["*"]` for all. | |
| 154 | pub events: Vec<String>, | |
| 155 | pub active: bool, | |
| 156 | /// The last four characters of its secret. | |
| 157 | pub secret_hint: String, | |
| 158 | pub created_by: String, | |
| 159 | /// RFC 3339. | |
| 160 | pub created_at: String, | |
| 161 | /// How its latest delivery went: `delivered`, `pending` or `failed`. | |
| 162 | pub last_status: Option<String>, | |
| 163 | pub last_delivered_at: Option<String>, | |
| 164 | } | |
| 165 | ||
| 166 | /// One event sent, or being sent, to a webhook. | |
| 167 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 168 | #[serde(rename_all = "camelCase")] | |
| 169 | pub struct HookDelivery { | |
| 170 | pub id: String, | |
| 171 | pub hook_id: String, | |
| 172 | /// The event's id, or empty for a ping. | |
| 173 | pub event_id: String, | |
| 174 | pub event: String, | |
| 175 | /// `pending` while it will be tried again, `delivered`, or `failed` once | |
| 176 | /// it has been tried as often as it will be. | |
| 177 | pub status: String, | |
| 178 | pub attempts: u32, | |
| 179 | /// The receiver's HTTP status, the last time it answered. | |
| 180 | pub response_status: Option<u16>, | |
| 181 | /// The start of what it answered. | |
| 182 | pub response_body: Option<String>, | |
| 183 | /// Why the last attempt failed, when the receiver could not be reached. | |
| 184 | pub error: Option<String>, | |
| 185 | pub duration_ms: Option<u32>, | |
| 186 | /// The JSON that was sent. | |
| 187 | pub payload: String, | |
| 188 | /// RFC 3339. | |
| 189 | pub created_at: String, | |
| 190 | pub delivered_at: Option<String>, | |
| 191 | pub next_attempt_at: Option<String>, | |
| 192 | } | |
| 193 | ||
| 194 | /// Which webhooks a call is about: a repository's, or with `repo` left out, | |
| 195 | /// the workspace's own. | |
| 196 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 197 | pub struct HookOwner { | |
| 198 | pub workspace: String, | |
| 199 | #[serde(default)] | |
| 200 | pub repo: Option<RepoPath>, | |
| 201 | } | |
| 202 | ||
| 203 | /// `list`. Returns `Outcome<Vec<Hook>>`. Members of the workspace only. | |
| 204 | #[derive(Debug, Serialize, Deserialize)] | |
| 205 | pub struct ListArgs { | |
| 206 | pub viewer: Viewer, | |
| 207 | #[serde(flatten)] | |
| 208 | pub owner: HookOwner, | |
| 209 | } | |
| 210 | ||
| 211 | /// `create`. Returns `Outcome<CreatedHook>`. Members, for a repository's | |
| 212 | /// webhooks; owners, for the workspace's. | |
| 213 | #[derive(Debug, Serialize, Deserialize)] | |
| 214 | pub struct CreateArgs { | |
| 215 | pub actor: User, | |
| 216 | #[serde(flatten)] | |
| 217 | pub owner: HookOwner, | |
| 218 | pub url: String, | |
| 219 | /// Event types, or `["*"]` for all. All when empty. | |
| 220 | #[serde(default)] | |
| 221 | pub events: Vec<String>, | |
| 222 | /// Made by g1t when left out. | |
| 223 | #[serde(default)] | |
| 224 | pub secret: Option<String>, | |
| 225 | } | |
| 226 | ||
| 227 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 228 | pub struct CreatedHook { | |
| 229 | pub hook: Hook, | |
| 230 | /// The secret, when g1t made it: shown this once. | |
| 231 | pub secret: Option<String>, | |
| 232 | } | |
| 233 | ||
| 234 | /// `update`: only the fields given change. Returns `Outcome<Hook>`. | |
| 235 | #[derive(Debug, Serialize, Deserialize)] | |
| 236 | pub struct UpdateArgs { | |
| 237 | pub actor: User, | |
| 238 | #[serde(flatten)] | |
| 239 | pub owner: HookOwner, | |
| 240 | pub id: String, | |
| 241 | #[serde(default)] | |
| 242 | pub url: Option<String>, | |
| 243 | #[serde(default)] | |
| 244 | pub events: Option<Vec<String>>, | |
| 245 | #[serde(default)] | |
| 246 | pub active: Option<bool>, | |
| 247 | } | |
| 248 | ||
| 249 | /// `delete` (returns `Outcome<bool>`) and `ping` (sends a `ping` event and | |
| 250 | /// returns `Outcome<HookDelivery>`). | |
| 251 | #[derive(Debug, Serialize, Deserialize)] | |
| 252 | pub struct HookArgs { | |
| 253 | pub actor: User, | |
| 254 | #[serde(flatten)] | |
| 255 | pub owner: HookOwner, | |
| 256 | pub id: String, | |
| 257 | } | |
| 258 | ||
| 259 | /// `deliveries`: a webhook's latest deliveries, newest first. Returns | |
| 260 | /// `Outcome<Vec<HookDelivery>>`. | |
| 261 | #[derive(Debug, Serialize, Deserialize)] | |
| 262 | pub struct DeliveriesArgs { | |
| 263 | pub viewer: Viewer, | |
| 264 | #[serde(flatten)] | |
| 265 | pub owner: HookOwner, | |
| 266 | pub id: String, | |
| 267 | } | |
| 268 | ||
| 269 | /// `redeliver`: sends a delivery's payload again, as a new delivery. | |
| 270 | /// Returns `Outcome<HookDelivery>`. | |
| 271 | #[derive(Debug, Serialize, Deserialize)] | |
| 272 | #[serde(rename_all = "camelCase")] | |
| 273 | pub struct RedeliverArgs { | |
| 274 | pub actor: User, | |
| 275 | #[serde(flatten)] | |
| 276 | pub owner: HookOwner, | |
| 277 | pub delivery_id: String, | |
| 278 | } | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 279 | |
| 280 | #[cfg(test)] | |
| 281 | mod tests { | |
| 282 | use super::EVENT_TYPES; | |
| 283 | ||
| 284 | /// The TypeScript mirror lists the same events, in the same order. | |
| 285 | #[test] | |
| 286 | fn the_typescript_mirror_lists_the_same_events() { | |
| 287 | let ts = include_str!("../../../packages/contracts/src/webhooks.ts"); | |
| 288 | let list = ts | |
| 289 | .split_once("export const EVENT_TYPES = [") | |
| 290 | .and_then(|(_, rest)| rest.split_once("] as const")) | |
| 291 | .map(|(list, _)| list) | |
| 292 | .expect("EVENT_TYPES in webhooks.ts"); | |
| 293 | let mirrored: Vec<&str> = list | |
| 294 | .split(',') | |
| 295 | .map(|item| item.trim().trim_matches('"')) | |
| 296 | .filter(|item| !item.is_empty()) | |
| 297 | .collect(); | |
| 298 | assert_eq!(mirrored, EVENT_TYPES); | |
| 299 | } | |
| 300 | } |
This file's history is long; its oldest lines are credited to the oldest commit read.