ExpressJs middleware for receiving Github Webhook requests with a NodeJS EventEmitter
-
Set up a webhook for the endpoint you specified using the repository settings page on Github
$: npm i git-hook-mw
const {
hookMW,
HookError,
hookEvents,
} = require('git-hook-mw');
// set 'yourhookendpoint' to the endpoint you specify on github
app.use(/yourhookendpoint, hookMW);
// hookEvents.on('<event>', EventListener)
// Handle a push event
hookEvents.on('push', function(hook) {
console.log(hook)
});
// Handle all events
hookEvents.on('*', function(hook) {
console.log(hook)
});
app.use((err, req, res, next) => {
// assuming you checked if an error is defined
if (HookError.isTest(err)) {
console.log(` Error is Hook Error`);
}
});
Attribute | Description |
---|---|
delivery |
x-github-delivery Webhook request header |
event |
x-github-event Webhook request header |
id |
x-github-hook-id Webhook request header |
payload | Webhook payload |
signature |
x-hub-signature Webhook request header |
signature256 |
x-hub-signature-256 Webhook request header |
target |
x-github-hook-installation-target-id Webhook request header |
type |
x-github-hook-installation-target-type Webhook request header |
https://github.com/<username>/<repository>/settings/hooks