|
1 | 1 | # AI-Powered Pull Request Review Bot
|
2 | 2 |
|
3 |
| -This example demonstrates how to use Codegen to create an intelligent PR review bot that analyzes code changes and their dependencies to provide comprehensive code reviews. The bot uses GPT-4 to generate contextual feedback based on modified code and its relationships. |
| 3 | +This example project demonstrates how to deploy an agentic bot that automatically reviews GitHub Pull Requests. The bot analyzes code changes and their dependencies to provide comprehensive code reviews using AI, considering both direct modifications and their impact on the codebase. |
4 | 4 |
|
5 |
| -> [!NOTE] |
6 |
| -> This codemod helps development teams by providing automated, context-aware code reviews that consider both direct and indirect code dependencies. |
| 5 | +## Prerequisites |
7 | 6 |
|
8 |
| -## How the PR Review Bot Works |
| 7 | +Before running this application, you'll need the following API tokens and credentials: |
9 | 8 |
|
10 |
| -The script analyzes pull requests in several key steps: |
| 9 | +- GitHub API Token |
| 10 | +- Anthropic API Token |
| 11 | +- GitHub Repository Access |
11 | 12 |
|
12 |
| -1. **Symbol Analysis** |
| 13 | +## Setup |
13 | 14 |
|
14 |
| - ```python |
15 |
| - modified_symbols = codebase.get_modified_symbols_in_pr(pr_number) |
16 |
| - for symbol in modified_symbols: |
17 |
| - deps = codebase.get_symbol_dependencies(symbol, max_depth=2) |
18 |
| - rev_deps = codebase.get_symbol_dependents(symbol, max_depth=2) |
19 |
| - ``` |
20 |
| - |
21 |
| - - Identifies modified symbols in the PR |
22 |
| - - Analyzes dependencies up to 2 levels deep |
23 |
| - - Tracks reverse dependencies (symbols that depend on changes) |
24 |
| - |
25 |
| -1. **Context Building** |
26 |
| - |
27 |
| - ```python |
28 |
| - context = {"pr_title": pr.title, "pr_body": pr.body, "modified_symbols": [...], "context_symbols": [...]} |
29 |
| - ``` |
30 |
| - |
31 |
| - - Gathers PR metadata |
32 |
| - - Collects modified code content |
33 |
| - - Includes relevant dependency context |
34 |
| - |
35 |
| -1. **AI Review Generation** |
36 |
| - |
37 |
| - ```python |
38 |
| - review = codebase.ai_client.llm_query_with_retry(messages=[...], model="gpt-4", max_tokens=2000) |
39 |
| - ``` |
40 |
| - |
41 |
| - - Uses GPT-4 for analysis |
42 |
| - - Generates comprehensive review feedback |
43 |
| - - Considers full context of changes |
44 |
| - |
45 |
| -## Why This Makes Code Review Better |
46 |
| - |
47 |
| -1. **Context-Aware Analysis** |
48 |
| - |
49 |
| - - Understands code dependencies |
50 |
| - - Considers impact of changes |
51 |
| - - Reviews code in proper context |
52 |
| - |
53 |
| -1. **Comprehensive Review** |
54 |
| - |
55 |
| - - Analyzes direct modifications |
56 |
| - - Evaluates dependency impact |
57 |
| - - Suggests improvements |
58 |
| - |
59 |
| -1. **Consistent Feedback** |
60 |
| - |
61 |
| - - Structured review format |
62 |
| - - Thorough analysis every time |
63 |
| - - Scalable review process |
64 |
| - |
65 |
| -## Review Output Format |
66 |
| - |
67 |
| -The bot provides structured feedback including: |
| 15 | +1. Clone the repository |
| 16 | +1. Set up your environment variables in a `.env` file: |
68 | 17 |
|
| 18 | +```env |
| 19 | +GITHUB_TOKEN=your_github_token |
| 20 | +ANTHROPIC_API_KEY=your_anthropic_token |
| 21 | +GITHUB_REPO_OWNER=your_repo_owner |
| 22 | +GITHUB_REPO_NAME=your_repo_name |
| 23 | +GITHUB_PR_NUMBER=your_pr_number |
69 | 24 | ```
|
70 |
| -1. Overall Assessment |
71 |
| - - High-level review of changes |
72 |
| - - Impact analysis |
73 |
| -
|
74 |
| -2. Specific Code Feedback |
75 |
| - - Detailed code comments |
76 |
| - - Style suggestions |
77 |
| - - Best practices |
78 |
| -
|
79 |
| -3. Potential Issues |
80 |
| - - Security concerns |
81 |
| - - Performance impacts |
82 |
| - - Edge cases |
83 |
| -
|
84 |
| -4. Dependency Analysis |
85 |
| - - Impact on dependent code |
86 |
| - - Breaking changes |
87 |
| - - Integration considerations |
88 |
| -
|
89 |
| -``` |
90 |
| - |
91 |
| -## Key Benefits to Note |
92 |
| - |
93 |
| -1. **Better Code Quality** |
94 |
| - |
95 |
| - - Thorough code analysis |
96 |
| - - Consistent review standards |
97 |
| - - Early issue detection |
98 |
| - |
99 |
| -1. **Time Savings** |
100 |
| - |
101 |
| - - Automated initial review |
102 |
| - - Quick feedback loop |
103 |
| - - Reduced review burden |
104 |
| - |
105 |
| -1. **Knowledge Sharing** |
106 |
| - |
107 |
| - - Educational feedback |
108 |
| - - Best practice suggestions |
109 |
| - - Team learning |
110 |
| - |
111 |
| -## Configuration Options |
112 | 25 |
|
113 |
| -You can customize the review by: |
| 26 | +## Features |
114 | 27 |
|
115 |
| -- Adjusting dependency depth |
116 |
| -- Modifying the AI prompt |
117 |
| -- Changing the review focus areas |
118 |
| -- Tuning the GPT-4 parameters |
| 28 | +- Automated PR code review using AI |
| 29 | +- Deep dependency analysis of code changes |
| 30 | +- Context-aware feedback generation |
| 31 | +- Structured review format with actionable insights |
| 32 | +- Integration with GitHub PR system |
119 | 33 |
|
120 |
| -## Learn More |
| 34 | +## Usage |
121 | 35 |
|
122 |
| -- [Codegen Documentation](https://docs.codegen.com) |
123 |
| -- [OpenAI API Documentation](https://platform.openai.com/docs/api-reference) |
124 |
| -- [GitHub API Documentation](https://docs.github.com/en/rest) |
125 |
| -- [Codegen llm integration](https://docs.codegen.com/building-with-codegen/calling-out-to-llms) |
| 36 | +1. `uv sync` |
| 37 | +1. `uv run modal deploy app.py` |
| 38 | + - This will deploy a modal app that can be triggered to review PRs |
| 39 | +1. Create or update a PR to trigger the review bot |
126 | 40 |
|
127 | 41 | ## Contributing
|
128 | 42 |
|
129 |
| -Feel free to submit issues and enhancement requests! Contributions to improve the review bot's capabilities are welcome. |
| 43 | +Contributions are welcome! Please feel free to submit a Pull Request. |
0 commit comments