diff --git a/config.example.js b/config.example.js index 88b345c..35f6abc 100644 --- a/config.example.js +++ b/config.example.js @@ -8,6 +8,8 @@ module.exports = { 'somebody': ['push', 'merge_request', 'issue', 'build'] }, + projectUrl: "https://framagit.org/bnjbvr/kresus/", + // IRC nick/names for the bot nick: 'gitlab-bot', userName: 'gitlab-bot', diff --git a/index.js b/index.js index 5e19ce0..08bf6b6 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,7 @@ var request = require('request'); var config = require('./config'); +// Bind recipients to notifications. var channels = []; var hookToChannel = {}; for (var who in config.reports) { @@ -18,6 +19,15 @@ for (var who in config.reports) { } } +// Sanitize projectUrl +if (typeof config.projectUrl !== 'undefined') { + var url = '' + config.projectUrl; + if (url[url.length - 1] !== '/') { + url += '/'; + } + config.projectUrl = url; +} + var client = new irc.Client(config.server, config.nick, { debug: config.debug || false, channels: channels, @@ -204,4 +214,19 @@ app.post('/', function(req, res) { app.listen(config.port, config.hostname, function() { console.log('gitlab-to-irc running.'); + + var issueRegexp = /#(\d+)/g; + var mergeRequestRegexp = /!(\d+)/g; + client.on('message', function(from, chan, message) { + var matches = null; + while ((matches = issueRegexp.exec(message)) !== null) { + var issueId = matches[1]; + client.say(chan, "Issue #" + issueId + ": " + config.projectUrl + 'issues/' + issueId); + } + + while ((matches = mergeRequestRegexp.exec(message)) !== null) { + var mrId = matches[1]; + client.say(chan, "Merge request !" + mrId + ": " + config.projectUrl + 'merge_requests/' + mrId); + } + }); });