From 3ba86461b4927d7cae8c395ef0d90f20c5d6097d Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 27 Feb 2020 10:33:55 +0000 Subject: [PATCH] Alert on all notifs --- src/NotificationsProcessor.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/NotificationsProcessor.ts b/src/NotificationsProcessor.ts index f471bec2..0dc3b43e 100644 --- a/src/NotificationsProcessor.ts +++ b/src/NotificationsProcessor.ts @@ -119,11 +119,7 @@ export class NotificationProcessor { }; } - private async handleUserNotification(roomId: string, notif: UserNotification) { - log.info("New notification event:", notif); - if (notif.reason === "security_alert") { - return this.matrixSender.sendMatrixMessage(roomId, this.formatSecurityAlert(notif)); - } + private formatIssueOrPullRequest(roomId: string, notif: UserNotification) { const issueNumber = notif.subject.url_data?.number.toString(); let diff = null; if (issueNumber) { @@ -165,4 +161,21 @@ export class NotificationProcessor { } return this.matrixSender.sendMatrixMessage(roomId, body); } + + private async handleUserNotification(roomId: string, notif: UserNotification) { + log.info("New notification event:", notif); + if (notif.subject.type === "RepositoryVulnerabilityAlert") { + return this.matrixSender.sendMatrixMessage(roomId, this.formatSecurityAlert(notif)); + } else if (notif.subject.type !== "Issue" && notif.subject.type !== "PullRequest") { + return this.formatIssueOrPullRequest(roomId, notif); + } + // We don't understand this type yet + const genericNotif = NotificationProcessor.formatNotification(notif, null, false); + return this.matrixSender.sendMatrixMessage(roomId, { + msgtype: "m.text", + body: genericNotif.plain, + formatted_body: genericNotif.html, + format: "org.matrix.custom.html", + }); + } } \ No newline at end of file