From a5b1a197a263149955cd5fa30690eaffd712b08d Mon Sep 17 00:00:00 2001 From: afuhflynn Date: Mon, 29 Dec 2025 01:23:51 +0100 Subject: [PATCH] fix: fix webhook pr body data access Error --- app/api/webhooks/github/route.ts | 1 - inngest/functions/index.ts | 1 - lib/ai/actions/index.ts | 30 ++++++++++++++++++++---------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/api/webhooks/github/route.ts b/app/api/webhooks/github/route.ts index ae98c08..21eaf2c 100644 --- a/app/api/webhooks/github/route.ts +++ b/app/api/webhooks/github/route.ts @@ -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, diff --git a/inngest/functions/index.ts b/inngest/functions/index.ts index 186f62a..d67ce2d 100644 --- a/inngest/functions/index.ts +++ b/inngest/functions/index.ts @@ -334,7 +334,6 @@ export const summarizePr = inngest.createFunction( changedFiles, additions, deletions, - installationId, } = event.data; // No summary for too many files changed diff --git a/lib/ai/actions/index.ts b/lib/ai/actions/index.ts index 03e64a8..6985d2f 100644 --- a/lib/ai/actions/index.ts +++ b/lib/ai/actions/index.ts @@ -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, @@ -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.` + ); + const githubAccount = repository.owner.accounts[0]; await inngest.send({ name: "pr.summary.requested", data: { @@ -172,7 +182,7 @@ export async function generatePullRequestSummary( prNumber, title: title ?? "", description: description ?? "", - accountId: account.accountId, + accountId: githubAccount.accountId, installationId: installationId ?? null, baseSha, headSha,