Permalink
Browse files

Add support for 'pull \d+', fix config issues.

  • Loading branch information...
1 parent ffff76a commit ac79db423a9fe7b3b935af8e4f083f90bf4b2f46 James Socol committed Oct 25, 2011
Showing with 79 additions and 6 deletions.
  1. +1 −1 .gitignore
  2. +39 −0 example.config.ini
  3. +36 −3 jig.js
  4. +3 −2 package.json
View
@@ -2,4 +2,4 @@
*.pid
pid
node_modules
-*.ini
+config.ini
View
@@ -0,0 +1,39 @@
+[process]
+daemon = no
+logfile = jig.log
+pidfile = jig.pid
+
+[http]
+; IP address to bind.
+host = 0.0.0.0
+; Port to listen.
+port = 8000
+; Hostname of Jenkins.
+jenkins = your.ci.server
+; Use HTTPS instead of HTTP to talk to Jenkins?
+ssl = no
+;auth = Basic base64encodeddata
+
+[irc]
+nick = jig
+server = your.irc.server
+channels = #comma,#separated,#channels
+
+[github]
+user = username
+repo = reponame
+
+[branches]
+master = refs/heads/master
+next = refs/heads/test
+
+[branch:master]
+path = /job/master/build
+token = your-build-token
+; List commits in IRC?
+commits = yes
+
+[branch:test]
+path = /job/test/build
+token = another-build-token
+commits = no
View
39 jig.js
@@ -11,7 +11,10 @@ var http = require('http'),
}
}).parseArgs(),
daemon = require('daemon'),
- IniReader = require('inireader').IniReader;
+ IniReader = require('inireader').IniReader,
+ GitHubApi = require('github').GitHubApi,
+ github = new GitHubApi(),
+ PULLREQRE = /pull\s+(?:req\s+)?#?(\d+)/i;
inireader = new IniReader();
inireader.load(options.config);
@@ -24,7 +27,7 @@ var CHANNELS = CONFIG.irc.channels.split(','),
IRCHOST = CONFIG.irc.server,
IRCNICK = CONFIG.irc.nick;
-CHANNELS.forEach(function(i, c) {
+CHANNELS.forEach(function(c, i) {
CHANNELS[i] = c.trim();
});
@@ -45,10 +48,40 @@ function interpolate(fmt, obj, named) {
var client = new irc.Client(IRCHOST, IRCNICK, {
channels: CHANNELS
}).on('error', function(err) {
- if (err.rawCommand != '421')
+ if (err.rawCommand != '421') {
console.log(err);
+ if (err.hasOwnProperty('stack')) {
+ console.log(err.stack);
+ }
+ }
+});
+
+
+var response = '\00303#%(number)s\003 - \00307%(title)s\003 - %(url)s';
+client.on('message', function(from, to, msg) {
+ if (to.indexOf('#') != 0) return;
+ msg = msg.toLowerCase();
+ if (msg.indexOf(IRCNICK) == 0 && /botsnack\s*$/i.test(msg)) {
+ client.say(to, 'YUMMY');
+ } else if (PULLREQRE.test(msg)) {
+ var m = PULLREQRE.exec(msg);
+ github.getPullApi().show(CONFIG.github.user, CONFIG.github.repo, m[1], function(err, pull) {
+ if (err || !pull) {
+ console.log(err);
+ return;
+ }
+ client.say(
+ to,
+ interpolate(response, {
+ 'number': pull.number,
+ 'title': pull.title,
+ 'url': pull.html_url
+ }, true));
+ });
+ }
});
+
var server = http.createServer(function(req, res) {
if (req.method != 'POST') {
res.statusCode = 405;
View
@@ -1,7 +1,7 @@
{
"name": "jig",
"description": "Jenkins-IRC-Github integration.",
- "version": "0.1.0",
+ "version": "0.2.0",
"author": {
"name": "James Socol",
"email": "james@mozilla.com",
@@ -15,7 +15,8 @@
"nomnom": ">=0.4.2",
"irc": ">=0.2.0",
"daemon": ">=0.3.0",
- "inireader": ">=0.2.0"
+ "inireader": ">=0.2.0",
+ "github": ">=0.0.6"
},
"bin": {
"jig": "./jig.js"

0 comments on commit ac79db4

Please sign in to comment.