Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix: use custom column names in webhook status reports (#1343)

Krauz8ef65f02ad14
diff --git a/apps/api/src/plugins/discord/client.ts b/apps/api/src/plugins/discord/client.ts
index dbb926826..10a5996ca 100644
--- a/apps/api/src/plugins/discord/client.ts
+++ b/apps/api/src/plugins/discord/client.ts
@@ -22,6 +22,17 @@ type DiscordMessage = {
const DISCORD_TIMEOUT_MS = 10_000;
+export function sanitizeDiscordContent(value: string): string {
+ return value
+ .replace(/@everyone/g, "@\u200beveryone")
+ .replace(/@here/g, "@\u200bhere")
+ .replace(/<@&/g, "<@\u200b&")
+ .replace(/<@!?\d+>/g, (match) => `<@\u200b${match.slice(2)}`)
+ .replace(/<#\d+>/g, (match) => `<#\u200b${match.slice(2)}`)
+ .replace(/<:\w+:\d+>/g, (match) => `<:\u200b${match.slice(2)}`)
+ .replace(/<a:\w+:\d+>/g, (match) => `<a:\u200b${match.slice(3)}`);
+}
+
export async function postToDiscord(
webhookUrl: string,
message: DiscordMessage,
diff --git a/apps/api/src/plugins/discord/events.ts b/apps/api/src/plugins/discord/events.ts
index 8b53d2cfb..fc77da980 100644
--- a/apps/api/src/plugins/discord/events.ts
+++ b/apps/api/src/plugins/discord/events.ts
@@ -1,6 +1,7 @@
import { and, eq } from "drizzle-orm";
import db from "../../database";
import {
+ columnTable,
projectTable,
taskTable,
userTable,
@@ -15,7 +16,7 @@ import type {
TaskStatusChangedEvent,
TaskTitleChangedEvent,
} from "../types";
-import { postToDiscord } from "./client";
+import { postToDiscord, sanitizeDiscordContent } from "./client";
import type { DiscordConfig, DiscordEventKey } from "./config";
import { normalizeDiscordConfig } from "./config";
@@ -25,7 +26,8 @@ type DiscordEventData = {
projectName: string;
taskUrl: string | null;
actorName: string | null;
- status: string | null;
+ statusSlug: string;
+ columnName: string | null;
priority: string | null;
};
@@ -72,6 +74,7 @@ async function getDiscordEventData(
number: taskTable.number,
status: taskTable.status,
priority: taskTable.priority,
+ columnName: columnTable.name,
projectName: projectTable.name,
projectId: projectTable.id,
workspaceId: workspaceTable.id,
@@ -79,6 +82,13 @@ async function getDiscordEventData(
.from(taskTable)
.innerJoin(projectTable, eq(taskTable.projectId, projectTable.id))
.innerJoin(workspaceTable, eq(projectTable.workspaceId, workspaceTable.id))
+ .leftJoin(
+ columnTable,
+ and(
+ eq(taskTable.columnId, columnTable.id),
+ eq(columnTable.projectId, projectTable.id),
+ ),
+ )
.where(and(eq(taskTable.id, taskId), eq(projectTable.id, projectId)))
.limit(1);
@@ -105,7 +115,8 @@ async function getDiscordEventData(
projectName: taskRow.projectName,
taskUrl,
actorName: user?.name ?? null,
- status: taskRow.status,
+ statusSlug: taskRow.status,
+ columnName: taskRow.columnName,
priority: taskRow.priority,
};
}
@@ -119,43 +130,54 @@ async function sendDiscordMessage(
const issueKey =
data.taskNumber !== null ? `#${data.taskNumber}` : "Task update";
const taskLabel = `${issueKey} ${data.taskTitle}`;
+ const safeTitle = sanitizeDiscordContent(title);
+ const safeBody = sanitizeDiscordContent(body);
+ const safeTaskLabel = sanitizeDiscordContent(taskLabel);
+ const safeProjectName = sanitizeDiscordContent(data.projectName);
+ const safeStatus = sanitizeDiscordContent(
+ data.columnName ?? toSentenceCase(data.statusSlug),
+ );
+ const safePriority = sanitizeDiscordContent(toSentenceCase(data.priority));
+ const safeActor = data.actorName
+ ? sanitizeDiscordContent(data.actorName)
+ : null;
try {
await postToDiscord(config.webhookUrl, {
- content: `${title}: ${data.taskTitle}`,
+ content: `${safeTitle}: ${safeTaskLabel}`,
embeds: [
{
- title,
- description: body,
+ title: safeTitle,
+ description: safeBody,
url: data.taskUrl ?? undefined,
color: 0x5865f2,
fields: [
{
name: "Task",
value: data.taskUrl
- ? `[${taskLabel}](${data.taskUrl})`
- : taskLabel,
+ ? `[${safeTaskLabel}](${data.taskUrl})`
+ : safeTaskLabel,
inline: true,
},
{
name: "Project",
- value: data.projectName,
+ value: safeProjectName,
inline: true,
},
{
name: "Status",
- value: toSentenceCase(data.status),
+ value: safeStatus,
inline: true,
},
{
name: "Priority",
- value: toSentenceCase(data.priority),
+ value: safePriority,
inline: true,
},
],
footer: {
- text: data.actorName
- ? `Triggered by ${data.actorName}`
+ text: safeActor
+ ? `Triggered by ${safeActor}`
: "Triggered by Kaneo",
},
},
diff --git a/apps/api/src/plugins/generic-webhook/events.ts b/apps/api/src/plugins/generic-webhook/events.ts
index 646e47c28..98481342f 100644
--- a/apps/api/src/plugins/generic-webhook/events.ts
+++ b/apps/api/src/plugins/generic-webhook/events.ts
@@ -1,6 +1,7 @@
import { and, eq } from "drizzle-orm";
import db from "../../database";
import {
+ columnTable,
integrationTable,
projectTable,
taskTable,
@@ -25,6 +26,7 @@ type GenericWebhookTaskData = {
title: string;
number: number | null;
status: string | null;
+ statusName: string | null;
priority: string | null;
projectId: string;
projectName: string;
@@ -50,6 +52,7 @@ async function getTaskData(
number: taskTable.number,
status: taskTable.status,
priority: taskTable.priority,
+ columnName: columnTable.name,
projectId: projectTable.id,
projectName: projectTable.name,
workspaceId: workspaceTable.id,
@@ -57,6 +60,13 @@ async function getTaskData(
.from(taskTable)
.innerJoin(projectTable, eq(taskTable.projectId, projectTable.id))
.innerJoin(workspaceTable, eq(projectTable.workspaceId, workspaceTable.id))
+ .leftJoin(
+ columnTable,
+ and(
+ eq(taskTable.columnId, columnTable.id),
+ eq(columnTable.projectId, projectTable.id),
+ ),
+ )
.where(and(eq(taskTable.id, taskId), eq(projectTable.id, projectId)))
.limit(1);
@@ -68,6 +78,8 @@ async function getTaskData(
return {
...taskRow,
+ status: taskRow.status,
+ statusName: taskRow.columnName ?? taskRow.status,
taskUrl: `${clientUrl}/dashboard/workspace/${taskRow.workspaceId}/project/${taskRow.projectId}/task/${taskId}`,
};
}
@@ -168,6 +180,7 @@ async function sendEvent(
number: task.number,
title: task.title,
status: task.status,
+ statusName: task.statusName,
priority: task.priority,
url: task.taskUrl,
},