llm summary and updates to PRs#1
Conversation
There was a problem hiding this comment.
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.tswithcheckForBugs()andgenerateSummary()functions for AI-powered code analysis - Added
createFileCommentandcreatePRCommentutilities insrc/utils.tsfor 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.tsnow logs entire webhook payload which may expose sensitive information - Enhanced
src/handlers.tswith 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.
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.
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.
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; |
| @@ -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.
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.
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.
logic: Missing error handling here - add try/catch like in checkForBugs()
Core functionality