-
Notifications
You must be signed in to change notification settings - Fork 0
fix: fix webhook pr body data access Error #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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, | ||||||||||||||||||||||
|
|
@@ -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]; | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing validation: If the repository owner has no connected GitHub account, 🔎 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| 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, | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
🤖 Prompt for AI Agents