UNPKG

54.7 kBMarkdownView Raw
1# @octokit/webhooks
2
3> GitHub webhook events toolset for Node.js
4
5[![@latest](https://img.shields.io/npm/v/@octokit/webhooks.svg)](https://www.npmjs.com/package/@octokit/webhooks)
6[![Test](https://github.com/octokit/webhooks.js/workflows/Test/badge.svg)](https://github.com/octokit/webhooks.js/actions?query=workflow)
7
8<!-- toc -->
9
10- [Usage](#usage)
11- [Local development](#local-development)
12- [API](#api)
13 - [Constructor](#constructor)
14 - [webhooks.sign()](#webhookssign)
15 - [webhooks.verify()](#webhooksverify)
16 - [webhooks.verifyAndReceive()](#webhooksverifyandreceive)
17 - [webhooks.receive()](#webhooksreceive)
18 - [webhooks.on()](#webhookson)
19 - [webhooks.onAny()](#webhooksonany)
20 - [webhooks.onError()](#webhooksonerror)
21 - [webhooks.removeListener()](#webhooksremovelistener)
22 - [createNodeMiddleware()](#createnodemiddleware)
23 - [Webhook events](#webhook-events)
24 - [emitterEventNames](#emittereventnames)
25- [TypeScript](#typescript)
26 - [`EmitterWebhookEventName`](#emitterwebhookeventname)
27 - [`EmitterWebhookEvent`](#emitterwebhookevent)
28- [License](#license)
29
30<!-- tocstop -->
31
32`@octokit/webhooks` helps to handle webhook events received from GitHub.
33
34[GitHub webhooks](https://docs.github.com/webhooks/) can be registered in multiple ways
35
361. In repository or organization settings on [github.com](https://github.com/).
372. Using the REST API for [repositories](https://docs.github.com/rest/reference/repos#webhooks) or [organizations](https://docs.github.com/rest/reference/orgs#webhooks/)
383. By [creating a GitHub App](https://docs.github.com/developers/apps/creating-a-github-app).
39
40Note that while setting a secret is optional on GitHub, it is required to be set in order to use `@octokit/webhooks`. Content Type must be set to `application/json`, `application/x-www-form-urlencoded` is not supported.
41
42## Usage
43
44```js
45// install with: npm install @octokit/webhooks
46import { Webhooks, createNodeMiddleware } from "@octokit/webhooks";
47import { createServer } from "node:http";
48const webhooks = new Webhooks({
49 secret: "mysecret",
50});
51
52webhooks.onAny(({ id, name, payload }) => {
53 console.log(name, "event received");
54});
55
56createServer(createNodeMiddleware(webhooks)).listen(3000);
57// can now receive webhook events at /api/github/webhooks
58```
59
60## Local development
61
62You can receive webhooks on your local machine or even browser using [EventSource](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) and [smee.io](https://smee.io/).
63
64Go to [smee.io](https://smee.io/) and <kbd>Start a new channel</kbd>. Then copy the "Webhook Proxy URL" and
65
661. enter it in the GitHub App’s "Webhook URL" input
672. pass it to the [EventSource](https://github.com/EventSource/eventsource) constructor, see below
68
69```js
70const webhookProxyUrl = "https://smee.io/IrqK0nopGAOc847"; // replace with your own Webhook Proxy URL
71const source = new EventSource(webhookProxyUrl);
72source.onmessage = (event) => {
73 const webhookEvent = JSON.parse(event.data);
74 webhooks
75 .verifyAndReceive({
76 id: webhookEvent["x-request-id"],
77 name: webhookEvent["x-github-event"],
78 signature: webhookEvent["x-hub-signature"],
79 payload: JSON.stringify(webhookEvent.body),
80 })
81 .catch(console.error);
82};
83```
84
85`EventSource` is a native browser API and can be polyfilled for browsers that don’t support it. In node, you can use the [`eventsource`](https://github.com/EventSource/eventsource) package: install with `npm install eventsource`, then `import EventSource from "eventsource";)`
86
87## API
88
891. [Constructor](#constructor)
902. [webhooks.sign()](#webhookssign)
913. [webhooks.verify()](#webhooksverify)
924. [webhooks.verifyAndReceive()](#webhooksverifyandreceive)
935. [webhooks.receive()](#webhooksreceive)
946. [webhooks.on()](#webhookson)
957. [webhooks.onAny()](#webhooksonany)
968. [webhooks.onError()](#webhooksonerror)
979. [webhooks.removeListener()](#webhooksremovelistener)
9810. [createNodeMiddleware()](#createnodemiddleware)
9911. [Webhook events](#webhook-events)
10012. [emitterEventNames](#emittereventnames)
101
102### Constructor
103
104```js
105new Webhooks({ secret /*, transform */ });
106```
107
108<table width="100%">
109 <tbody valign="top">
110 <tr>
111 <td>
112 <code>secret</code>
113 <em>(String)</em>
114 </td>
115 <td>
116 <strong>Required.</strong>
117 Secret as configured in GitHub Settings.
118 </td>
119 </tr>
120 <tr>
121 <td>
122 <code>transform</code>
123 <em>(Function)</em>
124 </td>
125 <td>
126 Only relevant for <a href="#webhookson"><code>webhooks.on</code></a>.
127 Transform emitted event before calling handlers. Can be asynchronous.
128 </td>
129 </tr>
130 <tr>
131 <td>
132 <code>log</code>
133 <em>
134 object
135 </em>
136 </td>
137 <td>
138
139Used for internal logging. Defaults to [`console`](https://developer.mozilla.org/en-US/docs/Web/API/console) with `debug` and `info` doing nothing.
140
141</td>
142 </tr>
143 </tbody>
144</table>
145
146Returns the `webhooks` API.
147
148### webhooks.sign()
149
150```js
151webhooks.sign(eventPayload);
152```
153
154<table width="100%">
155 <tbody valign="top">
156 <tr>
157 <td>
158 <code>eventPayload</code>
159 <em>
160 (String)
161 </em>
162 </td>
163 <td>
164 <strong>Required.</strong>
165 Webhook request payload as received from GitHub
166 </td>
167 </tr>
168 </tbody>
169</table>
170
171Returns a `signature` string. Throws error if `eventPayload` is not passed.
172
173The `sign` method can be imported as static method from [`@octokit/webhooks-methods`](https://github.com/octokit/webhooks-methods.js/#readme).
174
175### webhooks.verify()
176
177```js
178webhooks.verify(eventPayload, signature);
179```
180
181<table width="100%">
182 <tbody valign="top">
183 <tr>
184 <td>
185 <code>eventPayload</code>
186 <em>
187 (String)
188 </em>
189 </td>
190 <td>
191 <strong>Required.</strong>
192 Webhook event request payload as received from GitHub.
193 </td>
194 </tr>
195 <tr>
196 <td>
197 <code>signature</code>
198 <em>
199 (String)
200 </em>
201 </td>
202 <td>
203 <strong>Required.</strong>
204 Signature string as calculated by <code><a href="#webhookssign">webhooks.sign()</a></code>.
205 </td>
206 </tr>
207 </tbody>
208</table>
209
210Returns `true` or `false`. Throws error if `eventPayload` or `signature` not passed.
211
212The `verify` method can be imported as static method from [`@octokit/webhooks-methods`](https://github.com/octokit/webhooks-methods.js/#readme).
213
214### webhooks.verifyAndReceive()
215
216```js
217webhooks.verifyAndReceive({ id, name, payload, signature });
218```
219
220<table width="100%">
221 <tbody valign="top">
222 <tr>
223 <td>
224 <code>id</code>
225 <em>
226 String
227 </em>
228 </td>
229 <td>
230 Unique webhook event request id
231 </td>
232 </tr>
233 <tr>
234 <td>
235 <code>name</code>
236 <em>
237 String
238 </em>
239 </td>
240 <td>
241 <strong>Required.</strong>
242 Name of the event. (Event names are set as <a href="https://docs.github.com/developers/webhooks-and-events/webhook-events-and-payloads#delivery-headers"><code>X-GitHub-Event</code> header</a>
243 in the webhook event request.)
244 </td>
245 </tr>
246 <tr>
247 <td>
248 <code>payload</code>
249 <em>
250 String
251 </em>
252 </td>
253 <td>
254 <strong>Required.</strong>
255 Webhook event request payload as received from GitHub.
256 </td>
257 </tr>
258 <tr>
259 <td>
260 <code>signature</code>
261 <em>
262 (String)
263 </em>
264 </td>
265 <td>
266 <strong>Required.</strong>
267 Signature string as calculated by <code><a href="#webhookssign">webhooks.sign()</a></code>.
268 </td>
269 </tr>
270 </tbody>
271</table>
272
273Returns a promise.
274
275Verifies event using [webhooks.verify()](#webhooksverify), then handles the event using [webhooks.receive()](#webhooksreceive).
276
277Additionally, if verification fails, rejects the returned promise and emits an `error` event.
278
279Example
280
281```js
282import { Webhooks } from "@octokit/webhooks";
283const webhooks = new Webhooks({
284 secret: "mysecret",
285});
286eventHandler.on("error", handleSignatureVerificationError);
287
288// put this inside your webhooks route handler
289eventHandler
290 .verifyAndReceive({
291 id: request.headers["x-github-delivery"],
292 name: request.headers["x-github-event"],
293 payload: request.body,
294 signature: request.headers["x-hub-signature-256"],
295 })
296 .catch(handleErrorsFromHooks);
297```
298
299### webhooks.receive()
300
301```js
302webhooks.receive({ id, name, payload });
303```
304
305<table width="100%">
306 <tbody valign="top">
307 <tr>
308 <td>
309 <code>id</code>
310 <em>
311 String
312 </em>
313 </td>
314 <td>
315 Unique webhook event request id
316 </td>
317 </tr>
318 <tr>
319 <td>
320 <code>name</code>
321 <em>
322 String
323 </em>
324 </td>
325 <td>
326 <strong>Required.</strong>
327 Name of the event. (Event names are set as <a href="https://docs.github.com/developers/webhooks-and-events/webhook-events-and-payloads#delivery-headers"><code>X-GitHub-Event</code> header</a>
328 in the webhook event request.)
329 </td>
330 </tr>
331 <tr>
332 <td>
333 <code>payload</code>
334 <em>
335 Object
336 </em>
337 </td>
338 <td>
339 <strong>Required.</strong>
340 Webhook event request payload as received from GitHub.
341 </td>
342 </tr>
343 </tbody>
344</table>
345
346Returns a promise. Runs all handlers set with [`webhooks.on()`](#webhookson) in parallel and waits for them to finish. If one of the handlers rejects or throws an error, then `webhooks.receive()` rejects. The returned error has an `.errors` property which holds an array of all errors caught from the handlers. If no errors occur, `webhooks.receive()` resolves without passing any value.
347
348The `.receive()` method belongs to the `event-handler` module which can be used [standalone](src/event-handler/).
349
350### webhooks.on()
351
352```js
353webhooks.on(eventName, handler);
354webhooks.on(eventNames, handler);
355```
356
357<table width="100%">
358 <tbody valign="top">
359 <tr>
360 <td>
361 <code>eventName</code>
362 <em>
363 String
364 </em>
365 </td>
366 <td>
367 <strong>Required.</strong>
368 Name of the event. One of <a href="#webhook-events">GitHub's supported event names</a>, or (if the event has an action property) the name of an event followed by its action in the form of <code>&lt;event>.&lt;action></code>.
369 </td>
370 </tr>
371 <tr>
372 <td>
373 <code>eventNames</code>
374 <em>
375 Array
376 </em>
377 </td>
378 <td>
379 <strong>Required.</strong>
380 Array of event names.
381 </td>
382 </tr>
383 <tr>
384 <td>
385 <code>handler</code>
386 <em>
387 Function
388 </em>
389 </td>
390 <td>
391 <strong>Required.</strong>
392 Method to be run each time the event with the passed name is received.
393 the <code>handler</code> function can be an async function, throw an error or
394 return a Promise. The handler is called with an event object: <code>{id, name, payload}</code>.
395 </td>
396 </tr>
397 </tbody>
398</table>
399
400The `.on()` method belongs to the `event-handler` module which can be used [standalone](src/event-handler/).
401
402### webhooks.onAny()
403
404```js
405webhooks.onAny(handler);
406```
407
408<table width="100%">
409 <tbody valign="top">
410 <tr>
411 <td>
412 <code>handler</code>
413 <em>
414 Function
415 </em>
416 </td>
417 <td>
418 <strong>Required.</strong>
419 Method to be run each time any event is received.
420 the <code>handler</code> function can be an async function, throw an error or
421 return a Promise. The handler is called with an event object: <code>{id, name, payload}</code>.
422 </td>
423 </tr>
424 </tbody>
425</table>
426
427The `.onAny()` method belongs to the `event-handler` module which can be used [standalone](src/event-handler/).
428
429### webhooks.onError()
430
431```js
432webhooks.onError(handler);
433```
434
435If a webhook event handler throws an error or returns a promise that rejects, an error event is triggered. You can use this handler for logging or reporting events. The passed error object has a .event property which has all information on the event.
436
437Asynchronous `error` event handler are not blocking the `.receive()` method from completing.
438
439<table width="100%">
440 <tbody valign="top">
441 <tr>
442 <td>
443 <code>handler</code>
444 <em>
445 Function
446 </em>
447 </td>
448 <td>
449 <strong>Required.</strong>
450 Method to be run each time a webhook event handler throws an error or returns a promise that rejects.
451 The <code>handler</code> function can be an async function,
452 return a Promise. The handler is called with an error object that has a .event property which has all the information on the event: <code>{id, name, payload}</code>.
453 </td>
454 </tr>
455 </tbody>
456</table>
457
458The `.onError()` method belongs to the `event-handler` module which can be used [standalone](src/event-handler/).
459
460### webhooks.removeListener()
461
462```js
463webhooks.removeListener(eventName, handler);
464webhooks.removeListener(eventNames, handler);
465```
466
467<table width="100%">
468 <tbody valign="top">
469 <tr>
470 <td>
471 <code>eventName</code>
472 <em>
473 String
474 </em>
475 </td>
476 <td>
477 <strong>Required.</strong>
478 Name of the event. One of <a href="#webhook-events">GitHub's supported event names</a>, or (if the event has an action property) the name of an event followed by its action in the form of <code>&lt;event>.&lt;action></code>, or '*' for the <code>onAny()</code> method or 'error' for the <code>onError()</code> method.
479 </td>
480 </tr>
481 <tr>
482 <td>
483 <code>eventNames</code>
484 <em>
485 Array
486 </em>
487 </td>
488 <td>
489 <strong>Required.</strong>
490 Array of event names.
491 </td>
492 </tr>
493 <tr>
494 <td>
495 <code>handler</code>
496 <em>
497 Function
498 </em>
499 </td>
500 <td>
501 <strong>Required.</strong>
502 Method which was previously passed to <code><a href="webhookson">webhooks.on()</a></code>. If the same handler was registered multiple times for the same event, only the most recent handler gets removed.
503 </td>
504 </tr>
505 </tbody>
506</table>
507
508The `.removeListener()` method belongs to the `event-handler` module which can be used [standalone](src/event-handler/).
509
510### createNodeMiddleware()
511
512```js
513import { createServer } from "node:http";
514import { Webhooks, createNodeMiddleware } from "@octokit/webhooks";
515
516const webhooks = new Webhooks({
517 secret: "mysecret",
518});
519
520const middleware = createNodeMiddleware(webhooks, { path: "/webhooks" });
521createServer(async (req, res) => {
522 // `middleware` returns `false` when `req` is unhandled (beyond `/webhooks`)
523 if (await middleware(req, res)) return;
524 res.writeHead(404);
525 res.end();
526}).listen(3000);
527// can now receive user authorization callbacks at POST /webhooks
528```
529
530The middleware returned from `createNodeMiddleware` can also serve as an
531`Express.js` middleware directly.
532
533<table width="100%">
534 <tbody valign="top">
535 <tr>
536 <td>
537 <code>webhooks</code>
538 <em>
539 Webhooks instance
540 </em>
541 </td>
542 <td>
543 <strong>Required.</strong>
544 </td>
545 </tr>
546 <tr>
547 <td>
548 <code>path</code>
549 <em>
550 string
551 </em>
552 </td>
553 <td>
554 Custom path to match requests against. Defaults to <code>/api/github/webhooks</code>.
555 </td>
556 </tr>
557 <tr>
558 <td>
559 <code>log</code>
560 <em>
561 object
562 </em>
563 </td>
564 <td>
565
566Used for internal logging. Defaults to [`console`](https://developer.mozilla.org/en-US/docs/Web/API/console) with `debug` and `info` doing nothing.
567
568</td>
569 </tr>
570 <tbody>
571</table>
572
573### Webhook events
574
575See the full list of [event types with example payloads](https://docs.github.com/developers/webhooks-and-events/webhook-events-and-payloads/).
576
577If there are actions for a webhook, events are emitted for both, the webhook name as well as a combination of the webhook name and the action, e.g. `installation` and `installation.created`.
578
579<!-- autogenerated via scripts/generate-types.ts -->
580
581| Event | Actions |
582| ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
583| [`branch_protection_configuration`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#branch_protection_configuration) | `disabled`<br>`enabled` |
584| [`branch_protection_rule`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#branch_protection_rule) | `created`<br>`deleted`<br>`edited` |
585| [`check_run`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#check_run) | `completed`<br>`created`<br>`requested_action`<br>`rerequested` |
586| [`check_suite`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#check_suite) | `completed`<br>`requested`<br>`rerequested` |
587| [`code_scanning_alert`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#code_scanning_alert) | `appeared_in_branch`<br>`closed_by_user`<br>`created`<br>`fixed`<br>`reopened`<br>`reopened_by_user` |
588| [`commit_comment`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#commit_comment) | `created` |
589| [`create`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#create) | |
590| [`custom_property`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#custom_property) | `created`<br>`deleted`<br>`updated` |
591| [`custom_property_values`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#custom_property_values) | `updated` |
592| [`delete`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#delete) | |
593| [`dependabot_alert`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#dependabot_alert) | `auto_dismissed`<br>`auto_reopened`<br>`created`<br>`dismissed`<br>`fixed`<br>`reintroduced`<br>`reopened` |
594| [`deploy_key`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#deploy_key) | `created`<br>`deleted` |
595| [`deployment`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#deployment) | `created` |
596| [`deployment_protection_rule`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#deployment_protection_rule) | `requested` |
597| [`deployment_review`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#deployment_review) | `approved`<br>`rejected`<br>`requested` |
598| [`deployment_status`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#deployment_status) | `created` |
599| [`discussion`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#discussion) | `answered`<br>`category_changed`<br>`closed`<br>`created`<br>`deleted`<br>`edited`<br>`labeled`<br>`locked`<br>`pinned`<br>`reopened`<br>`transferred`<br>`unanswered`<br>`unlabeled`<br>`unlocked`<br>`unpinned` |
600| [`discussion_comment`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#discussion_comment) | `created`<br>`deleted`<br>`edited` |
601| [`fork`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#fork) | |
602| [`github_app_authorization`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#github_app_authorization) | `revoked` |
603| [`gollum`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#gollum) | |
604| [`installation`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#installation) | `created`<br>`deleted`<br>`new_permissions_accepted`<br>`suspend`<br>`unsuspend` |
605| [`installation_repositories`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#installation_repositories) | `added`<br>`removed` |
606| [`installation_target`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#installation_target) | `renamed` |
607| [`issue_comment`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#issue_comment) | `created`<br>`deleted`<br>`edited` |
608| [`issues`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#issues) | `assigned`<br>`closed`<br>`deleted`<br>`demilestoned`<br>`edited`<br>`labeled`<br>`locked`<br>`milestoned`<br>`opened`<br>`pinned`<br>`reopened`<br>`transferred`<br>`unassigned`<br>`unlabeled`<br>`unlocked`<br>`unpinned` |
609| [`label`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#label) | `created`<br>`deleted`<br>`edited` |
610| [`marketplace_purchase`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#marketplace_purchase) | `cancelled`<br>`changed`<br>`pending_change`<br>`pending_change_cancelled`<br>`purchased` |
611| [`member`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#member) | `added`<br>`edited`<br>`removed` |
612| [`membership`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#membership) | `added`<br>`removed` |
613| [`merge_group`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#merge_group) | `checks_requested`<br>`destroyed` |
614| [`meta`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#meta) | `deleted` |
615| [`milestone`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#milestone) | `closed`<br>`created`<br>`deleted`<br>`edited`<br>`opened` |
616| [`org_block`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#org_block) | `blocked`<br>`unblocked` |
617| [`organization`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#organization) | `deleted`<br>`member_added`<br>`member_invited`<br>`member_removed`<br>`renamed` |
618| [`package`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#package) | `published`<br>`updated` |
619| [`page_build`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#page_build) | |
620| [`personal_access_token_request`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#personal_access_token_request) | `approved`<br>`cancelled`<br>`created`<br>`denied` |
621| [`ping`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#ping) | |
622| [`project`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#project) | `closed`<br>`created`<br>`deleted`<br>`edited`<br>`reopened` |
623| [`project_card`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#project_card) | `converted`<br>`created`<br>`deleted`<br>`edited`<br>`moved` |
624| [`project_column`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#project_column) | `created`<br>`deleted`<br>`edited`<br>`moved` |
625| [`projects_v2`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#projects_v2) | `closed`<br>`created`<br>`deleted`<br>`edited`<br>`reopened` |
626| [`projects_v2_item`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#projects_v2_item) | `archived`<br>`converted`<br>`created`<br>`deleted`<br>`edited`<br>`reordered`<br>`restored` |
627| [`public`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#public) | |
628| [`pull_request`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request) | `assigned`<br>`auto_merge_disabled`<br>`auto_merge_enabled`<br>`closed`<br>`converted_to_draft`<br>`demilestoned`<br>`dequeued`<br>`edited`<br>`enqueued`<br>`labeled`<br>`locked`<br>`milestoned`<br>`opened`<br>`ready_for_review`<br>`reopened`<br>`review_request_removed`<br>`review_requested`<br>`synchronize`<br>`unassigned`<br>`unlabeled`<br>`unlocked` |
629| [`pull_request_review`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request_review) | `dismissed`<br>`edited`<br>`submitted` |
630| [`pull_request_review_comment`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request_review_comment) | `created`<br>`deleted`<br>`edited` |
631| [`pull_request_review_thread`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request_review_thread) | `resolved`<br>`unresolved` |
632| [`push`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#push) | |
633| [`registry_package`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#registry_package) | `published`<br>`updated` |
634| [`release`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#release) | `created`<br>`deleted`<br>`edited`<br>`prereleased`<br>`published`<br>`released`<br>`unpublished` |
635| [`repository`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#repository) | `archived`<br>`created`<br>`deleted`<br>`edited`<br>`privatized`<br>`publicized`<br>`renamed`<br>`transferred`<br>`unarchived` |
636| [`repository_advisory`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#repository_advisory) | `published`<br>`reported` |
637| [`repository_dispatch`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#repository_dispatch) | `sample` |
638| [`repository_import`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#repository_import) | |
639| [`repository_ruleset`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#repository_ruleset) | `created`<br>`deleted`<br>`edited` |
640| [`repository_vulnerability_alert`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#repository_vulnerability_alert) | `create`<br>`dismiss`<br>`reopen`<br>`resolve` |
641| [`secret_scanning_alert`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#secret_scanning_alert) | `created`<br>`reopened`<br>`resolved`<br>`revoked`<br>`validated` |
642| [`secret_scanning_alert_location`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#secret_scanning_alert_location) | `created` |
643| [`security_advisory`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#security_advisory) | `published`<br>`updated`<br>`withdrawn` |
644| [`security_and_analysis`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#security_and_analysis) | |
645| [`sponsorship`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#sponsorship) | `cancelled`<br>`created`<br>`edited`<br>`pending_cancellation`<br>`pending_tier_change`<br>`tier_changed` |
646| [`star`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#star) | `created`<br>`deleted` |
647| [`status`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#status) | |
648| [`team`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#team) | `added_to_repository`<br>`created`<br>`deleted`<br>`edited`<br>`removed_from_repository` |
649| [`team_add`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#team_add) | |
650| [`watch`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#watch) | `started` |
651| [`workflow_dispatch`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#workflow_dispatch) | |
652| [`workflow_job`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#workflow_job) | `completed`<br>`in_progress`<br>`queued`<br>`waiting` |
653| [`workflow_run`](https://docs.github.com/en/webhooks/webhook-events-and-payloads#workflow_run) | `completed`<br>`in_progress`<br>`requested` |
654
655<!-- /autogenerated via scripts/generate-types.ts -->
656
657### emitterEventNames
658
659A read only tuple containing all the possible combinations of the webhook events + actions listed above. This might be useful in GUI and input validation.
660
661```js
662import { emitterEventNames } from "@octokit/webhooks";
663emitterEventNames; // ["check_run", "check_run.completed", ...]
664```
665
666## TypeScript
667
668The types for the webhook payloads are sourced from [`@octokit/openapi-webhooks-types`](https://github.com/octokit/openapi-webhooks/tree/main/packages/openapi-webhooks-types),
669which can be used by themselves.
670
671In addition to these types, `@octokit/webhooks` exports 2 types specific to itself:
672
673Note that changes to the exported types are not considered breaking changes, as the changes will not impact production code, but only fail locally or during CI at build time.
674
675> [!IMPORTANT]
676> As we use [conditional exports](https://nodejs.org/api/packages.html#conditional-exports), you will need to adapt your `tsconfig.json` by setting `"moduleResolution": "node16", "module": "node16"`.
677>
678> See the TypeScript docs on [package.json "exports"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports).<br>
679> See this [helpful guide on transitioning to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) from [@sindresorhus](https://github.com/sindresorhus)
680
681**⚠️ Caution ⚠️**: Webhooks Types are expected to be used with the [`strictNullChecks` option](https://www.typescriptlang.org/tsconfig#strictNullChecks) enabled in your `tsconfig`. If you don't have this option enabled, there's the possibility that you get `never` as the inferred type in some use cases. See [octokit/webhooks#395](https://github.com/octokit/webhooks/issues/395) for details.
682
683### `EmitterWebhookEventName`
684
685A union of all possible events and event/action combinations supported by the event emitter, e.g. `"check_run" | "check_run.completed" | ... many more ... | "workflow_run.requested"`.
686
687### `EmitterWebhookEvent`
688
689The object that is emitted by `@octokit/webhooks` as an event; made up of an `id`, `name`, and `payload` properties.
690An optional generic parameter can be passed to narrow the type of the `name` and `payload` properties based on event names or event/action combinations, e.g. `EmitterWebhookEvent<"check_run" | "code_scanning_alert.fixed">`.
691
692## License
693
694[MIT](LICENSE.md)