Tutorial: AI-Powered Code Reviews
OpenCodeHub integrates with LLMs (GPT-4, Claude) to provide automated, intelligent code reviews on every Pull Request. This tutorial guides you through setting it up.
Prerequisites
Section titled “Prerequisites”- An OpenCodeHub instance running v1.0.0+.
- An API Key from OpenAI or Anthropic.
Step 1: Configure Provider
Section titled “Step 1: Configure Provider”As an administrator, you need to configure the AI provider in your environment variables.
For OpenAI:
AI_PROVIDER=openaiOPENAI_API_KEY=sk-proj-...For Anthropic:
AI_PROVIDER=anthropicANTHROPIC_API_KEY=sk-ant-...Restart your OpenCodeHub instance to apply changes.
Step 2: Enable for Repository
Section titled “Step 2: Enable for Repository”By default, AI review is opt-in per repository to save costs.
- Navigate to Repository Settings > AI Review.
- Toggle Enable AI Review.
- Select Triggers:
- On PR Open: Reviews the initial code.
- On Every Push: Reviews every update (Can be expensive).
- Manual Only: Developers must click “Request AI Review”.
Step 3: Seeing it in Action
Section titled “Step 3: Seeing it in Action”- Create a Pull Request with some code.
- If configured for “Manual Only”, look for the ”🤖 Request AI Review” button in the PR sidebar. Click it.
- Wait a few seconds (or minutes for large PRs).
- The AI will comment directly on lines of code with:
- 🔴 Security Risks: SQL injection, hardcoded secrets.
- 🟡 Bugs: Null pointer exceptions, logic errors.
- 🔵 Suggestions: Code style, minor performance tweaks.
Tuning Prompts (Advanced)
Section titled “Tuning Prompts (Advanced)”You can customize the system prompt used for reviews by editing src/lib/ai/prompts.ts if you are self-hosting and want to enforce specific coding standards.