git-hook-mw
v1.0.6
Published
Middleware for catching git webhooks
Downloads
10
Maintainers
Readme
git-hook-mw
ExpressJs middleware for receiving Github Webhook requests with a NodeJS EventEmitter
Install
Set up a webhook for the endpoint you specified using the repository settings page on Github
Add to your Express Project
Add Webhook Event handlers
Run in your shell
Install
$: npm i git-hook-mw
Add to your Express App:
Require the module
const {
hookMW,
HookError,
hookEvents,
} = require('git-hook-mw');
// set 'yourhookendpoint' to the endpoint you specify on github
app.use(/yourhookendpoint, hookMW);
Handle a Webhook event
// 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)
});
Check for errors
app.use((err, req, res, next) => {
// assuming you checked if an error is defined
if (HookError.isTest(err)) {
console.log(` Error is Hook Error`);
}
});
Notes:
Webhook EventListener Argument Attributes:
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 |
Current Webhook Settings Page
https://github.com/<username>/<repository>/settings/hooks