Build a reports map;

This commit is contained in:
Benjamin Bouvier 2016-06-24 01:39:10 +02:00
parent ca284f4262
commit 107c3d83ad
2 changed files with 22 additions and 5 deletions

View File

@ -3,7 +3,10 @@ module.exports = {
server: 'chat.freenode.net', server: 'chat.freenode.net',
// List of channels / people to report to. // List of channels / people to report to.
channels: ['#horsejs'], reports: {
'#horsejs': ['push', 'merge_request'],
'somebody': ['push', 'merge_request', 'issue', 'build']
},
// IRC nick/names for the bot // IRC nick/names for the bot
nick: 'gitlab-bot', nick: 'gitlab-bot',
@ -17,5 +20,5 @@ module.exports = {
port: 1337, port: 1337,
// Network interface on which to run the webhook server. // Network interface on which to run the webhook server.
hostname: '0.0.0.0' hostname: '0.0.0.0',
} }

View File

@ -4,9 +4,22 @@ var bodyParser = require('body-parser');
var config = require('./config'); var config = require('./config');
var channels = [];
var hookToChannel = {};
for (var who in config.reports) {
if (who.indexOf('#') === 0)
channels.push(who);
var hooks = config.reports[who];
for (var i = 0; i < hooks.length; i++) {
var hook = hooks[i];
(hookToChannel[hook] = hookToChannel[hook] || []).push(who);
}
}
var client = new irc.Client(config.server, config.nick, { var client = new irc.Client(config.server, config.nick, {
//debug: true, //debug: true,
channels: config.channels, channels: channels,
userName: config.userName, userName: config.userName,
realName: config.realName, realName: config.realName,
retryDelay: 120000 retryDelay: 120000
@ -127,11 +140,12 @@ app.post('/', function(req, res) {
console.log("Unexpected object_kind:", body.object_kind); console.log("Unexpected object_kind:", body.object_kind);
if (msgs) { if (msgs) {
var whom = hookToChannel[body.object_kind] || [];
if (msgs instanceof Array) { if (msgs instanceof Array) {
for (var i = 0; i < msgs.length; i++) for (var i = 0; i < msgs.length; i++)
say(config.channels, msgs[i]); say(whom, msgs[i]);
} else { } else {
say(config.channels, msgs); say(whom, msgs);
} }
} }