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
1 change: 0 additions & 1 deletion app/api/webhooks/github/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export async function POST(request: NextRequest) {
const [owner, repoName] = repo?.split("/");
// trigger pr summary immediately after
if (action === "opened") {
console.log({ body });
await generatePullRequestSummary(
owner,
repo,
Expand Down
1 change: 0 additions & 1 deletion inngest/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ export const summarizePr = inngest.createFunction(
changedFiles,
additions,
deletions,
installationId,
} = event.data;

// No summary for too many files changed
Expand Down
30 changes: 20 additions & 10 deletions lib/ai/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"use server";

import { auth } from "@/lib/auth";
import { getPullRequestDiff } from "@/lib/github-utils/actions";
import { inngest } from "@/lib/inngest";
import { prisma } from "@/lib/prisma";
import { headers } from "next/headers";

export async function reviewPullRequest(
owner: string,
Expand Down Expand Up @@ -152,18 +150,30 @@ export async function generatePullRequestSummary(
deletions: number
) {
try {
const session = await auth.api.getSession({ headers: await headers() });

if (!session) throw new Error("Unauthorized");
const account = await prisma.account.findFirst({
const repository = await prisma.repo.findFirst({
where: {
userId: session.user.id,
providerId: "github",
name: repoName,
fullName: `${owner}/${repoName}`,
},
include: {
owner: {
include: {
accounts: {
where: {
providerId: "github",
},
},
},
},
},
});

if (!account?.accessToken) throw new Error("No GitHub access token found");
if (!repository)
throw new Error(
`Repository ${owner}/${repoName} not found in databse. Please reconnect the repository.`
);
Comment on lines +171 to +174
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 | 🟡 Minor

Typo in error message: "databse" → "database".

This typo also appears on line 33.

🔎 Proposed fix
     if (!repository)
       throw new Error(
-        `Repository ${owner}/${repoName} not found in databse. Please reconnect the repository.`
+        `Repository ${owner}/${repoName} not found in database. Please reconnect the repository.`
       );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!repository)
throw new Error(
`Repository ${owner}/${repoName} not found in databse. Please reconnect the repository.`
);
if (!repository)
throw new Error(
`Repository ${owner}/${repoName} not found in database. Please reconnect the repository.`
);
🤖 Prompt for AI Agents
In lib/ai/actions/index.ts around lines 171-174 (and also update the same typo
on line 33), fix the misspelled word "databse" to "database" in the thrown Error
message(s). Update both occurrences so the message reads "...not found in
database. Please reconnect the repository." and save/compile to verify no lint
or build errors.


const githubAccount = repository.owner.accounts[0];
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 | 🔴 Critical

Missing validation: accounts[0] may be undefined if no GitHub account is linked.

If the repository owner has no connected GitHub account, accounts will be an empty array, making githubAccount undefined. Accessing githubAccount.accountId on line 185 will throw a TypeError.

🔎 Proposed fix
     const githubAccount = repository.owner.accounts[0];
+
+    if (!githubAccount) {
+      throw new Error(
+        `No GitHub account found for the owner of repository ${owner}/${repoName}.`
+      );
+    }
+
     await inngest.send({
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const githubAccount = repository.owner.accounts[0];
const githubAccount = repository.owner.accounts[0];
if (!githubAccount) {
throw new Error(
`No GitHub account found for the owner of repository ${owner}/${repoName}.`
);
}
await inngest.send({
🤖 Prompt for AI Agents
In lib/ai/actions/index.ts around line 176, the code assumes
repository.owner.accounts[0] exists; if the owner has no linked GitHub account
this will be undefined and later access to githubAccount.accountId will throw.
Add validation: check that repository.owner.accounts is a non-empty array (or
find the account with provider === 'github'), and if no GitHub account is
present either return/throw a clear, handled error or branch to the non-GitHub
flow; ensure subsequent code uses the validated githubAccount object (or early
exits) so no property access occurs on undefined.

await inngest.send({
name: "pr.summary.requested",
data: {
Expand All @@ -172,7 +182,7 @@ export async function generatePullRequestSummary(
prNumber,
title: title ?? "",
description: description ?? "",
accountId: account.accountId,
accountId: githubAccount.accountId,
installationId: installationId ?? null,
baseSha,
headSha,
Expand Down