READ LICENSE BEFORE INSTALLING AND RUNNING THE PROJECT.
The AI-Powered Code Reviewer is a tool that uses natural language processing and machine learning to provide intelligent code reviews for Merge Requests (MRs) in a GitHub repository. It analyzes the code changes, considers the relevant context from the codebase, and generates detailed feedback on potential issues, code quality, and areas for improvement.
The project utilizes the following technologies:
- Python: The main programming language used for the project.
- Chroma: A vector database used for storing and querying code embeddings.
- Git: Used for cloning and managing the Git repository.
- GitHub API: Used for fetching Merge Request details and posting review comments.
- Ollama: Ollama is a software required to run LLM locally.
- LLMs (Large Language Models): Used for generating code embeddings and reviews, operating under their respective licenses.
The code relies on the vector database (Chroma) to store and query relevant context for the code review process.
-
Clone the repository:
git clone https://github.com/sumitpore/MRCodeReviewUsingAI.git -
Create a new Python virtual environment and activate it:
python -m venv venv source venv/bin/activate -
Install the required dependencies:
pip install -r requirements.txt -
Set up the Chroma database:
mkdir chroma_db
-
Install Ollama: Ollama is required to run LLM models locally. You can install it by following the instructions on the Ollama installation page.
-
Pull the Llama 3.1 Model: After installing Ollama, pull the
llama3.1model by running the following command:ollama pull llama3.1 -
Pull the Chroma Embedding Model: Pull the
chroma/all-minilm-l6-v2-f32model required for embeddings:ollama pull chroma/all-minilm-l6-v2-f32Ensure both models are successfully pulled before proceeding with the usage of the AI-Powered Code Reviewer.
-
Run the code reviewer:
python main.py --repo_path /path/to/git/repo --repo_owner your-github-username --repo_name your-repo-name --github_token your-github-tokenThis will create code embeddings, analyze the latest open Merge Request, and post the review comments to the GitHub MR.
-
To review a specific Merge Request:
python main.py --repo_path /path/to/git/repo --repo_owner your-github-username --repo_name your-repo-name --github_token your-github-token --mr_number 123Replace
123with the actual Merge Request number you want to review.
Below is the list of all accepted arguments for main.py:
| Argument | Description | Required | Default |
|---|---|---|---|
--repo_path |
Path to the local Git repository. | Yes | N/A |
--repo_owner |
Owner of the GitHub repository (username or organization). | Yes | N/A |
--repo_name |
Name of the GitHub repository. | Yes | N/A |
--github_token |
GitHub personal access token for authentication. | Yes | N/A |
--db_path |
Path to the Chroma database directory. | No | ./chroma_db |
--mr_number |
Specific Merge Request number to review. If not provided, the latest open MR will be reviewed. | No | None |
--additional_context |
Path to an additional file or directory for embedding context during the review process. | No | None |
To pass these arguments, use the corresponding flags followed by the appropriate values when running main.py.
- Automatically fetches the latest open Merge Request or a specific MR for review.
- Generates code embeddings for the repository using the Llama 3.1 LLM.
- Analyzes the code changes in the context of the relevant parts of the codebase.
- Identifies and reports on various issues, including code quality, potential bugs, performance implications, and integration problems.
- Provides corrective code snippets for each identified issue.
- Posts the review comments directly to the GitHub Merge Request.
- Supports incremental updates to the code embeddings.