Prefetch issue/MR title when mentioning them;

This commit is contained in:
Benjamin Bouvier 2017-06-28 11:29:29 +02:00
parent 7d5dd45e86
commit 8f1a231779
2 changed files with 28 additions and 6 deletions

View File

@ -2,6 +2,7 @@ var irc = require('irc');
var express = require('express');
var bodyParser = require('body-parser');
var request = require('request');
var cheerio = require('cheerio');
var config = require('./config');
@ -221,12 +222,32 @@ app.listen(config.port, config.hostname, function() {
var matches = null;
while ((matches = issueRegexp.exec(message)) !== null) {
var issueId = matches[1];
client.say(chan, "Issue #" + issueId + ": " + config.projectUrl + 'issues/' + issueId);
var url = config.projectUrl + 'issues/' + issueId;
request(url, function(err, res, body) {
if (res && res.statusCode === '200') {
var title = cheerio.load(body)('head title').text();
if (title.length) {
client.say(chan, title);
} else {
client.say(chan, "Issue #" + issueId + ": " + url);
}
}
});
}
while ((matches = mergeRequestRegexp.exec(message)) !== null) {
var mrId = matches[1];
client.say(chan, "Merge request !" + mrId + ": " + config.projectUrl + 'merge_requests/' + mrId);
var url = config.projectUrl + 'merge_requests/' + mrId;
request(url, function(err, res, body) {
if (res && res.statusCode === '200') {
var title = cheerio.load(body)('head title').text();
if (title.length) {
client.say(chan, title);
} else {
client.say(chan, "Merge request !" + mrId + ": " + url);
}
}
});
}
});
});

View File

@ -6,9 +6,10 @@
"author": "Benjamin Bouvier <public@benj.me>",
"license": "GPLv3",
"dependencies": {
"body-parser": "1.15.2",
"express": "4.14.0",
"irc": "0.3.9",
"request": "2.73.0"
"body-parser": "1.17.2",
"cheerio": "0.22.0",
"express": "4.15.3",
"irc": "0.5.2",
"request": "2.81.0"
}
}