This project is an automated code review tool that leverages AI to provide insightful feedback on GitHub pull requests. It combines GitHub integration, AI-powered analysis, and basic code metrics to offer comprehensive code reviews.
- Automatic pull request analysis
- AI-generated code review comments
- Basic code metrics
- Configurable settings via YAML file
- Environment variable support for sensitive data
- Python 3.7 or higher
- GitHub account and personal access token
- OpenAI API key
-
Clone the repository:
git clone https://github.com/yourusername/ai-powered-code-reviewer.git cd ai-powered-code-reviewer
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use: venv\Scripts\activate
-
Install the required packages:
pip install -r requirements.txt
-
Set up your environment variables: Create a
.env
file in the project root and add your GitHub and OpenAI API keys:GITHUB_TOKEN=your_github_token OPENAI_API_KEY=your_open
The project uses a YAML configuration file located at config/config.yaml. You can customize various settings here, including:
github:
token: ${GITHUB_TOKEN}
openai:
api_key: ${OPENAI_API_KEY}
review:
max_files: 5
file_extensions:
- .py
- .js
- .ts
ai:
model: gpt-3.5-turbo
temperature: 0.7
max_tokens: 500
prompts:
code_review: |
You are a code reviewer. Analyze the following code diff and provide constructive feedback:
{code_diff}
Focus on:
1. Code quality
2. Potential bugs
3. Performance issues
4. Best practices
Run the code reviewer with the following command:
python src/main.py --repo username/repository --pr pull_request_number
Optional arguments:
- --config: Specify a custom configuration file path (default:
config/config.yaml
)
src/
: Contains the main source codemain.py
: Entry point of the applicationgithub_integration.py
: Handles GitHub API interactionsai_integration.py
: Manages AI-powered code reviewcode_analysis.py
: Performs basic code analysis
tests/
: Contains unit testsconfig/
: Holds configuration files
To run the tests, use the following command:
pytest tests/
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.