Skip to content

feat: add some new changes#58

Merged
afuhflynn merged 1 commit intomainfrom
chore/octokit-app-upgrade
Dec 29, 2025
Merged

feat: add some new changes#58
afuhflynn merged 1 commit intomainfrom
chore/octokit-app-upgrade

Conversation

@afuhflynn
Copy link
Copy Markdown
Owner

@afuhflynn afuhflynn commented Dec 29, 2025

Summary by CodeRabbit

  • Refactor
    • Enhanced internal code organization for pull request review processing by optimizing how installation credentials are managed and resolved, improving system maintainability and reducing complexity while maintaining full backward compatibility.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 29, 2025

📝 Walkthrough

Walkthrough

The changes remove the installationId parameter from the reviewPullRequest function signature across the codebase, shifting responsibility for obtaining it from callers to the function itself via database lookups for account and installation records.

Changes

Cohort / File(s) Summary
Webhook GitHub Route
app/api/webhooks/github/route.ts
Removed installationId argument from reviewPullRequest invocation in pull_request handler; now called with (owner, repoName, prNumber, baseSha, headSha) instead of (owner, repoName, prNumber, installationId, baseSha, headSha).
AI Actions Function
lib/ai/actions/index.ts
Removed installationId parameter from reviewPullRequest signature; added logic to fetch account by accountId, validate it, and fetch installation by userId to derive installationId dynamically before sending pr.summary.requested event payload; introduces new error path for invalid accounts.

Sequence Diagram(s)

sequenceDiagram
    participant Webhook as Webhook Handler
    participant Func as reviewPullRequest()
    participant DB as Database
    participant EventBus as Event Bus

    rect rgb(240, 248, 255)
    Note over Func: New Flow: Resolve installationId internally
    end

    Webhook->>Func: Call with (owner, repo, prNumber, baseSha, headSha)<br/>no installationId
    activate Func
    Func->>DB: Fetch account by accountId
    DB-->>Func: account record
    alt account invalid
        Func-->>Webhook: Error: Invalid account
    else account valid
        Func->>DB: Fetch installation by userId
        DB-->>Func: installation record
        Func->>EventBus: Send pr.summary.requested<br/>with installationId from record
        EventBus-->>Func: Event queued
    end
    deactivate Func
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 No more installationId in sight,
From callers freed, a rabbit's delight!
The database whispers secrets untold,
Deriving the ID from accounts so bold,
One hop removed, the code flows just right! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'feat: add some new changes' is vague and generic, using non-descriptive language that fails to convey the specific nature of the changeset. Replace with a descriptive title that reflects the main change, such as 'refactor: remove installationId parameter and derive from database' to clearly indicate the architectural change.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/octokit-app-upgrade

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
lib/ai/actions/index.ts (3)

35-35: Fix typo in error message.

"databse" should be "database".

🔎 Proposed fix
-        `Repository ${owner}/${repo} not found in databse. Please reconnect the repository.`
+        `Repository ${owner}/${repo} not found in database. Please reconnect the repository.`

38-38: Add bounds check before accessing array.

Accessing accounts[0] without validating the array is non-empty can cause a runtime error if no GitHub account exists for the owner.

🔎 Proposed fix
 const githubAccount = repository.owner.accounts[0];
+
+if (!githubAccount) {
+  throw new Error(`No GitHub account found for repository owner`);
+}

140-140: Fix typo in return object property.

"sucess" should be "success". This typo in the property name could break API contracts if consumers expect the correctly spelled field name.

🔎 Proposed fix
     return {
-      sucess: true,
+      success: true,
       message: "Review Queued",
       runId: run.id,
     };
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d3e0e6 and baa01aa.

📒 Files selected for processing (2)
  • app/api/webhooks/github/route.ts
  • lib/ai/actions/index.ts
💤 Files with no reviewable changes (1)
  • app/api/webhooks/github/route.ts
🔇 Additional comments (2)
lib/ai/actions/index.ts (2)

7-13: LGTM: Function signature refactored correctly.

The removal of the installationId parameter is a clean refactoring that shifts the responsibility for resolving the installation ID into the function itself.


119-119: ****

Already addressed in the review comment for lines 89-108.

