1.0.6 • Published 3 years ago

git-hook-mw v1.0.6

Weekly downloads
2
License
ISC
Repository
github
Last release
3 years ago

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:

AttributeDescription
deliveryx-github-delivery Webhook request header
eventx-github-event Webhook request header
idx-github-hook-id Webhook request header
payloadWebhook payload
signaturex-hub-signature Webhook request header
signature256x-hub-signature-256 Webhook request header
targetx-github-hook-installation-target-id Webhook request header
typex-github-hook-installation-target-type Webhook request header

Current Webhook Settings Page

https://github.com/<username>/<repository>/settings/hooks

Git Webhook Documentation

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago