From 212006ba9e8d4542a2d47869a36fe2f16fd0c55d Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 7 Dec 2025 19:32:00 +0000 Subject: [PATCH] [autofix.ci] apply automated fixes --- .../src/utils/notifications/build-success.ts | 686 +++++++++--------- .../utils/notifications/dokploy-restart.ts | 408 +++++------ 2 files changed, 547 insertions(+), 547 deletions(-) diff --git a/packages/server/src/utils/notifications/build-success.ts b/packages/server/src/utils/notifications/build-success.ts index f3350d72b..e120d107b 100644 --- a/packages/server/src/utils/notifications/build-success.ts +++ b/packages/server/src/utils/notifications/build-success.ts @@ -6,365 +6,365 @@ import { renderAsync } from "@react-email/components"; import { format } from "date-fns"; import { and, eq } from "drizzle-orm"; import { - sendCustomNotification, - sendDiscordNotification, - sendEmailNotification, - sendGotifyNotification, - sendLarkNotification, - sendNtfyNotification, - sendSlackNotification, - sendTelegramNotification, + sendCustomNotification, + sendDiscordNotification, + sendEmailNotification, + sendGotifyNotification, + sendLarkNotification, + sendNtfyNotification, + sendSlackNotification, + sendTelegramNotification, } from "./utils"; interface Props { - projectName: string; - applicationName: string; - applicationType: string; - buildLink: string; - organizationId: string; - domains: Domain[]; - environmentName: string; + projectName: string; + applicationName: string; + applicationType: string; + buildLink: string; + organizationId: string; + domains: Domain[]; + environmentName: string; } export const sendBuildSuccessNotifications = async ({ - projectName, - applicationName, - applicationType, - buildLink, - organizationId, - domains, - environmentName, + projectName, + applicationName, + applicationType, + buildLink, + organizationId, + domains, + environmentName, }: Props) => { - const date = new Date(); - const unixDate = ~~(Number(date) / 1000); - const notificationList = await db.query.notifications.findMany({ - where: and( - eq(notifications.appDeploy, true), - eq(notifications.organizationId, organizationId) - ), - with: { - email: true, - discord: true, - telegram: true, - slack: true, - gotify: true, - ntfy: true, - custom: true, - lark: true, - }, - }); + const date = new Date(); + const unixDate = ~~(Number(date) / 1000); + const notificationList = await db.query.notifications.findMany({ + where: and( + eq(notifications.appDeploy, true), + eq(notifications.organizationId, organizationId), + ), + with: { + email: true, + discord: true, + telegram: true, + slack: true, + gotify: true, + ntfy: true, + custom: true, + lark: true, + }, + }); - for (const notification of notificationList) { - const { email, discord, telegram, slack, gotify, ntfy, custom, lark } = - notification; - try { - if (email) { - const template = await renderAsync( - BuildSuccessEmail({ - projectName, - applicationName, - applicationType, - buildLink, - date: date.toLocaleString(), - environmentName, - }) - ).catch(); - await sendEmailNotification( - email, - "Build success for dokploy", - template - ); - } + for (const notification of notificationList) { + const { email, discord, telegram, slack, gotify, ntfy, custom, lark } = + notification; + try { + if (email) { + const template = await renderAsync( + BuildSuccessEmail({ + projectName, + applicationName, + applicationType, + buildLink, + date: date.toLocaleString(), + environmentName, + }), + ).catch(); + await sendEmailNotification( + email, + "Build success for dokploy", + template, + ); + } - if (discord) { - const decorate = (decoration: string, text: string) => - `${discord.decoration ? decoration : ""} ${text}`.trim(); + if (discord) { + const decorate = (decoration: string, text: string) => + `${discord.decoration ? decoration : ""} ${text}`.trim(); - await sendDiscordNotification(discord, { - title: decorate(">", "`โœ…` Build Successes"), - color: 0x57f287, - fields: [ - { - name: decorate("`๐Ÿ› ๏ธ`", "Project"), - value: projectName, - inline: true, - }, - { - name: decorate("`โš™๏ธ`", "Application"), - value: applicationName, - inline: true, - }, - { - name: decorate("`๐ŸŒ`", "Environment"), - value: environmentName, - inline: true, - }, - { - name: decorate("`โ”`", "Type"), - value: applicationType, - inline: true, - }, - { - name: decorate("`๐Ÿ“…`", "Date"), - value: ``, - inline: true, - }, - { - name: decorate("`โŒš`", "Time"), - value: ``, - inline: true, - }, - { - name: decorate("`โ“`", "Type"), - value: "Successful", - inline: true, - }, - { - name: decorate("`๐Ÿงท`", "Build Link"), - value: `[Click here to access build link](${buildLink})`, - }, - ], - timestamp: date.toISOString(), - footer: { - text: "Dokploy Build Notification", - }, - }); - } + await sendDiscordNotification(discord, { + title: decorate(">", "`โœ…` Build Successes"), + color: 0x57f287, + fields: [ + { + name: decorate("`๐Ÿ› ๏ธ`", "Project"), + value: projectName, + inline: true, + }, + { + name: decorate("`โš™๏ธ`", "Application"), + value: applicationName, + inline: true, + }, + { + name: decorate("`๐ŸŒ`", "Environment"), + value: environmentName, + inline: true, + }, + { + name: decorate("`โ”`", "Type"), + value: applicationType, + inline: true, + }, + { + name: decorate("`๐Ÿ“…`", "Date"), + value: ``, + inline: true, + }, + { + name: decorate("`โŒš`", "Time"), + value: ``, + inline: true, + }, + { + name: decorate("`โ“`", "Type"), + value: "Successful", + inline: true, + }, + { + name: decorate("`๐Ÿงท`", "Build Link"), + value: `[Click here to access build link](${buildLink})`, + }, + ], + timestamp: date.toISOString(), + footer: { + text: "Dokploy Build Notification", + }, + }); + } - if (gotify) { - const decorate = (decoration: string, text: string) => - `${gotify.decoration ? decoration : ""} ${text}\n`; - await sendGotifyNotification( - gotify, - decorate("โœ…", "Build Success"), - `${decorate("๐Ÿ› ๏ธ", `Project: ${projectName}`)}` + - `${decorate("โš™๏ธ", `Application: ${applicationName}`)}` + - `${decorate("๐ŸŒ", `Environment: ${environmentName}`)}` + - `${decorate("โ”", `Type: ${applicationType}`)}` + - `${decorate("๐Ÿ•’", `Date: ${date.toLocaleString()}`)}` + - `${decorate("๐Ÿ”—", `Build details:\n${buildLink}`)}` - ); - } + if (gotify) { + const decorate = (decoration: string, text: string) => + `${gotify.decoration ? decoration : ""} ${text}\n`; + await sendGotifyNotification( + gotify, + decorate("โœ…", "Build Success"), + `${decorate("๐Ÿ› ๏ธ", `Project: ${projectName}`)}` + + `${decorate("โš™๏ธ", `Application: ${applicationName}`)}` + + `${decorate("๐ŸŒ", `Environment: ${environmentName}`)}` + + `${decorate("โ”", `Type: ${applicationType}`)}` + + `${decorate("๐Ÿ•’", `Date: ${date.toLocaleString()}`)}` + + `${decorate("๐Ÿ”—", `Build details:\n${buildLink}`)}`, + ); + } - if (ntfy) { - await sendNtfyNotification( - ntfy, - "Build Success", - "white_check_mark", - `view, Build details, ${buildLink}, clear=true;`, - `๐Ÿ› Project: ${projectName}\n` + - `โš™๏ธApplication: ${applicationName}\n` + - `๐ŸŒEnvironment: ${environmentName}\n` + - `โ”Type: ${applicationType}\n` + - `๐Ÿ•’Date: ${date.toLocaleString()}` - ); - } + if (ntfy) { + await sendNtfyNotification( + ntfy, + "Build Success", + "white_check_mark", + `view, Build details, ${buildLink}, clear=true;`, + `๐Ÿ› Project: ${projectName}\n` + + `โš™๏ธApplication: ${applicationName}\n` + + `๐ŸŒEnvironment: ${environmentName}\n` + + `โ”Type: ${applicationType}\n` + + `๐Ÿ•’Date: ${date.toLocaleString()}`, + ); + } - if (telegram) { - const chunkArray = (array: T[], chunkSize: number): T[][] => - Array.from({ length: Math.ceil(array.length / chunkSize) }, (_, i) => - array.slice(i * chunkSize, i * chunkSize + chunkSize) - ); + if (telegram) { + const chunkArray = (array: T[], chunkSize: number): T[][] => + Array.from({ length: Math.ceil(array.length / chunkSize) }, (_, i) => + array.slice(i * chunkSize, i * chunkSize + chunkSize), + ); - const inlineButton = [ - [ - { - text: "Deployment Logs", - url: buildLink, - }, - ], - ...chunkArray(domains, 2).map((chunk) => - chunk.map((data) => ({ - text: data.host, - url: `${data.https ? "https" : "http"}://${data.host}`, - })) - ), - ]; + const inlineButton = [ + [ + { + text: "Deployment Logs", + url: buildLink, + }, + ], + ...chunkArray(domains, 2).map((chunk) => + chunk.map((data) => ({ + text: data.host, + url: `${data.https ? "https" : "http"}://${data.host}`, + })), + ), + ]; - await sendTelegramNotification( - telegram, - `โœ… Build Success\n\nProject: ${projectName}\nApplication: ${applicationName}\nEnvironment: ${environmentName}\nType: ${applicationType}\nDate: ${format( - date, - "PP" - )}\nTime: ${format(date, "pp")}`, - inlineButton - ); - } + await sendTelegramNotification( + telegram, + `โœ… Build Success\n\nProject: ${projectName}\nApplication: ${applicationName}\nEnvironment: ${environmentName}\nType: ${applicationType}\nDate: ${format( + date, + "PP", + )}\nTime: ${format(date, "pp")}`, + inlineButton, + ); + } - if (slack) { - const { channel } = slack; - await sendSlackNotification(slack, { - channel: channel, - attachments: [ - { - color: "#00FF00", - pretext: ":white_check_mark: *Build Success*", - fields: [ - { - title: "Project", - value: projectName, - short: true, - }, - { - title: "Application", - value: applicationName, - short: true, - }, - { - title: "Environment", - value: environmentName, - short: true, - }, - { - title: "Type", - value: applicationType, - short: true, - }, - { - title: "Time", - value: date.toLocaleString(), - short: true, - }, - ], - actions: [ - { - type: "button", - text: "View Build Details", - url: buildLink, - }, - ], - }, - ], - }); - } + if (slack) { + const { channel } = slack; + await sendSlackNotification(slack, { + channel: channel, + attachments: [ + { + color: "#00FF00", + pretext: ":white_check_mark: *Build Success*", + fields: [ + { + title: "Project", + value: projectName, + short: true, + }, + { + title: "Application", + value: applicationName, + short: true, + }, + { + title: "Environment", + value: environmentName, + short: true, + }, + { + title: "Type", + value: applicationType, + short: true, + }, + { + title: "Time", + value: date.toLocaleString(), + short: true, + }, + ], + actions: [ + { + type: "button", + text: "View Build Details", + url: buildLink, + }, + ], + }, + ], + }); + } - if (custom) { - await sendCustomNotification(custom, { - title: "Build Success", - message: "Build completed successfully", - projectName, - applicationName, - applicationType, - buildLink, - timestamp: date.toISOString(), - date: date.toLocaleString(), - domains: domains.map((domain) => domain.host).join(", "), - status: "success", - type: "build", - }); - } + if (custom) { + await sendCustomNotification(custom, { + title: "Build Success", + message: "Build completed successfully", + projectName, + applicationName, + applicationType, + buildLink, + timestamp: date.toISOString(), + date: date.toLocaleString(), + domains: domains.map((domain) => domain.host).join(", "), + status: "success", + type: "build", + }); + } - if (lark) { - await sendLarkNotification(lark, { - msg_type: "interactive", - card: { - schema: "2.0", - config: { - update_multi: true, - style: { - text_size: { - normal_v2: { - default: "normal", - pc: "normal", - mobile: "heading", - }, - }, - }, - }, - header: { - title: { - tag: "plain_text", - content: "โœ… Build Success", - }, - subtitle: { - tag: "plain_text", - content: "", - }, - template: "green", - padding: "12px 12px 12px 12px", - }, - body: { - direction: "vertical", - padding: "12px 12px 12px 12px", - elements: [ - { - tag: "column_set", - columns: [ - { - tag: "column", - width: "weighted", - elements: [ - { - tag: "markdown", - content: `**Project:**\n${projectName}`, - text_align: "left", - text_size: "normal_v2", - }, - { - tag: "markdown", - content: `**Environment:**\n${environmentName}`, - text_align: "left", - text_size: "normal_v2", - }, - { - tag: "markdown", - content: `**Type:**\n${applicationType}`, - text_align: "left", - text_size: "normal_v2", - }, - ], - vertical_align: "top", - weight: 1, - }, - { - tag: "column", - width: "weighted", - elements: [ - { - tag: "markdown", - content: `**Application:**\n${applicationName}`, - text_align: "left", - text_size: "normal_v2", - }, - { - tag: "markdown", - content: `**Date:**\n${format(date, "PP pp")}`, - text_align: "left", - text_size: "normal_v2", - }, - ], - vertical_align: "top", - weight: 1, - }, - ], - }, - { - tag: "button", - text: { - tag: "plain_text", - content: "View Build Details", - }, - type: "primary", - width: "default", - size: "medium", - behaviors: [ - { - type: "open_url", - default_url: buildLink, - pc_url: "", - ios_url: "", - android_url: "", - }, - ], - margin: "0px 0px 0px 0px", - }, - ], - }, - }, - }); - } - } catch (error) { - console.log(error); - } - } + if (lark) { + await sendLarkNotification(lark, { + msg_type: "interactive", + card: { + schema: "2.0", + config: { + update_multi: true, + style: { + text_size: { + normal_v2: { + default: "normal", + pc: "normal", + mobile: "heading", + }, + }, + }, + }, + header: { + title: { + tag: "plain_text", + content: "โœ… Build Success", + }, + subtitle: { + tag: "plain_text", + content: "", + }, + template: "green", + padding: "12px 12px 12px 12px", + }, + body: { + direction: "vertical", + padding: "12px 12px 12px 12px", + elements: [ + { + tag: "column_set", + columns: [ + { + tag: "column", + width: "weighted", + elements: [ + { + tag: "markdown", + content: `**Project:**\n${projectName}`, + text_align: "left", + text_size: "normal_v2", + }, + { + tag: "markdown", + content: `**Environment:**\n${environmentName}`, + text_align: "left", + text_size: "normal_v2", + }, + { + tag: "markdown", + content: `**Type:**\n${applicationType}`, + text_align: "left", + text_size: "normal_v2", + }, + ], + vertical_align: "top", + weight: 1, + }, + { + tag: "column", + width: "weighted", + elements: [ + { + tag: "markdown", + content: `**Application:**\n${applicationName}`, + text_align: "left", + text_size: "normal_v2", + }, + { + tag: "markdown", + content: `**Date:**\n${format(date, "PP pp")}`, + text_align: "left", + text_size: "normal_v2", + }, + ], + vertical_align: "top", + weight: 1, + }, + ], + }, + { + tag: "button", + text: { + tag: "plain_text", + content: "View Build Details", + }, + type: "primary", + width: "default", + size: "medium", + behaviors: [ + { + type: "open_url", + default_url: buildLink, + pc_url: "", + ios_url: "", + android_url: "", + }, + ], + margin: "0px 0px 0px 0px", + }, + ], + }, + }, + }); + } + } catch (error) { + console.log(error); + } + } }; diff --git a/packages/server/src/utils/notifications/dokploy-restart.ts b/packages/server/src/utils/notifications/dokploy-restart.ts index edc83c513..095ca4a6a 100644 --- a/packages/server/src/utils/notifications/dokploy-restart.ts +++ b/packages/server/src/utils/notifications/dokploy-restart.ts @@ -5,222 +5,222 @@ import { renderAsync } from "@react-email/components"; import { format } from "date-fns"; import { eq } from "drizzle-orm"; import { - sendCustomNotification, - sendDiscordNotification, - sendEmailNotification, - sendGotifyNotification, - sendLarkNotification, - sendNtfyNotification, - sendSlackNotification, - sendTelegramNotification, + sendCustomNotification, + sendDiscordNotification, + sendEmailNotification, + sendGotifyNotification, + sendLarkNotification, + sendNtfyNotification, + sendSlackNotification, + sendTelegramNotification, } from "./utils"; export const sendDokployRestartNotifications = async () => { - const date = new Date(); - const unixDate = ~~(Number(date) / 1000); - const notificationList = await db.query.notifications.findMany({ - where: eq(notifications.dokployRestart, true), - with: { - email: true, - discord: true, - telegram: true, - slack: true, - gotify: true, - ntfy: true, - custom: true, - lark: true, - }, - }); + const date = new Date(); + const unixDate = ~~(Number(date) / 1000); + const notificationList = await db.query.notifications.findMany({ + where: eq(notifications.dokployRestart, true), + with: { + email: true, + discord: true, + telegram: true, + slack: true, + gotify: true, + ntfy: true, + custom: true, + lark: true, + }, + }); - for (const notification of notificationList) { - const { email, discord, telegram, slack, gotify, ntfy, custom, lark } = - notification; + for (const notification of notificationList) { + const { email, discord, telegram, slack, gotify, ntfy, custom, lark } = + notification; - try { - if (email) { - const template = await renderAsync( - DokployRestartEmail({ date: date.toLocaleString() }) - ).catch(); + try { + if (email) { + const template = await renderAsync( + DokployRestartEmail({ date: date.toLocaleString() }), + ).catch(); - await sendEmailNotification( - email, - "Dokploy Server Restarted", - template - ); - } + await sendEmailNotification( + email, + "Dokploy Server Restarted", + template, + ); + } - if (discord) { - const decorate = (decoration: string, text: string) => - `${discord.decoration ? decoration : ""} ${text}`.trim(); + if (discord) { + const decorate = (decoration: string, text: string) => + `${discord.decoration ? decoration : ""} ${text}`.trim(); - await sendDiscordNotification(discord, { - title: decorate(">", "`โœ…` Dokploy Server Restarted"), - color: 0x57f287, - fields: [ - { - name: decorate("`๐Ÿ“…`", "Date"), - value: ``, - inline: true, - }, - { - name: decorate("`โŒš`", "Time"), - value: ``, - inline: true, - }, - { - name: decorate("`โ“`", "Type"), - value: "Successful", - inline: true, - }, - ], - timestamp: date.toISOString(), - footer: { - text: "Dokploy Restart Notification", - }, - }); - } + await sendDiscordNotification(discord, { + title: decorate(">", "`โœ…` Dokploy Server Restarted"), + color: 0x57f287, + fields: [ + { + name: decorate("`๐Ÿ“…`", "Date"), + value: ``, + inline: true, + }, + { + name: decorate("`โŒš`", "Time"), + value: ``, + inline: true, + }, + { + name: decorate("`โ“`", "Type"), + value: "Successful", + inline: true, + }, + ], + timestamp: date.toISOString(), + footer: { + text: "Dokploy Restart Notification", + }, + }); + } - if (gotify) { - const decorate = (decoration: string, text: string) => - `${gotify.decoration ? decoration : ""} ${text}\n`; - await sendGotifyNotification( - gotify, - decorate("โœ…", "Dokploy Server Restarted"), - `${decorate("๐Ÿ•’", `Date: ${date.toLocaleString()}`)}` - ); - } + if (gotify) { + const decorate = (decoration: string, text: string) => + `${gotify.decoration ? decoration : ""} ${text}\n`; + await sendGotifyNotification( + gotify, + decorate("โœ…", "Dokploy Server Restarted"), + `${decorate("๐Ÿ•’", `Date: ${date.toLocaleString()}`)}`, + ); + } - if (ntfy) { - await sendNtfyNotification( - ntfy, - "Dokploy Server Restarted", - "white_check_mark", - "", - `๐Ÿ•’Date: ${date.toLocaleString()}` - ); - } + if (ntfy) { + await sendNtfyNotification( + ntfy, + "Dokploy Server Restarted", + "white_check_mark", + "", + `๐Ÿ•’Date: ${date.toLocaleString()}`, + ); + } - if (telegram) { - await sendTelegramNotification( - telegram, - `โœ… Dokploy Server Restarted\n\nDate: ${format( - date, - "PP" - )}\nTime: ${format(date, "pp")}` - ); - } + if (telegram) { + await sendTelegramNotification( + telegram, + `โœ… Dokploy Server Restarted\n\nDate: ${format( + date, + "PP", + )}\nTime: ${format(date, "pp")}`, + ); + } - if (slack) { - const { channel } = slack; - await sendSlackNotification(slack, { - channel: channel, - attachments: [ - { - color: "#00FF00", - pretext: ":white_check_mark: *Dokploy Server Restarted*", - fields: [ - { - title: "Time", - value: date.toLocaleString(), - short: true, - }, - ], - }, - ], - }); - } + if (slack) { + const { channel } = slack; + await sendSlackNotification(slack, { + channel: channel, + attachments: [ + { + color: "#00FF00", + pretext: ":white_check_mark: *Dokploy Server Restarted*", + fields: [ + { + title: "Time", + value: date.toLocaleString(), + short: true, + }, + ], + }, + ], + }); + } - if (custom) { - try { - await sendCustomNotification(custom, { - title: "Dokploy Server Restarted", - message: "Dokploy server has been restarted successfully", - timestamp: date.toISOString(), - date: date.toLocaleString(), - status: "success", - type: "dokploy-restart", - }); - } catch (error) { - console.log(error); - } - } + if (custom) { + try { + await sendCustomNotification(custom, { + title: "Dokploy Server Restarted", + message: "Dokploy server has been restarted successfully", + timestamp: date.toISOString(), + date: date.toLocaleString(), + status: "success", + type: "dokploy-restart", + }); + } catch (error) { + console.log(error); + } + } - if (lark) { - await sendLarkNotification(lark, { - msg_type: "interactive", - card: { - schema: "2.0", - config: { - update_multi: true, - style: { - text_size: { - normal_v2: { - default: "normal", - pc: "normal", - mobile: "heading", - }, - }, - }, - }, - header: { - title: { - tag: "plain_text", - content: "โœ… Dokploy Server Restarted", - }, - subtitle: { - tag: "plain_text", - content: "", - }, - template: "green", - padding: "12px 12px 12px 12px", - }, - body: { - direction: "vertical", - padding: "12px 12px 12px 12px", - elements: [ - { - tag: "column_set", - columns: [ - { - tag: "column", - width: "weighted", - elements: [ - { - tag: "markdown", - content: "**Status:**\nSuccessful", - text_align: "left", - text_size: "normal_v2", - }, - ], - vertical_align: "top", - weight: 1, - }, - { - tag: "column", - width: "weighted", - elements: [ - { - tag: "markdown", - content: `**Restart Time:**\n${format( - date, - "PP pp" - )}`, - text_align: "left", - text_size: "normal_v2", - }, - ], - vertical_align: "top", - weight: 1, - }, - ], - }, - ], - }, - }, - }); - } - } catch (error) { - console.log(error); - } - } + if (lark) { + await sendLarkNotification(lark, { + msg_type: "interactive", + card: { + schema: "2.0", + config: { + update_multi: true, + style: { + text_size: { + normal_v2: { + default: "normal", + pc: "normal", + mobile: "heading", + }, + }, + }, + }, + header: { + title: { + tag: "plain_text", + content: "โœ… Dokploy Server Restarted", + }, + subtitle: { + tag: "plain_text", + content: "", + }, + template: "green", + padding: "12px 12px 12px 12px", + }, + body: { + direction: "vertical", + padding: "12px 12px 12px 12px", + elements: [ + { + tag: "column_set", + columns: [ + { + tag: "column", + width: "weighted", + elements: [ + { + tag: "markdown", + content: "**Status:**\nSuccessful", + text_align: "left", + text_size: "normal_v2", + }, + ], + vertical_align: "top", + weight: 1, + }, + { + tag: "column", + width: "weighted", + elements: [ + { + tag: "markdown", + content: `**Restart Time:**\n${format( + date, + "PP pp", + )}`, + text_align: "left", + text_size: "normal_v2", + }, + ], + vertical_align: "top", + weight: 1, + }, + ], + }, + ], + }, + }, + }); + } + } catch (error) { + console.log(error); + } + } };