diff --git a/config.example.js b/config.example.js index aa886b9..8c807fe 100644 --- a/config.example.js +++ b/config.example.js @@ -3,7 +3,10 @@ module.exports = { server: 'chat.freenode.net', // 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 nick: 'gitlab-bot', @@ -17,5 +20,5 @@ module.exports = { port: 1337, // Network interface on which to run the webhook server. - hostname: '0.0.0.0' + hostname: '0.0.0.0', } diff --git a/index.js b/index.js index ffd8105..7b44ad4 100644 --- a/index.js +++ b/index.js @@ -4,9 +4,22 @@ var bodyParser = require('body-parser'); 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, { //debug: true, - channels: config.channels, + channels: channels, userName: config.userName, realName: config.realName, retryDelay: 120000 @@ -127,11 +140,12 @@ app.post('/', function(req, res) { console.log("Unexpected object_kind:", body.object_kind); if (msgs) { + var whom = hookToChannel[body.object_kind] || []; if (msgs instanceof Array) { for (var i = 0; i < msgs.length; i++) - say(config.channels, msgs[i]); + say(whom, msgs[i]); } else { - say(config.channels, msgs); + say(whom, msgs); } }