Skip to content

g1t/packages/contracts/src/webhooks.ts

147 lines4,117 bytesCodeBlame

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.

Webhooks: every event, to your own addresses, signed and retried1import 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",
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look13 "branch.renamed",
Webhooks: every event, to your own addresses, signed and retried14 "repo.created",
15 "repo.forked",
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look16 "repo.updated",
17 "repo.visibility_changed",
18 "repo.renamed",
19 "repo.transferred",
20 "repo.default_branch_changed",
21 "repo.archived",
22 "repo.unarchived",
23 "repo.deleted",
24 "repo.restored",
25 "repo.purged",
26 "repo.collaborator_added",
27 "repo.collaborator_removed",
28 "repo.collaborator_role_changed",
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar29 "team.created",
30 "team.edited",
31 "team.deleted",
32 "team.member_added",
33 "team.member_role_changed",
34 "team.member_removed",
35 "team.repo_added",
36 "team.repo_role_changed",
37 "team.repo_removed",
Merge rulesets: branch and tag rules, agent-first, enforced on push and merge38 "ruleset.created",
39 "ruleset.updated",
40 "ruleset.deleted",
Webhooks: every event, to your own addresses, signed and retried41 "issue.opened",
42 "issue.updated",
43 "issue.assigned",
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar44 "issue.labeled",
45 "issue.unlabeled",
46 "issue.milestoned",
47 "issue.demilestoned",
Webhooks: every event, to your own addresses, signed and retried48 "issue.closed",
49 "issue.reopened",
50 "comment.created",
51 "pull.opened",
52 "pull.ready",
53 "pull.updated",
54 "pull.merge_requested",
55 "pull.merged",
56 "pull.closed",
Events: review requests, assignments, stops and deployments are published57 "pull.assigned",
58 "pull.review_requested",
59 "pull.review_request_removed",
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar60 "pull.labeled",
61 "pull.unlabeled",
62 "pull.milestoned",
63 "pull.demilestoned",
64 "pull.base_changed",
Events: review requests, assignments, stops and deployments are published65 "pull.stalled",
66 "pull.resumed",
Agents asked while not at work are woken to answer67 "agent.asked",
Webhooks: every event, to your own addresses, signed and retried68 "checks.completed",
69 "review.completed",
Actions: workflow_run, workflow.completed, artifacts on the run page, Node 2470 "workflow.completed",
Events: review requests, assignments, stops and deployments are published71 "deployment.succeeded",
72 "deployment.failed",
Merge main: Deployments panel in the About, project homepage, both sides' operations73 "deployment.created",
74 "deployment_status.created",
Webhooks: every event, to your own addresses, signed and retried75 "queue.changed",
76 "session.appended",
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member77 "package.published",
78 "package.version_deleted",
79 "package.deleted",
80 "package.visibility_changed",
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar81 "secret_scanning_alert.created",
82 "secret_scanning_alert.fixed",
83 "secret_scanning_alert.dismissed",
84 "secret_scanning_alert.reopened",
85 "secret_scanning.bypass_requested",
86 "secret_scanning.bypass_reviewed",
87 "code_scanning_alert.created",
88 "code_scanning_alert.fixed",
89 "code_scanning_alert.dismissed",
90 "code_scanning_alert.reopened",
91 "vulnerability_alert.created",
92 "vulnerability_alert.fixed",
93 "vulnerability_alert.dismissed",
94 "vulnerability_alert.reopened",
Webhooks: every event, to your own addresses, signed and retried95] as const;
96
97export type Hook = {
98 id: string;
99 scope: "repo" | "workspace";
100 workspace: string;
101 /** For a repository's webhook: `owner/name`. */
102 repo: string | null;
103 url: string;
104 /** Event types, or `["*"]` for all. */
105 events: string[];
106 active: boolean;
107 secretHint: string;
108 createdBy: string;
109 createdAt: string;
110 lastStatus: "delivered" | "pending" | "failed" | null;
111 lastDeliveredAt: string | null;
112};
113
114export type HookDelivery = {
115 id: string;
116 hookId: string;
117 eventId: string;
118 event: string;
119 status: "pending" | "delivered" | "failed";
120 attempts: number;
121 responseStatus: number | null;
122 responseBody: string | null;
123 error: string | null;
124 durationMs: number | null;
125 /** The JSON that was sent. */
126 payload: string;
127 createdAt: string;
128 deliveredAt: string | null;
129 nextAttemptAt: string | null;
130};
131
132/** A repository's webhooks, or with `repo` left out, the workspace's own. */
133export type HookOwner = { workspace: string; repo?: RepoPath };
134
135export interface WebhooksApi {
136 list(viewer: Viewer, owner: HookOwner): Promise<Result<Hook[]>>;
137 create(
138 actor: User,
139 owner: HookOwner,
140 input: { url: string; events?: string[]; secret?: string },
141 ): Promise<Result<{ hook: Hook; secret: string | null }>>;
142 update(actor: User, owner: HookOwner, id: string, input: { url?: string; events?: string[]; active?: boolean }): Promise<Result<Hook>>;
143 delete(actor: User, owner: HookOwner, id: string): Promise<Result<boolean>>;
144 ping(actor: User, owner: HookOwner, id: string): Promise<Result<HookDelivery>>;
145 deliveries(viewer: Viewer, owner: HookOwner, id: string): Promise<Result<HookDelivery[]>>;
146 redeliver(actor: User, owner: HookOwner, deliveryId: string): Promise<Result<HookDelivery>>;
147}

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