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
9 changes: 3 additions & 6 deletions app/api/webhooks/github/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,12 @@ export async function POST(request: NextRequest) {
prNumber,
body?.installation?.id,
pull_request?.base?.sha,
pull_request?.head?.sha,
pull_request?.changed_files,
pull_request?.additions,
pull_request?.deletions
pull_request?.head?.sha
);
console.log(`Review completed for: ${repo} #${prNumber}`);
console.log(`Review queued for: ${repo} #${prNumber}`);
} catch (error) {
console.error(
`Review failed for repo: ${repo} #${prNumber}: `,
`Review queue failed for repo: ${repo} #${prNumber}: `,
error
);
}
Expand Down
84 changes: 42 additions & 42 deletions lib/ai/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ export async function reviewPullRequest(
prNumber: number,
installationId: number,
baseSha: string,
headSha: string,
changedFiles: number,
additions: number,
deletions: number
headSha: string
) {
try {
const repository = await prisma.repo.findFirst({
Expand Down Expand Up @@ -46,12 +43,8 @@ export async function reviewPullRequest(

const token = githubAccount.accessToken;

const { title, description, author } = await getPullRequestDiff(
token,
owner,
repo,
prNumber
);
const { title, description, changed_files, deletions, additions } =
await getPullRequestDiff(token, owner, repo, prNumber);

// Find or create PullRequest
let pullRequest = await (prisma as any).pullRequest.findUnique({
Expand Down Expand Up @@ -82,9 +75,8 @@ export async function reviewPullRequest(
});

if (!defaultPersona) {
throw new Error(
"No persona found for user. Please create a persona first."
);
console.error("No persona found");
return { success: false };
Comment on lines +78 to +79
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Behavior change: returning false instead of throwing.

This changes error propagation semantics. Previously, missing persona would throw an exception caught by the webhook handler. Now it returns { success: false }, but the webhook handler (app/api/webhooks/github/route.ts lines 110-124) doesn't check the return value, causing it to log "Review queued" even when no review was actually queued.

Note: There's also an existing typo at line 131: sucess instead of success, which means successful returns have a different key spelling than this failure return.

Consider either:

  1. Keep throwing an error here (preserve existing behavior), OR
  2. Update the webhook handler to check and handle the { success: false } return value (see my comment on the webhook file)

Also consider fixing the typo at line 131: sucesssuccess for consistency.

🤖 Prompt for AI Agents
In lib/ai/actions/index.ts around lines 78-79, the function currently logs "No
persona found" and returns { success: false } which changes error propagation
and breaks the webhook flow; revert to throwing an error instead of returning a
failure object so upstream webhook error handling works as before, or if you
prefer the new return-style contract, update the webhook handler to check the
returned value and handle failure cases (do not assume success), and fix the
typo at line 131 by changing "sucess" to "success" so returned objects use a
consistent key.

}

// Create Run
Expand All @@ -96,36 +88,44 @@ export async function reviewPullRequest(
},
});

await inngest.send({
name: "pr.summary.requested",
id: `review-${repository.id}-${prNumber}`,
data: {
owner,
repo,
prNumber,
title: title ?? "",
description: description ?? "",
accountId: githubAccount.accountId,
installationId: installationId ?? null,
baseSha,
headSha,
changedFiles: changedFiles ?? 0,
additions: additions ?? 0,
deletions: deletions ?? 0,
},
});
try {
await inngest.send({
name: "pr.summary.requested",
id: `summary-${repository.id}-${prNumber}`,
data: {
owner,
repo,
prNumber,
title: title ?? "",
description: description ?? "",
accountId: githubAccount.accountId,
installationId: installationId ?? null,
baseSha,
headSha,
changedFiles: changed_files ?? 0,
additions: additions ?? 0,
deletions: deletions ?? 0,
},
});
} catch (e) {
console.error("Summary enqueue failed", e);
}

await inngest.send({
name: "pr.review.requested",
id: `review-${repository.id}-${prNumber}`,
data: {
owner,
repo,
prNumber,
userId: repository.ownerId,
runId: run.id,
},
});
try {
await inngest.send({
name: "pr.review.requested",
id: `review-${repository.id}-${prNumber}`,
data: {
owner,
repo,
prNumber,
userId: repository.ownerId,
runId: run.id,
},
});
} catch (e) {
console.error("Review enqueue failed", e);
}

return {
sucess: true,
Expand Down
3 changes: 3 additions & 0 deletions lib/github-utils/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ export async function getPullRequestDiff(
title: pr.title,
description: pr.body || "",
author: pr.user.name,
changed_files: pr.changed_files,
additions: pr.additions,
deletions: pr.deletions,
};
}

Expand Down