mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 13:17:08 +00:00
Yay logging
This commit is contained in:
parent
146a88c38d
commit
d88d315c1b
@ -1,12 +1,16 @@
|
||||
import { parseConfig } from "../Config";
|
||||
import { GithubWebhooks } from "../GithubWebhooks";
|
||||
import { LogWrapper } from "../LogWrapper";
|
||||
|
||||
const log = new LogWrapper("App");
|
||||
|
||||
async function start() {
|
||||
LogWrapper.configureLogging();
|
||||
const configFile = process.argv[2] || "./config.yml";
|
||||
const config = await parseConfig(configFile, process.env);
|
||||
const webhookHandler = new GithubWebhooks(config);
|
||||
webhookHandler.listen();
|
||||
}
|
||||
start().catch((ex) => {
|
||||
console.error("GithubWebhookApp encountered an error and has stopped:", ex);
|
||||
log.error("GithubWebhookApp encountered an error and has stopped:", ex);
|
||||
});
|
||||
|
@ -5,11 +5,13 @@ import markdown from "markdown-it";
|
||||
import mime from "mime";
|
||||
import emoji from "node-emoji";
|
||||
import { MatrixMessageContent } from "./MatrixEvent";
|
||||
import { LogWrapper } from "./LogWrapper";
|
||||
|
||||
const md = new markdown();
|
||||
const REGEX_MENTION = /(^|\s)(@[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38})(\s|$)/ig;
|
||||
const REGEX_MATRIX_MENTION = /<a href="https:\/\/matrix\.to\/#\/(.+)">(.*)<\/a>/gmi;
|
||||
const REGEX_IMAGES = /!\[.*]\((.*\.(\w+))\)/gm;
|
||||
const md = new markdown();
|
||||
const log = new LogWrapper("CommentProcessor");
|
||||
|
||||
interface IMatrixCommentEvent {
|
||||
msgtype: string;
|
||||
@ -117,7 +119,7 @@ export class CommentProcessor {
|
||||
|
||||
body = body.replace(rawUrl, url);
|
||||
} catch (ex) {
|
||||
console.warn("Failed to upload file");
|
||||
log.warn("Failed to upload file");
|
||||
}
|
||||
}
|
||||
return body;
|
||||
|
@ -4,6 +4,9 @@ import { createHmac } from "crypto";
|
||||
import { IssuesGetResponse, ReposGetResponse, IssuesGetResponseUser, IssuesGetCommentResponse } from "@octokit/rest";
|
||||
import { EventEmitter } from "events";
|
||||
import { MessageQueue, createMessageQueue } from "./MessageQueue/MessageQueue";
|
||||
import { LogWrapper } from "./LogWrapper";
|
||||
|
||||
const log = new LogWrapper("GithubWebhooks");
|
||||
|
||||
export interface IWebhookEvent {
|
||||
action: string;
|
||||
@ -40,41 +43,34 @@ export class GithubWebhooks extends EventEmitter {
|
||||
|
||||
public onPayload(req: Request, res: Response) {
|
||||
const body = req.body as IWebhookEvent;
|
||||
console.debug("Got", body);
|
||||
log.debug("Got", body);
|
||||
let eventName;
|
||||
let from;
|
||||
if (body.sender) {
|
||||
from = body.sender.login;
|
||||
}
|
||||
try {
|
||||
if (body.action === "created" && body.comment) {
|
||||
this.queue.push({
|
||||
eventName: "comment.created",
|
||||
sender: "GithubWebhooks",
|
||||
data: body,
|
||||
});
|
||||
eventName = "comment.created";
|
||||
} else if (body.action === "edited" && body.comment) {
|
||||
this.queue.push({
|
||||
eventName: "comment.edited",
|
||||
sender: "GithubWebhooks",
|
||||
data: body,
|
||||
});
|
||||
eventName = "comment.edited";
|
||||
} else if (body.action === "edited" && body.issue) {
|
||||
this.queue.push({
|
||||
eventName: "issue.edited",
|
||||
sender: "GithubWebhooks",
|
||||
data: body,
|
||||
});
|
||||
eventName = "issue.edited";
|
||||
} else if (body.action === "closed" && body.issue) {
|
||||
this.queue.push({
|
||||
eventName: "issue.closed",
|
||||
sender: "GithubWebhooks",
|
||||
data: body,
|
||||
});
|
||||
eventName = "issue.closed";
|
||||
} else if (body.action === "reopened" && body.issue) {
|
||||
eventName = "issue.reopened";
|
||||
}
|
||||
if (eventName) {
|
||||
log.info(`Got event ${eventName} ${from ? "from " + from : ""}`);
|
||||
this.queue.push({
|
||||
eventName: "issue.reopened",
|
||||
eventName,
|
||||
sender: "GithubWebhooks",
|
||||
data: body,
|
||||
});
|
||||
}
|
||||
} catch (ex) {
|
||||
console.error("Failed to emit");
|
||||
log.error("Failed to emit");
|
||||
}
|
||||
res.sendStatus(200);
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ import { MessageQueue, MessageQueueMessage } from "./MessageQueue";
|
||||
import { Redis, default as redis } from "ioredis";
|
||||
import { BridgeConfig } from "../Config";
|
||||
import { EventEmitter } from "events";
|
||||
import { LogWrapper } from "../LogWrapper";
|
||||
|
||||
const log = new LogWrapper("RedisMq");
|
||||
|
||||
export class RedisMQ extends EventEmitter implements MessageQueue {
|
||||
private redis: Redis;
|
||||
@ -11,7 +14,7 @@ export class RedisMQ extends EventEmitter implements MessageQueue {
|
||||
this.redis.on("pmessage", (pattern: string, channel: string, message: string) => {
|
||||
const msg = JSON.parse(message);
|
||||
const delay = (process.hrtime()[1]) - msg.ts!;
|
||||
console.log("Delay: ", delay / 1000000, "ms");
|
||||
log.debug("Delay: ", delay / 1000000, "ms");
|
||||
this.emit(channel, JSON.parse(message));
|
||||
});
|
||||
}
|
||||
@ -27,9 +30,9 @@ export class RedisMQ extends EventEmitter implements MessageQueue {
|
||||
public push(data: MessageQueueMessage) {
|
||||
data.ts = process.hrtime()[1];
|
||||
this.redis.publish(data.eventName, JSON.stringify(data)).then(() => {
|
||||
console.log(`Pushed ${data.eventName}`);
|
||||
log.debug(`Pushed ${data.eventName}`);
|
||||
}).catch((ex) => {
|
||||
console.warn("Failed to push an event:", ex);
|
||||
log.warn("Failed to push an event:", ex);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user