Build a reports map;
This commit is contained in:
parent
ca284f4262
commit
107c3d83ad
@ -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',
|
||||
}
|
||||
|
20
index.js
20
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user