GitMRAI is a work-in-progress hobby project designed to automate the creation of reviews and summaries for GitLab Merge Requests. The goal is to replicate some of the features offered by 'GitLab Duo', but with a completely open-source and free-to-use approach. Note that it is possible there are still some bugs.
At this moment, GitMRAI offers three endpoints that can be triggered by GitLab webhooks on Merge Request push events:
- Summarize the changes in a new comment within the Merge Request:
/api/v1/mr_summarize
- Update the current description of the Merge Request with a summary:
/api/v1/mr_description
- Create a comment on a specific part of the Merge Request diff/changes:
/api/v1/mr_comment_on_diff
- Python 3.10+
- GitLab account with access to the repository or group
- Mistral AI API key
-
Clone the repository:
git clone https://github.com/ethux/GitMRAI.git cd GitMRAI
-
Create a virtual environment and activate it:
python3 -m venv venv source venv/bin/activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up environment variables: Create a
.env
file in the root directory and add the following variables:MODEL=<mistral_ai_model> API_KEY=<mistral_api_key> GITLAB_URL=<gitlab_url> GITLAB_TOKEN=<gitlab_access_token_for_repo_or_group> SECRET_TOKEN=<secret_token_for_api_auth> # This token should be added to the GitLab webhook config as the GitLab secret auth token.
-
Run the application:
uvicorn main:app --host 0.0.0.0 --port 8080
You can also choose to use Docker Compose. This will build and run the application in a Docker container.
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/ethux/GitMRAI.git cd GitMRAI
-
Create a
.env
file in the root directory and add the necessary environment variables:MODEL=<mistral_ai_model> API_KEY=<mistral_api_key> GITLAB_URL=<gitlab_url> GITLAB_TOKEN=<gitlab_access_token_for_repo_or_group> SECRET_TOKEN=<secret_token_for_api_auth> # This token should be added to the GitLab webhook config as the GitLab secret auth token.
-
Build and run the application using Docker Compose:
docker-compose up --build
This will build the Docker image and start the container, exposing the application on port 8080.
- Navigate to your GitLab repository or group settings.
- Go to Webhooks.
- Add a new webhook:
- URL:
http://your-server-ip:8080/api/v1/mr_summarize
(or the respective endpoint) - Secret Token: Use the
SECRET_TOKEN
from your.env
file. - Trigger: Select Merge Request events.
- URL:
Once the webhook is set up, any push event on a Merge Request will trigger the respective endpoint, generating a summary or comment based on the changes.
You can also change the prompts within the JSON files to adjust the summarize style or prompt to your wishes:
system_prompt_summarize.json
- OR
system_prompt.json
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE file for details.