Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ async function main() {
const eventData = JSON.parse(
Comment thread
tusharshah21 marked this conversation as resolved.
readFileSync(process.env.GITHUB_EVENT_PATH ?? "", "utf8")
Comment thread
tusharshah21 marked this conversation as resolved.
);
const commitSha: string =
eventData.after || eventData.pull_request?.head?.sha || "";

const notificationRefs = notifier.isEnabled()
? await notifier.sendStart({
Expand All @@ -146,7 +144,6 @@ async function main() {
prTitle: prDetails.title,
prUrl: prDetails.url,
action: eventData.action || "unknown",
Comment thread
tusharshah21 marked this conversation as resolved.
commitSha,
})
: {};

Expand Down
27 changes: 13 additions & 14 deletions src/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,13 @@ interface NotificationContext {
prTitle: string;
prUrl: string;
action: string;
commitSha?: string;
}
Comment thread
tusharshah21 marked this conversation as resolved.

interface NotificationThreadRefs {
discordMessageId?: string;
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`;
Expand All @@ -43,31 +37,36 @@ async function postJson(url: string, payload: Record<string, unknown>, 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 {
Comment thread
tusharshah21 marked this conversation as resolved.
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 [
Expand Down
Loading