You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GitHub allows you to register **[Webhooks](https://developer.github.com/webhooks/)** for your repositories. Each time an event occurs on your repository, whether it be pushing code, filling issues or creating pull requests, the webhook address you register can be configured to be pinged with details.
8
6
9
7
This library is a small handler (or "middleware" if you must) for Node.js web servers that handles all the logic of receiving and verifying webhook requests from GitHub.
10
8
9
+
## Requirements
10
+
11
+
Node.js >= 20
12
+
11
13
## Tips
12
14
13
15
In Github Webhooks settings, Content type must be `application/json`.
@@ -17,28 +19,29 @@ In Github Webhooks settings, Content type must be `application/json`.
17
19
## Example
18
20
19
21
```js
20
-
var http =require('http')
21
-
var createHandler =require('github-webhook-handler')
22
-
var handler =createHandler({ path:'/webhook', secret:'myhashsecret' })
console.log('Received an issue event for %s action=%s: #%d %s',
43
46
event.payload.repository.name,
44
47
event.payload.action,
@@ -47,11 +50,11 @@ handler.on('issues', function (event) {
47
50
})
48
51
```
49
52
50
-
for multiple handlers, please see [multiple-handlers-issue](https://github.com/rvagg/github-webhook-handler/pull/22#issuecomment-274301907).
53
+
For multiple handlers, see [multiple-handlers-issue](https://github.com/rvagg/github-webhook-handler/pull/22#issuecomment-274301907).
51
54
52
55
## API
53
56
54
-
github-webhook-handler exports a single function, use this function to *create* a webhook handler by passing in an *options* object. Your options object should contain:
57
+
github-webhook-handler exports a single function. Use this function to *create* a webhook handler by passing in an *options* object. Your options object should contain:
55
58
56
59
*`"path"`: the complete case sensitive path/route to match when looking at `req.url` for incoming requests. Any request not matching this path will cause the callback function to the handler to be called (sometimes called the `next` handler).
57
60
*`"secret"`: this is a hash key used for creating the SHA-1 HMAC signature of the JSON blob sent by GitHub. You should register the same secret key with GitHub. Any request not delivering a `X-Hub-Signature` that matches the signature generated using this key against the blob will be rejected and cause an `'error'` event (also the callback will be called with an `Error` object).
@@ -66,13 +69,14 @@ See the [GitHub Webhooks documentation](https://developer.github.com/webhooks/)
66
69
Included in the distribution is an *events.json* file which maps the event names to descriptions taken from the API:
67
70
68
71
```js
69
-
var events =require('github-webhook-handler/events')
70
-
Object.keys(events).forEach(function (event) {
71
-
console.log(event, '=', events[event])
72
-
})
72
+
importeventsfrom'github-webhook-handler/events.json' with { type: 'json' }
73
+
74
+
for (const [event, description] ofObject.entries(events)) {
75
+
console.log(event, '=', description)
76
+
}
73
77
```
74
78
75
-
Additionally, there is a special `'*'`even you can listen to in order to receive _everything_.
79
+
Additionally, there is a special `'*'`event you can listen to in order to receive _everything_.
0 commit comments