Skip to content

g1t/packages/contracts/src/webhooks.ts

110 lines3,123 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",
Webhooks: every event, to your own addresses, signed and retried29 "issue.opened",
30 "issue.updated",
31 "issue.assigned",
32 "issue.closed",
33 "issue.reopened",
34 "comment.created",
35 "pull.opened",
36 "pull.ready",
37 "pull.updated",
38 "pull.merge_requested",
39 "pull.merged",
40 "pull.closed",
Events: review requests, assignments, stops and deployments are published41 "pull.assigned",
42 "pull.review_requested",
43 "pull.review_request_removed",
44 "pull.stalled",
45 "pull.resumed",
Agents asked while not at work are woken to answer46 "agent.asked",
Webhooks: every event, to your own addresses, signed and retried47 "checks.completed",
48 "review.completed",
Actions: workflow_run, workflow.completed, artifacts on the run page, Node 2449 "workflow.completed",
Events: review requests, assignments, stops and deployments are published50 "deployment.succeeded",
51 "deployment.failed",
Webhooks: every event, to your own addresses, signed and retried52 "queue.changed",
53 "session.appended",
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member54 "package.published",
55 "package.version_deleted",
56 "package.deleted",
57 "package.visibility_changed",
Webhooks: every event, to your own addresses, signed and retried58] as const;
59
60export type Hook = {
61 id: string;
62 scope: "repo" | "workspace";
63 workspace: string;
64 /** For a repository's webhook: `owner/name`. */
65 repo: string | null;
66 url: string;
67 /** Event types, or `["*"]` for all. */
68 events: string[];
69 active: boolean;
70 secretHint: string;
71 createdBy: string;
72 createdAt: string;
73 lastStatus: "delivered" | "pending" | "failed" | null;
74 lastDeliveredAt: string | null;
75};
76
77export type HookDelivery = {
78 id: string;
79 hookId: string;
80 eventId: string;
81 event: string;
82 status: "pending" | "delivered" | "failed";
83 attempts: number;
84 responseStatus: number | null;
85 responseBody: string | null;
86 error: string | null;
87 durationMs: number | null;
88 /** The JSON that was sent. */
89 payload: string;
90 createdAt: string;
91 deliveredAt: string | null;
92 nextAttemptAt: string | null;
93};
94
95/** A repository's webhooks, or with `repo` left out, the workspace's own. */
96export type HookOwner = { workspace: string; repo?: RepoPath };
97
98export interface WebhooksApi {
99 list(viewer: Viewer, owner: HookOwner): Promise<Result<Hook[]>>;
100 create(
101 actor: User,
102 owner: HookOwner,
103 input: { url: string; events?: string[]; secret?: string },
104 ): Promise<Result<{ hook: Hook; secret: string | null }>>;
105 update(actor: User, owner: HookOwner, id: string, input: { url?: string; events?: string[]; active?: boolean }): Promise<Result<Hook>>;
106 delete(actor: User, owner: HookOwner, id: string): Promise<Result<boolean>>;
107 ping(actor: User, owner: HookOwner, id: string): Promise<Result<HookDelivery>>;
108 deliveries(viewer: Viewer, owner: HookOwner, id: string): Promise<Result<HookDelivery[]>>;
109 redeliver(actor: User, owner: HookOwner, deliveryId: string): Promise<Result<HookDelivery>>;
110}