Skip to content

Commit

Permalink
Add support for 'pull \d+', fix config issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Socol committed Oct 25, 2011
1 parent ffff76a commit ac79db4
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -2,4 +2,4 @@
*.pid
pid
node_modules
*.ini
config.ini
39 changes: 39 additions & 0 deletions example.config.ini
@@ -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
39 changes: 36 additions & 3 deletions jig.js
Expand Up @@ -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);
Expand All @@ -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();
});

Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions package.json
@@ -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",
Expand All @@ -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"
Expand Down

0 comments on commit ac79db4

Please sign in to comment.