g1t/packages/contracts/src/webhooks.ts

103 lines2,959 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",
Agents asked while not at work are woken to answer41 "agent.asked",
Webhooks: every event, to your own addresses, signed and retried42 "checks.completed",
43 "review.completed",
Actions: workflow_run, workflow.completed, artifacts on the run page, Node 2444 "workflow.completed",
Webhooks: every event, to your own addresses, signed and retried45 "queue.changed",
46 "session.appended",
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member47 "package.published",
48 "package.version_deleted",
49 "package.deleted",
50 "package.visibility_changed",
Webhooks: every event, to your own addresses, signed and retried51] as const;
52
53export type Hook = {
54 id: string;
55 scope: "repo" | "workspace";
56 workspace: string;
57 /** For a repository's webhook: `owner/name`. */
58 repo: string | null;
59 url: string;
60 /** Event types, or `["*"]` for all. */
61 events: string[];
62 active: boolean;
63 secretHint: string;
64 createdBy: string;
65 createdAt: string;
66 lastStatus: "delivered" | "pending" | "failed" | null;
67 lastDeliveredAt: string | null;
68};
69
70export type HookDelivery = {
71 id: string;
72 hookId: string;
73 eventId: string;
74 event: string;
75 status: "pending" | "delivered" | "failed";
76 attempts: number;
77 responseStatus: number | null;
78 responseBody: string | null;
79 error: string | null;
80 durationMs: number | null;
81 /** The JSON that was sent. */
82 payload: string;
83 createdAt: string;
84 deliveredAt: string | null;
85 nextAttemptAt: string | null;
86};
87
88/** A repository's webhooks, or with `repo` left out, the workspace's own. */
89export type HookOwner = { workspace: string; repo?: RepoPath };
90
91export interface WebhooksApi {
92 list(viewer: Viewer, owner: HookOwner): Promise<Result<Hook[]>>;
93 create(
94 actor: User,
95 owner: HookOwner,
96 input: { url: string; events?: string[]; secret?: string },
97 ): Promise<Result<{ hook: Hook; secret: string | null }>>;
98 update(actor: User, owner: HookOwner, id: string, input: { url?: string; events?: string[]; active?: boolean }): Promise<Result<Hook>>;
99 delete(actor: User, owner: HookOwner, id: string): Promise<Result<boolean>>;
100 ping(actor: User, owner: HookOwner, id: string): Promise<Result<HookDelivery>>;
101 deliveries(viewer: Viewer, owner: HookOwner, id: string): Promise<Result<HookDelivery[]>>;
102 redeliver(actor: User, owner: HookOwner, deliveryId: string): Promise<Result<HookDelivery>>;
103}