post links and details to bug numbers on irc, like firebot
This commit is contained in:
Родитель
b6714fb050
Коммит
85b57f9d17
31
src/irc.js
31
src/irc.js
|
@ -3,13 +3,29 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import irc from "irc";
|
||||
import request from "request-json";
|
||||
|
||||
const NICK = "nss-tc";
|
||||
const CHANNEL = "#nss";
|
||||
const SERVER = "irc.mozilla.org";
|
||||
const BZ_HOST = "https://bugzilla.mozilla.org";
|
||||
|
||||
let client;
|
||||
|
||||
async function jsonRequest(url) {
|
||||
let client = request.createClient(BZ_HOST);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
client.get(url, (err, res, json) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(json);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function say(msg) {
|
||||
if (!client) {
|
||||
connect();
|
||||
|
@ -34,6 +50,21 @@ function connect() {
|
|||
client.addListener("error", msg => {
|
||||
console.log("irc error: ", msg);
|
||||
});
|
||||
|
||||
// Listen for bug numbers.
|
||||
client.addListener(`message${CHANNEL}`, async function (from, message) {
|
||||
let match = /[Bb]ug (\d{5,})/.exec(message);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
|
||||
let id = match[1];
|
||||
let client = request.createClient(BZ_HOST);
|
||||
let {bugs: [bug]} = await jsonRequest(`/rest/bug/${id}`);
|
||||
let status = bug.resolution || bug.status;
|
||||
|
||||
say(`https://bugzil.la/${id} — ${status}, ${bug.assigned_to} — ${bug.summary}`);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.say = say;
|
||||
|
|
Загрузка…
Ссылка в новой задаче