Skip to content

Commit

Permalink
[Nakamura] Change layout cards
Browse files Browse the repository at this point in the history
Signed-off-by: nakamuraos <[email protected]>
  • Loading branch information
nakamuraos committed Dec 3, 2021
1 parent 136ec1f commit 7871be4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
15 changes: 12 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2592,7 +2592,11 @@ const textButton = (text, url) => ({
onClick: { openLink: { url } },
},
});
const htmlEntities = (str) => {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
};
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;
Expand All @@ -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: [
Expand All @@ -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,
},
},
],
Expand Down
18 changes: 14 additions & 4 deletions src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Expand All @@ -27,6 +28,10 @@ const textButton = (text: string, url: string) => ({
},
})

const htmlEntities = (str: string) => {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
}

export async function notify({
title,
subtitle,
Expand All @@ -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: [
Expand All @@ -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,
},
},
],
Expand Down

0 comments on commit 7871be4

Please sign in to comment.