-
Notifications
You must be signed in to change notification settings - Fork 1
llm summary and updates to PRs #1
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
base: main
Are you sure you want to change the base?
Conversation
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.
PR Summary
Implements automated code review functionality using OpenAI's GPT-4 for analyzing pull requests, generating change summaries, and detecting potential bugs.
- Added new
src/llm.ts
withcheckForBugs()
andgenerateSummary()
functions for AI-powered code analysis - Added
createFileComment
andcreatePRComment
utilities insrc/utils.ts
for handling both inline and general PR comments - Integrated OpenAI package (v5.8.4) and ngrok for development testing in
package.json
- Security concern:
src/index.ts
now logs entire webhook payload which may expose sensitive information - Enhanced
src/handlers.ts
with LLM-based diff analysis and automated comment generation
5 files reviewed, 6 comments
Edit PR Review Bot Settings | Greptile
// Webhook endpoint | ||
app.post('/webhook', async (req, res) => { | ||
try { | ||
console.log(req.body) |
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.
logic: Remove or guard this log statement. GitHub webhook payloads contain sensitive data. If needed, log specific fields or use debug logging that's disabled in production.
console.log(req.body) | |
// Log only necessary fields to avoid exposing sensitive data | |
console.log('Received webhook event:', req.body.action); |
|
||
const FIRST_LINE = 1; | ||
|
||
export const handleWebhook = async (payload: any) => { |
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.
style: payload type needs to be properly typed for webhook events rather than 'any' to ensure type safety
export const handleWebhook = async (payload: any) => { | |
export const handleWebhook = async (payload: WebhookPayload) => { |
function getFileDiffFromRaw(diff: any, filename: string): string | null { | ||
const pattern = new RegExp(`^diff --git a/${filename.replace(/\./g, '\\.')}.*?(?=^diff --git|\\Z)`, 'gms'); | ||
const match = diff.match(pattern); | ||
return match ? match[0] : null; |
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.
logic: regex pattern could fail with filenames containing special characters - needs more robust diff parsing
function getFileDiffFromRaw(diff: any, filename: string): string | null { | |
const pattern = new RegExp(`^diff --git a/${filename.replace(/\./g, '\\.')}.*?(?=^diff --git|\\Z)`, 'gms'); | |
const match = diff.match(pattern); | |
return match ? match[0] : null; | |
function getFileDiffFromRaw(diff: any, filename: string): string | null { | |
const escapedFilename = filename.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | |
const pattern = new RegExp(`^diff --git a/${escapedFilename}.*?(?=^diff --git|\\Z)`, 'gms'); | |
const match = diff.match(pattern); | |
return match ? match[0] : null; |
src/llm.ts
Outdated
@@ -0,0 +1,61 @@ | |||
import { OpenAI } from "openai" | |||
|
|||
const openai = new OpenAI({ apiKey: process.env.OPEN_AI_KEY}); |
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.
style: Consider validating process.env.OPEN_AI_KEY exists early to fail fast if API key is missing
const openai = new OpenAI({ apiKey: process.env.OPEN_AI_KEY}); | |
if (!process.env.OPEN_AI_KEY) throw new Error('OPEN_AI_KEY environment variable is required'); | |
const openai = new OpenAI({ apiKey: process.env.OPEN_AI_KEY}); |
try { | ||
const output = response.choices[0].message.content?.trim() || "[]"; | ||
return JSON.parse(output); | ||
} catch (err){ | ||
console.error('Failed to parse bug comment response:', err); | ||
return []; | ||
} |
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.
style: Add type information to err parameter. Also consider rethrowing or handling specific OpenAI errors differently than JSON parse errors
const response = await openai.chat.completions.create({ | ||
model: 'gpt-4', | ||
temperature: 0.5, | ||
messages: [ | ||
{ role: "system", content: SYSTEM_CONTENT }, | ||
{ role: "user", content: context} | ||
] | ||
}); |
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.
logic: Missing error handling here - add try/catch like in checkForBugs()
Core functionality