Prefetch issue/MR title when mentioning them;
This commit is contained in:
parent
7d5dd45e86
commit
8f1a231779
25
index.js
25
index.js
@ -2,6 +2,7 @@ var irc = require('irc');
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var bodyParser = require('body-parser');
|
var bodyParser = require('body-parser');
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
|
var cheerio = require('cheerio');
|
||||||
|
|
||||||
var config = require('./config');
|
var config = require('./config');
|
||||||
|
|
||||||
@ -221,12 +222,32 @@ app.listen(config.port, config.hostname, function() {
|
|||||||
var matches = null;
|
var matches = null;
|
||||||
while ((matches = issueRegexp.exec(message)) !== null) {
|
while ((matches = issueRegexp.exec(message)) !== null) {
|
||||||
var issueId = matches[1];
|
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) {
|
while ((matches = mergeRequestRegexp.exec(message)) !== null) {
|
||||||
var mrId = matches[1];
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -6,9 +6,10 @@
|
|||||||
"author": "Benjamin Bouvier <public@benj.me>",
|
"author": "Benjamin Bouvier <public@benj.me>",
|
||||||
"license": "GPLv3",
|
"license": "GPLv3",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "1.15.2",
|
"body-parser": "1.17.2",
|
||||||
"express": "4.14.0",
|
"cheerio": "0.22.0",
|
||||||
"irc": "0.3.9",
|
"express": "4.15.3",
|
||||||
"request": "2.73.0"
|
"irc": "0.5.2",
|
||||||
|
"request": "2.81.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user