From d3bd1baae304d01606dd7a4757a4044380269183 Mon Sep 17 00:00:00 2001 From: Kaustav Das Modak Date: Sat, 20 Jun 2015 22:14:33 +0530 Subject: [PATCH] First test of integrating Github webhook with push event Signed-off-by: Kaustav Das Modak --- config.js.example | 21 +++++++++++++++++++++ package.json | 3 ++- server.js | 23 +++++++++++++++++++++-- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/config.js.example b/config.js.example index 3f95cb5..8c26cc0 100644 --- a/config.js.example +++ b/config.js.example @@ -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: { diff --git a/package.json b/package.json index 3cd879f..655157a 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "url": "https://github.com/applait/bottle/issues" }, "dependencies": { - "irc": "~0.3.12" + "irc": "~0.3.12", + "githubhook": "~1.2.0" } } diff --git a/server.js b/server.js index a909874..0421eb6 100644 --- a/server.js +++ b/server.js @@ -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, { @@ -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();