gith[ooks] - a simple node server that responds to github post-receive events with meaningful data
Install the module with:
npm install gith
In your node application, require gith and create a gith server. You can specify a port now, or
you can use the
.listen( portNumber ) method later.
// create a gith server on port 9001var gith = ;
Pass an object of how you want to filter gith (if at all) and subscribe to an event.
Be sure github.com is sending payload data to your server. From your repository root
Admin > Service Hooks > WebHook URLs and add your server url, e.g.,
The object passed into
gith() can utilize four parameters (
All of these can either be an exact match string, a regular expression or a function.
You can either omit the key that you don't want to filter (e.g., we would get every file and tag in the above
example) or use
* to specifiy that it's a wildcard.
Events available are:
all- as long as the filtering passed, this will get fired
The github payload is very detailed, but can be a bit excessive.
This is the payload that gith gives you:
original: the-original-github-payloadfiles:all:added:deleted:modified:tag: tag /* if a tagging operation */branch: branch /* if working on a branch */repo: the-repo-namesha: the-now-current-shatime: when-it-was-pushedurls:head: current-shabranch: branch-url-if-availabletag: sha-url-of-tag-if-availablerepo: repo-urlcompare: compare-urlreset: did-the-head-get-resetpusher: github-username-of-pusherowner: github-username-of-repo-owner
Note that this payload will only be fully available in case of standard
push hooks (see below for more information).
The gith function returns a new Gith object that has all of the EventEmitter2 methods.
On the gith server, there are three additional methods available:
This closes the gith server
If you didn't pass in a port to
.create() when you required gith, this
will start the server on the specified port
You can broadcast a payload to the gith server manually.
When you use Github UI to declare a web hook, it's only attached to the
Whenever you want to attach you hook to other events, you will have to use the API. In this case,
gith may not be able to fully interpret the original payload, and you should consider the simplified payload as unreliable. In those cases, just use
Copyright (c) 2012 Dan Heberden Licensed under the MIT license.