From 0d1127e139e4ad6b3d8b2ad6949cb67ace8dbb39 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 27 Feb 2020 10:55:49 +0000 Subject: [PATCH] Format review requests --- src/NotificationsProcessor.ts | 23 +++++++++++++++++++++-- src/UserNotificationWatcher.ts | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/NotificationsProcessor.ts b/src/NotificationsProcessor.ts index 52135306..add4e502 100644 --- a/src/NotificationsProcessor.ts +++ b/src/NotificationsProcessor.ts @@ -50,6 +50,10 @@ export class NotificationProcessor { } private static getEmojiForNotifType(notif: UserNotification): string { + switch(notif.reason) { + case "review_requested": + return "🚩"; + } switch (notif.subject.type) { case "Issue": return "📝"; @@ -110,6 +114,19 @@ export class NotificationProcessor { return diff; } + private formatReviewRequest(notif: UserNotification) { + const issue = notif.subject.url_data!; + const body = `🚩 Review Requested for [${issue.title} #${issue.number}](${issue.html_url}) - ` + + ` **[${notif.repository.full_name}](${notif.repository.html_url})**`; + return { + ...FormatUtil.getPartialBodyForRepo(notif.repository), + msgtype: "m.text", + body, + formatted_body: md.render(body), + format: "org.matrix.custom.html", + }; + } + private formatSecurityAlert(notif: UserNotification) { const body = `⚠️ ${notif.subject.title} - ` + `for **[${notif.repository.full_name}](${notif.repository.html_url})**`; @@ -167,9 +184,11 @@ export class NotificationProcessor { private async handleUserNotification(roomId: string, notif: UserNotification) { log.info("New notification event:", notif); - if (notif.subject.type === "RepositoryVulnerabilityAlert") { + if (notif.reason === "security_alert") { return this.matrixSender.sendMatrixMessage(roomId, this.formatSecurityAlert(notif)); - } else if (notif.subject.type !== "Issue" && notif.subject.type !== "PullRequest") { + } else if (notif.reason === "review_requested") { + return this.matrixSender.sendMatrixMessage(roomId, this.formatReviewRequest(notif)); + } else if (notif.subject.type === "Issue" || notif.subject.type === "PullRequest") { return this.formatIssueOrPullRequest(roomId, notif); } // We don't understand this type yet diff --git a/src/UserNotificationWatcher.ts b/src/UserNotificationWatcher.ts index de2f20b7..1091d277 100644 --- a/src/UserNotificationWatcher.ts +++ b/src/UserNotificationWatcher.ts @@ -22,7 +22,7 @@ export interface UserNotificationsEvent { export interface UserNotification { id: string; - reason: "assign"|"author"|"comment"|"invitation"|"manual"|"mention"|"review_required"| + reason: "assign"|"author"|"comment"|"invitation"|"manual"|"mention"|"review_required"|"review_requested"| "security_alert"|"state_change"|"subscribed"|"team_mention"; unread: boolean; updated_at: number;