Permalink
Browse files

Add some nice lil' comments.

  • Loading branch information...
1 parent 6f34fc2 commit dbc0ac3de844650b4fca9f7008d248384518ad2f @johnhamelink committed Feb 20, 2012
Showing with 44 additions and 9 deletions.
  1. +9 −0 bitbucket.js
  2. +25 −0 github.js
  3. +10 −9 httpd.js
View
@@ -3,13 +3,15 @@ module.exports = flow = {
express: null,
pubsub: null,
bitly: null,
+ // On load, inject in all the modules we need
init: function(robot,express,pubsub){
this.robot = robot;
this.express = express;
this.pubsub = pubsub;
this.setUpExpress();
this.setUpHubot();
},
+ // Attach routes to catch data with.
setUpExpress: function(){
this.express.get('/bitbucket',function(req,res){
res.send('POST this URL with the payload parameter from bitbucket here.');
@@ -20,19 +22,26 @@ module.exports = flow = {
res.send('Received');
});
},
+ // When Hubot hears anything, remove all listeners, then
+ // re-add the listener to get it to send a message to the adapter.
setUpHubot: function(){
this.robot.hear('',function(msg){
flow.pubsub.removeAllListeners('bitbucket/newCommit');
flow.pubsub.on('bitbucket/newCommit',function(payload){
+ // Remove newlines from the commit message.
payload.commits[0].message = payload.commits[0].message.replace(/\n/gm,"");
var url = null;
var Bitly = require('bitly');
var bitly = new Bitly('s0l1dsnak3123', 'R_36bd50ae52c1ad2de6eb92fe4ee3233d');
+ // Bit.ly up the URL :)
bitly.shorten('https://bitbucket.org' payload.repository.absolute_url 'changeset/' payload.commits[0].node,function(err,resp){
+ // If there's an error, bottle out.
if(err) throw err;
console.log(resp.data);
url = resp.data['url'];
+ // Build the message based on the variables Bitbucket gave us.
var response = '\00307[' payload.repository.name ']\003 \00304 ' payload.commits.length '\003 \00300' payload.commits[0].author '\003: "' payload.commits[0].message '" \00302' url '\003 \00304ChangeSet: \003 ' payload.commits[0].node;
+ // Send the message.
msg.send(response);
});
});
View
@@ -1,14 +1,32 @@
+/*
+ * Github Post-commit hook plugin for hubot.
+ *
+ * In Github, add a post-commit hook, and set it to POST.
+ * In the "URL" field, set the url to http://<your-server-name>:<hubot web port>/github
+ *
+ * You can test you have the correct URL by GETting the same URL.
+ */
module.exports = flow = {
robot: null,
express: null,
pubsub: null,
+ /*
+ * - Import the robot object from hubot
+ * - Import the express object from http plugin
+ * - Include a listener for any kind of message,
+ * so we can get the "msg" object for sending.
+ */
init: function(robot,express,pubsub){
this.robot = robot;
this.express = express;
this.pubsub = express;
this.setUpExpress();
this.setUpHubot();
},
+
+ /*
+ * Add a test express route.
+ */
setUpExpress: function(){
this.express.get('/github',function(req,res){
res.send('POST this URL with the payload parameter from github here.');
@@ -19,6 +37,13 @@ module.exports = flow = {
res.send('Received');
});
},
+
+ /*
+ * - Set up an event listener within hubot for any kind of message from
+ * the adapter (eg, IRC).
+ * - Set up an internal listener which uses the msg object to send data
+ * back to the adapter.
+ */
setUpHubot: function(){
this.robot.hear('',function(msg){
flow.pubsub.removeAllListeners('github/newCommit');
View
@@ -1,13 +1,14 @@
module.exports = function(robot){
- var events = require('events').EventEmitter;
- var pubsub = new events();
- pubsub.setMaxListeners(1);
+ var events = require('events').EventEmitter;
+ var pubsub = new events();
var express = require('express');
- express = express.createServer(express.logger(),express.bodyParser());
+ express = express.createServer(express.logger(),express.bodyParser());
+
+ var github = require('./github.js').init(robot,express,pubsub),
+ bitbucket = require('./bitbucket.js').init(robot,express,pubsub),
+ skeleton = require('./skeletonhttpd.js').init(robot,express,pubsub),
+ cloudkick = require('./cloudkick.js').init(robot,express,pubsub);
- var github = require('./github.js').init(robot,express,pubsub),
- bitbucket = require('./bitbucket.js').init(robot,express,pubsub),
- skeleton = require('./skeletonhttpd.js').init(robot,express,pubsub),
- cloudkick = require('./cloudkick.js').init(robot,express,pubsub);
- express.listen(1337);
+ pubsub.setMaxListeners(1);
+ express.listen(1337);
};

0 comments on commit dbc0ac3

Please sign in to comment.