fix: fix webhook pr body data access Error#45
Conversation
📝 WalkthroughWalkthroughThese changes refactor the PR summary generation flow by removing debug logging, eliminating unused destructured variables, and replacing session-based account retrieval with repository-based GitHub account resolution and validation. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/ai/actions/index.ts (1)
195-198: Typo in return key: "sucess" → "success".This typo also appears on line 105. Consumers expecting
successwill get unexpected behavior.🔎 Proposed fix
return { - sucess: true, + success: true, message: "PR Summary Queued", };
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
app/api/webhooks/github/route.tsinngest/functions/index.tslib/ai/actions/index.ts
💤 Files with no reviewable changes (2)
- app/api/webhooks/github/route.ts
- inngest/functions/index.ts
🔇 Additional comments (1)
lib/ai/actions/index.ts (1)
153-169: LGTM on the repository lookup pattern.The Prisma query correctly includes the nested owner accounts filtered by GitHub provider.
| if (!repository) | ||
| throw new Error( | ||
| `Repository ${owner}/${repoName} not found in databse. Please reconnect the repository.` | ||
| ); |
There was a problem hiding this comment.
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.
| 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.
| `Repository ${owner}/${repoName} not found in databse. Please reconnect the repository.` | ||
| ); | ||
|
|
||
| const githubAccount = repository.owner.accounts[0]; |
There was a problem hiding this comment.
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.
| 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.
Summary by CodeRabbit
Chores
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.