tenseleyflow/shithub / e0ed19f

Browse files

docs/api: webhooks reference (S50 §8)

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
e0ed19fba60e0c6a0e59aeb2af8270c6714a6e61
Parents
230d267
Tree
635239e

1 changed file

StatusFile+-
M docs/public/api/webhooks.md 82 18
docs/public/api/webhooks.mdmodified
@@ -1,8 +1,11 @@
11
 # Webhooks
22
 
3
-The webhook **delivery format** (payloads, signing) is shipped
4
-and stable. The webhook **management API** (CRUD over webhooks
5
-on a repo) is planned.
3
+The webhook **delivery format** (payloads, signing) and the
4
+webhook **management API** (CRUD over webhooks on a repo) are
5
+both shipped. The management endpoints are PAT-authenticated and
6
+share the canonical [API conventions](overview.md) (JSON error
7
+envelopes, `X-RateLimit-*`, `X-OAuth-Scopes`, `Link`
8
+pagination).
69
 
710
 ## Delivery format
811
 
@@ -13,21 +16,82 @@ retries, idempotency.
1316
 The user-docs page is intentionally the canonical place; an API
1417
 consumer building a subscriber endpoint reads the same material.
1518
 
16
-## Management API (planned)
17
-
18
-| Method | Path                                                      | Scope        |
19
-|--------|-----------------------------------------------------------|--------------|
20
-| GET    | `/api/v1/repos/{owner}/{repo}/hooks`                      | `webhooks`   |
21
-| POST   | `/api/v1/repos/{owner}/{repo}/hooks`                      | `webhooks`   |
22
-| GET    | `/api/v1/repos/{owner}/{repo}/hooks/{id}`                 | `webhooks`   |
23
-| PATCH  | `/api/v1/repos/{owner}/{repo}/hooks/{id}`                 | `webhooks`   |
24
-| DELETE | `/api/v1/repos/{owner}/{repo}/hooks/{id}`                 | `webhooks`   |
25
-| POST   | `/api/v1/repos/{owner}/{repo}/hooks/{id}/pings`           | `webhooks`   |
26
-| GET    | `/api/v1/repos/{owner}/{repo}/hooks/{id}/deliveries`      | `webhooks`   |
27
-| POST   | `/api/v1/repos/{owner}/{repo}/hooks/{id}/deliveries/{delivery}/redeliver` | `webhooks` |
28
-
29
-Until these land, manage webhooks via the web UI under
30
-Repository → Settings → Webhooks.
19
+## Management API
20
+
21
+All endpoints require an `Authorization: Bearer <pat>` header
22
+whose token carries the `repo:write` scope and the caller's role
23
+on the repo must reach **settings:general** (owner / write
24
+collaborator). Webhook secrets are write-only: they're set on
25
+create and rotated by passing a new `secret` on PATCH, but
26
+**never** returned in any response.
27
+
28
+| Method | Path                                                                       |
29
+|--------|----------------------------------------------------------------------------|
30
+| GET    | `/api/v1/repos/{owner}/{repo}/hooks`                                       |
31
+| POST   | `/api/v1/repos/{owner}/{repo}/hooks`                                       |
32
+| GET    | `/api/v1/repos/{owner}/{repo}/hooks/{id}`                                  |
33
+| PATCH  | `/api/v1/repos/{owner}/{repo}/hooks/{id}`                                  |
34
+| DELETE | `/api/v1/repos/{owner}/{repo}/hooks/{id}`                                  |
35
+| GET    | `/api/v1/repos/{owner}/{repo}/hooks/{id}/deliveries`                       |
36
+| GET    | `/api/v1/repos/{owner}/{repo}/hooks/{id}/deliveries/{did}`                 |
37
+| POST   | `/api/v1/repos/{owner}/{repo}/hooks/{id}/deliveries/{did}/redeliver`       |
38
+
39
+### Create
40
+
41
+```http
42
+POST /api/v1/repos/alice/demo/hooks
43
+Authorization: Bearer <pat>
44
+Content-Type: application/json
45
+
46
+{
47
+  "url":             "https://hooks.example.com/sink",
48
+  "content_type":    "json",
49
+  "events":          ["push", "pull_request"],
50
+  "active":          true,
51
+  "ssl_verification": true,
52
+  "secret":          "shared-secret-or-omit-to-mint"
53
+}
54
+```
55
+
56
+`content_type` is `json` (default) or `form`. Omitting `secret`
57
+mints a fresh one server-side. The server validates the URL
58
+against the SSRF allow-list (scheme + port + non-private
59
+resolution) so a 422 here means the target was rejected at
60
+create time — no silent delivery failures later.
61
+
62
+A successful create returns the hook row at `201 Created` and
63
+enqueues a synthetic `ping` delivery so the operator sees an
64
+immediate round-trip.
65
+
66
+### Patch
67
+
68
+```http
69
+PATCH /api/v1/repos/alice/demo/hooks/42
70
+Content-Type: application/json
71
+
72
+{
73
+  "url":    "https://hooks.example.com/v2",
74
+  "events": ["push", "pull_request", "issues"],
75
+  "active": false,
76
+  "secret": "rotated-secret"
77
+}
78
+```
79
+
80
+Fields are merged onto the current row: omit a field to keep its
81
+existing value. Passing `secret` rotates the HMAC key used for
82
+subsequent deliveries.
83
+
84
+### Deliveries
85
+
86
+The deliveries list is paginated (default 30, max 100 per page)
87
+and emits standard `Link: <...>; rel="next" …` headers. The
88
+single-delivery shape includes the captured request headers,
89
+request body, and response body so operators can replay a
90
+failed delivery from the recorded transcript.
91
+
92
+`POST .../deliveries/{did}/redeliver` enqueues a fresh delivery
93
+copying the same payload + headers under a new id; the response
94
+body is `{"id": <new_delivery_id>}`.
3195
 
3296
 ## Event types (canonical list)
3397