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
2 changes: 1 addition & 1 deletion config/octokit-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function getOctokitForInstallation(installationId: number) {
authStrategy: createAppAuth,
auth: {
appId: Number(process.env.GITHUB_APP_ID),
privateKey: process.env.GITHUB_PRIVATE_KEY,
privateKey: process.env.GITHUB_APP_PRIVATE_KEY,
installationId,
},
});
Expand Down
3 changes: 2 additions & 1 deletion inngest/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export const summarizePr = inngest.createFunction(
changedFiles,
additions,
deletions,
installationId,
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 look at the actual code around line 337 in inngest/functions/index.ts
head -360 inngest/functions/index.ts | tail -30

Repository: afuhflynn/code-reverb

Length of output: 758


🏁 Script executed:

# Run the provided script to find where pr.summary.requested event is triggered
rg -nP "pr\.summary\.requested|['\"](pr\.summary\.requested)['\"]" --type=ts --type=js -A 10 -B 2

Repository: afuhflynn/code-reverb

Length of output: 1501


🏁 Script executed:

# Get more context around line 337 - show more lines to see how installationId is used
sed -n '320,400p' inngest/functions/index.ts

Repository: afuhflynn/code-reverb

Length of output: 2171


🏁 Script executed:

# Find the postSummaryAsUser function to check if it requires installationId
rg -n "postSummaryAsUser|function postSummaryAsUser" --type=ts --type=js -A 5

Repository: afuhflynn/code-reverb

Length of output: 1131


🏁 Script executed:

# Get context around line 403 where postSummaryAsUser is called
sed -n '395,410p' inngest/functions/index.ts

Repository: afuhflynn/code-reverb

Length of output: 363


🏁 Script executed:

# Check the full signature and implementation of postSummaryAsUser
sed -n '269,290p' lib/github-utils/actions/index.ts

Repository: afuhflynn/code-reverb

Length of output: 514


Add validation for installationId before using it.

The event data can send installationId as null (see lib/ai/actions/index.ts:186), but postSummaryAsUser expects it as a required number. Without validation, passing a null value will cause a runtime error when getOctokitForInstallation(installationId) is called.

Add this check after destructuring:

if (!installationId) {
  throw new Error("installationId is required in event.data");
}
🤖 Prompt for AI Agents
In inngest/functions/index.ts around line 337, installationId from event.data
can be null but is used as a required number later (causing runtime errors);
after the destructuring of event.data add a validation that installationId is
present and truthy and throw a clear Error like "installationId is required in
event.data" if missing so subsequent calls (e.g. getOctokitForInstallation)
receive a valid number.

} = event.data;

// No summary for too many files changed
Expand Down Expand Up @@ -399,7 +400,7 @@ Generate a technical summary based primarily on the code changes above.`;
});

await step.run("post-summary-comment", async () => {
await postSummaryAsUser(owner, repo, prNumber, summary);
await postSummaryAsUser(owner, repo, prNumber, summary, installationId);
});

return { success: true };
Expand Down
8 changes: 4 additions & 4 deletions lib/github-utils/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ export async function postSummaryAsUser(
owner: string,
repo: string,
prNumber: number,
summary: string
summary: string,
installationId: number
) {
const token = await getGithubToken();
const octokit = new Octokit({ auth: token });
const octokit = getOctokitForInstallation(installationId);

await octokit.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: summary,
body: `## Summary by CodeReverb\n\n${summary}\n\n---\n*Generated automatically by CodeReverb [Try out CodeReverb](https://codereverb.dev)*`,
});
}