Skip to content

Commit

Permalink
First test of integrating Github webhook with push event
Browse files Browse the repository at this point in the history
Signed-off-by: Kaustav Das Modak <[email protected]>
  • Loading branch information
Kaustav Das Modak committed Jun 20, 2015
1 parent a7390ec commit d3bd1ba
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
21 changes: 21 additions & 0 deletions config.js.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
module.exports = {

// Github config
github: {

// Webhook config
webhook: {

// IP to run the webhook on
ip: "0.0.0.0",

// Port to run the webhook on
port: 8081,

// Path to webhook
path: "push",

// Webhook secret
secret: ""
}

},

// IRC config
irc: {

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"url": "https://github.com/applait/bottle/issues"
},
"dependencies": {
"irc": "~0.3.12"
"irc": "~0.3.12",
"githubhook": "~1.2.0"
}
}
23 changes: 21 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
* Bottle server start
*/

var irc = { module: require("irc"), servers: {}, clients: {} };
var irc = { module: require("irc"), servers: {}, clients: {} },
util = require("util"),
config = require("./config");

var config = require("./config");
// set up github webhook listener
var gh_webhook = require('githubhook')({
host: config.github.webhook.ip || "0.0.0.0",
port: config.github.webhook.port || 8081,
path: config.github.webhook.path || "push",
secret: config.github.webhook.secret
});

// Spin off IRC client instance
irc.clients.freenode = new irc.module.Client(config.irc.freenode.server, config.irc.freenode.nick, {
Expand All @@ -23,3 +31,14 @@ irc.clients.freenode = new irc.module.Client(config.irc.freenode.server, config.
retryDelay: 5000,
debug: true
});

// listen to push on github on branch master
gh_webhook.on('push', function (repo, ref, data) {
util.log("GH push", data);
irc.clients.freenode.say("#applait",
["[Github]", data.pusher.name, "pushed", data.commits.length, "commits to",
data.repository.full_name, data.compare].join(" "));
});

// listen to github push
gh_webhook.listen();

0 comments on commit d3bd1ba

Please sign in to comment.