Comment on lines +89 to +108
const account = await prisma.account.findFirst({
where: {
accountId: String(githubAccount.accountId),
},
include: {
user: true,
},
});

if (!account) {
throw new Error("Invalid account");
}
const installation = await prisma.installation.findFirst({
where: {
userId: account.user.id,
},
select: {
installationId: true,
},
});
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

🧩 Analysis chain

🏁 Script executed:

# First, let's get the full context of the file around lines 38-120
head -n 150 lib/ai/actions/index.ts | tail -n 120

Repository: afuhflynn/code-reverb

Length of output: 2976


🏁 Script executed:

# Search for the pr.summary.requested event handler and installationId usage
rg -n "pr\.summary\.requested" --type ts -A 10 -B 2

Repository: afuhflynn/code-reverb

Length of output: 1450


🏁 Script executed:

# Look for how installationId is used in the codebase
rg -n "installationId" --type ts -C 5 | head -n 100

Repository: afuhflynn/code-reverb

Length of output: 5747


🏁 Script executed:

# Check the database schema/Prisma models to understand type consistency
find . -name "*.prisma" -o -name "schema.prisma" | head -5

Repository: afuhflynn/code-reverb

Length of output: 87


🏁 Script executed:

# Check the Prisma schema to understand the type of accountId and userId relationships
cat prisma/schema.prisma | grep -A 20 "model Account"

Repository: afuhflynn/code-reverb

Length of output: 741


🏁 Script executed:

# Check the Installation model schema
cat prisma/schema.prisma | grep -A 20 "model Installation"

Repository: afuhflynn/code-reverb

Length of output: 729


🏁 Script executed:

# Check how getOctokitForInstallation handles null installationId
rg -n "getOctokitForInstallation" --type ts -A 10 -B 2

Repository: afuhflynn/code-reverb

Length of output: 5122


🏁 Script executed:

# Check if there's any null handling for installationId in the summarizePr event handler
rg -n "summarizePr" --type ts -A 30 | grep -A 30 "installationId"

Repository: afuhflynn/code-reverb

Length of output: 1639


🏁 Script executed:

# Check the full implementation of getOctokitForInstallation to see if it handles null
cat config/octokit-instance.ts

Repository: afuhflynn/code-reverb

Length of output: 870


🏁 Script executed:

# Check if there's any null checking for installationId in the summarizePr event handler before calling getOctokitForInstallation
rg -n "summarizePr" --type ts -A 50 | head -80

Repository: afuhflynn/code-reverb

Length of output: 3714


🏁 Script executed:

# Get the full summarizePr function implementation to see how installationId is used
sed -n '322,450p' inngest/functions/index.ts

Repository: afuhflynn/code-reverb

Length of output: 3446


Address error handling inconsistency and prevent potential null reference errors in downstream code.

The account and installation lookup pattern is not redundant—it's a necessary two-step flow to get account.user.id which is required to find the installation. However, the code has two issues:

  1. Error handling inconsistency (lines 98-100, 101-108): An error is thrown when the account is not found, but null is allowed when the installation is not found. This inconsistency is compounded by the fact that the null installationId is then passed directly to postSummaryAsUser()getOctokitForInstallation() at line 119. The getOctokitForInstallation function expects a number but receives number | null, with no null checks, which will cause a runtime error.

  2. Missing null check: Before sending the pr.summary.requested event with a potentially null installationId, validate that the installation was found or decide whether this is a critical failure. If it's optional, ensure downstream handlers in summarizePr (lines 388-391 in inngest/functions/index.ts) properly guard against null before calling getOctokitForInstallation.

🤖 Prompt for AI Agents
In lib/ai/actions/index.ts around lines 89 to 108, the account lookup throws
when missing but the installation lookup allows null and its installationId
(possibly null) is passed to postSummaryAsUser/getOctokitForInstallation; make
the behavior consistent by validating the installation result and handling null:
either throw an error when no installation is found (recommended if the
operation requires an installation) or explicitly handle the optional case
before calling postSummaryAsUser (e.g., early-return, send an event without
installationId, or branch logic) and ensure any call to
getOctokitForInstallation only receives a non-null number after a check; update
downstream callers or add guards so getOctokitForInstallation never receives
number | null.

@afuhflynn afuhflynn merged commit 88c157a into main Dec 29, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant