Compare commits

...
2 Commits
Author SHA1 Message Date
asepharyana 296f825347 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').
2026-09-21 15:38:21 +07:00
asepharyana 391743780d fix(discord): review score scale is 0-100 not /10
The LLM review score comes from the PR Reviewer Guide table which uses a
0-100 scale (72, 78, 100...). The Discord notification appended '/10',
making it read 'score 72/10'. Fixed to '/100' to match the actual scale.
2026-09-21 15:35:30 +07:00
+33 -2
View File
@@ -115,9 +115,9 @@ export async function handleWebhook(
env.discordWebhookUrl,
`**${owner}/${repo}** PR #${pr.number} reviewed` +
(result.data && result.data["review"] && (result.data["review"] as Record<string, unknown>)["score"]
? ` — score ${(result.data["review"] as Record<string, unknown>)["score"]}/10`
? ` — 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(/&nbsp;/g, " ")
.replace(/&amp;/g, "&")
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&quot;/g, '"')
.replace(/&#39;/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, {