From 7871be43d4201736f709cd95d25857ecd9daccb5 Mon Sep 17 00:00:00 2001 From: nakamuraos Date: Fri, 3 Dec 2021 15:10:14 +0700 Subject: [PATCH] [Nakamura] Change layout cards Signed-off-by: nakamuraos --- dist/index.js | 15 ++++++++++++--- src/chat.ts | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/dist/index.js b/dist/index.js index b9141e5..53c5942 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2592,7 +2592,11 @@ const textButton = (text, url) => ({ onClick: { openLink: { url } }, }, }); +const htmlEntities = (str) => { + return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); +}; function notify({ title, subtitle, webhookUrl, status, threadKey, }) { + var _a, _b; return __awaiter(this, void 0, void 0, function* () { const { owner, repo } = github.context.repo; const { eventName, sha, ref } = github.context; @@ -2606,6 +2610,12 @@ function notify({ title, subtitle, webhookUrl, status, threadKey, }) { const body = { cards: [ { + header: { + title, + subtitle: htmlEntities((_a = subtitle === null || subtitle === void 0 ? void 0 : subtitle.replace(/(\r\n|\n|\r)/gm, ' ')) !== null && _a !== void 0 ? _a : ''), + imageUrl: statusIcon[status], + imageStyle: 'IMAGE', + }, sections: [ { widgets: [ @@ -2616,9 +2626,8 @@ function notify({ title, subtitle, webhookUrl, status, threadKey, }) { }, { keyValue: { - content: title, - bottomLabel: subtitle === null || subtitle === void 0 ? void 0 : subtitle.replace(/(\r\n|\n|\r)/gm, ' '), - iconUrl: statusIcon[status], + content: htmlEntities((_b = subtitle === null || subtitle === void 0 ? void 0 : subtitle.replace(/(\r\n|\n|\r)/gm, ' ')) !== null && _b !== void 0 ? _b : ''), + contentMultiline: true, }, }, ], diff --git a/src/chat.ts b/src/chat.ts index 772e3b9..63c6439 100644 --- a/src/chat.ts +++ b/src/chat.ts @@ -16,7 +16,8 @@ const statusText: { [key in Status]: string } = { const statusIcon: { [key in Status]: string } = { success: 'https://raw.githubusercontent.com/nakamuraos/google-chat-notifications/releases/v2.1.0/icons/success.png', - cancelled: 'https://raw.githubusercontent.com/nakamuraos/google-chat-notifications/releases/v2.1.0/icons/cancelled.png', + cancelled: + 'https://raw.githubusercontent.com/nakamuraos/google-chat-notifications/releases/v2.1.0/icons/cancelled.png', failure: 'https://raw.githubusercontent.com/nakamuraos/google-chat-notifications/releases/v2.1.0/icons/failure.png', } @@ -27,6 +28,10 @@ const textButton = (text: string, url: string) => ({ }, }) +const htmlEntities = (str: string) => { + return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"') +} + export async function notify({ title, subtitle, @@ -53,6 +58,12 @@ export async function notify({ const body: any = { cards: [ { + header: { + title, + subtitle: htmlEntities(subtitle?.replace(/(\r\n|\n|\r)/gm, ' ') ?? ''), + imageUrl: statusIcon[status], + imageStyle: 'IMAGE', + }, sections: [ { widgets: [ @@ -63,9 +74,8 @@ export async function notify({ }, { keyValue: { - content: title, - bottomLabel: subtitle?.replace(/(\r\n|\n|\r)/gm, ' '), - iconUrl: statusIcon[status], + content: htmlEntities(subtitle?.replace(/(\r\n|\n|\r)/gm, ' ') ?? ''), + contentMultiline: true, }, }, ],