$ show anc95/ChatGPT-CodeReview
This repository implements an AI-powered code review bot for GitHub. It listens for pull request events (opened, synchronize) and uses OpenAI's language models (or Azure OpenAI, GitHub Models) to automatically review code diffs and post inline comments and summary reviews. The system supports multiple deployment modes: a Probot-based GitHub App, a GitHub Action, an AWS Lambda function, and a Vercel serverless function. The core logic is in `src/bot.ts` (event handling, file filtering, review creation) and `src/chat.ts` (LLM API abstraction). The architecture is a monolith with adapter layers for each platform. External dependencies include the OpenAI/LLM API, GitHub API via Octokit, and minimatch for glob-based file filtering. The bot is configurable via environment variables for model selection, prompt customization, language, and file inclusion/exclusion patterns. It also implements an incremental review feature to reduce API costs by only re-reviewing files changed since the last bot review.
The LLM identified 2 files worth highlighting for reuse:
The Chat class encapsulates interactions with OpenAI, Azure OpenAI, and GitHub Models APIs. It handles authentication, model selection, parameter configuration (temperature, top_p, max_tokens, reasoning_effort), prompt construction, and response parsing. This is a clean, self-contained abstraction that could be extracted and reused in any project requiring a multi-provider LLM client. It demonstrates good separation of concerns and defensive programming (e.g., fallback for missing API key).
The file contains several well-crafted utility functions for parsing Git diff hunks: parseHunkHeader extracts line ranges from @@ headers, getReviewCommentLocation determines the correct line and side for inline comments, isHunkHeaderInPatch checks hunk existence, createInlineReviewComment builds comment objects, and createReviewBody constructs the overall review text. These functions are stateless, input/output clean, and could be extracted into a reusable Git diff processing library for other GitHub automation tools. They demonstrate precise string parsing and correct handling of edge cases in unified diffs.