hubhookdeprecated

github post-receive service hook handler

Usage no npm install needed!

<script type="module">
  import hubhook from 'https://cdn.skypack.dev/hubhook';
</script>

README

hubhook

A github post-commit service hook handler

example:

example.js

var hook = require('hubhook')();

var http = require('http');

http.createServer(function (req, res) {
  if (req.method === 'POST' && req.url === '/api/webhooks/git') {
    return hook.handle(req, res);
  }
  res.statusCode = 404;
  res.setHeader('content-type': 'application/json');
  res.end(JSON.stringify({
    error: 404,
    message: 'not_found',
    hints: 'POST to /api/webhooks/git'
  }, true, 2));
}).listen(7005);

hook.on('payload', function (payload) {
  console.log(payload);
});

output:

(example with a random repo of mine)

$ node example.js
{ pusher: { name: 'none' },
  repository: 
   { name: 'my-little-proxy',
     size: 168,
     has_wiki: true,
     created_at: '2012-09-16T12:08:06-07:00',
     private: false,
     watchers: 6,
     url: 'https://github.com/jesusabdullah/my-little-proxy',
     fork: false,
     language: 'JavaScript',
     pushed_at: '2012-09-23T02:04:52-07:00',
     id: 5832190,

***snip***

API:

var HubHook = require('hubhook')

var hook = new HubHook;

A constructor. Can call without new like so: var hook = HubHook().

hook.handle(req, res)

Handle the request as a webhook post.

event: "payload"

This event is emitted after hook.handle processes a hook payload.

Tests:

$ npm test

License:

MIT/X11