git-hook-mw

1.0.6 • Public • Published

git-hook-mw

ExpressJs middleware for receiving Github Webhook requests with a NodeJS EventEmitter

  1. Install
  2. Set up a webhook for the endpoint you specified using the repository settings page on Github
  3. Add to your Express Project
  4. 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

Package Sidebar

Install

npm i git-hook-mw

Weekly Downloads

0

Version

1.0.6

License

ISC

Unpacked Size

4.38 kB

Total Files

3

Last publish

Collaborators

  • twhanawa