fix(discord): strip HTML table markup from review notifications
Discord embeds render markdown, not HTML — the PR Reviewer Guide table (<table><tr><td>…) was appearing as literal HTML in the webhook message. Added htmlToDiscordPlain(): collapses the table into readable lines (score/effort/security/key-issues), keeps emoji + **bold** markdown, and decodes entities. Also fixed review score suffix '/10' → '/100' (the LLM score scale is 0-100, matching the table's 'Score: 72').
This commit is contained in:
+32
-1
@@ -117,7 +117,7 @@ export async function handleWebhook(
|
||||
(result.data && result.data["review"] && (result.data["review"] as Record<string, unknown>)["score"]
|
||||
? ` — score ${(result.data["review"] as Record<string, unknown>)["score"]}/100`
|
||||
: "") +
|
||||
`\n${result.markdown.slice(0, 4000)}`,
|
||||
`\n${htmlToDiscordPlain(result.markdown).slice(0, 4000)}`,
|
||||
"✅ PR-Agent Review Complete",
|
||||
);
|
||||
}
|
||||
@@ -147,6 +147,37 @@ async function getHttpx() {
|
||||
return fetch;
|
||||
}
|
||||
|
||||
/** Strip HTML table markup down to Discord-friendly plain text.
|
||||
* Discord embeds render limited markdown — raw <table>/<td>/<tr> tags
|
||||
* would show as literal HTML. Convert the reviewer table into lines. */
|
||||
function htmlToDiscordPlain(html: string): string {
|
||||
let s = html
|
||||
.replace(/<details>/g, "")
|
||||
.replace(/<\/details>/g, "")
|
||||
.replace(/<summary>/g, "▶ ")
|
||||
.replace(/<\/summary>/g, "\n")
|
||||
.replace(/<br\s*\/?>/gi, "\n")
|
||||
.replace(/<\/tr>/gi, "\n")
|
||||
.replace(/<\/td>/gi, "")
|
||||
.replace(/<\/th>/gi, "")
|
||||
.replace(/<td[^>]*>/gi, "")
|
||||
.replace(/<th[^>]*>/gi, "")
|
||||
.replace(/<tr[^>]*>/gi, "")
|
||||
.replace(/<table[^>]*>/gi, "")
|
||||
.replace(/<\/table>/gi, "")
|
||||
.replace(/<li[^>]*>/gi, "• ")
|
||||
.replace(/<[^>]+>/g, "")
|
||||
.replace(/ /g, " ")
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, "'")
|
||||
.replace(/\n{3,}/g, "\n\n")
|
||||
.trim();
|
||||
return s;
|
||||
}
|
||||
|
||||
async function sendDiscord(webhook: string, content: string, title?: string): Promise<void> {
|
||||
try {
|
||||
await fetch(webhook, {
|
||||
|
||||
Reference in New Issue
Block a user