From 6f8079e293fd9df386fe3502ee9e1be181c97e9e Mon Sep 17 00:00:00 2001 From: tusharshah21 Date: Sun, 10 May 2026 15:29:11 +0530 Subject: [PATCH] feat: improve chat notifications with detailed findings --- src/main.ts | 3 --- src/notifications.ts | 27 +++++++++++++-------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/main.ts b/src/main.ts index fe842e2..910876d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -136,8 +136,6 @@ async function main() { const eventData = JSON.parse( readFileSync(process.env.GITHUB_EVENT_PATH ?? "", "utf8") ); - const commitSha: string = - eventData.after || eventData.pull_request?.head?.sha || ""; const notificationRefs = notifier.isEnabled() ? await notifier.sendStart({ @@ -146,7 +144,6 @@ async function main() { prTitle: prDetails.title, prUrl: prDetails.url, action: eventData.action || "unknown", - commitSha, }) : {}; diff --git a/src/notifications.ts b/src/notifications.ts index 575e711..3541b27 100644 --- a/src/notifications.ts +++ b/src/notifications.ts @@ -13,7 +13,6 @@ interface NotificationContext { prTitle: string; prUrl: string; action: string; - commitSha?: string; } interface NotificationThreadRefs { @@ -21,11 +20,6 @@ interface NotificationThreadRefs { slackThreadTs?: string; } -function shortenSha(sha?: string): string { - if (!sha) return "n/a"; - return sha.slice(0, 7); -} - function appendWaitQuery(url: string): string { const separator = url.includes("?") ? "&" : "?"; return `${url}${separator}wait=true`; @@ -43,31 +37,36 @@ async function postJson(url: string, payload: Record, headers?: } function buildStartMessage(context: NotificationContext): string { - const commitPart = context.commitSha - ? `Commit: ${shortenSha(context.commitSha)}` - : "Commit: n/a"; - return [ `AI review started for ${context.repoFullName}`, `PR #${context.prNumber}: ${context.prTitle}`, `PR: ${context.prUrl}`, - commitPart, `Event: ${context.action}`, ].join("\n"); } +function truncate(input: string, maxLength: number): string { + const normalized = input.replace(/\s+/g, " ").trim(); + if (normalized.length <= maxLength) return normalized; + return `${normalized.slice(0, maxLength - 3)}...`; +} + function buildResultMessage(results: ReviewResult[]): string { if (results.length === 0) { return "Review finished: no issues found by the reviewer."; } - const lines = results.slice(0, 5).map((result) => { - return `- [${result.issueType}] ${result.file}:${result.lineNumber}`; + const lines = results.slice(0, 3).map((result, index) => { + const explanation = truncate(result.explanation, 220); + return [ + `${index + 1}. [${result.issueType}] ${result.file}:${result.lineNumber}`, + ` Detail: ${explanation}`, + ].join("\n"); }); const extraCount = results.length - lines.length; if (extraCount > 0) { - lines.push(`- ...and ${extraCount} more issue(s)`); + lines.push(`...and ${extraCount} more issue(s).`); } return [