Dify GitLab MR Reviewer is a tool designed to automate the code review process for GitLab Merge Requests (MRs). It integrates with the Dify workflow to provide intelligent code review suggestions, helping developers identify potential issues and improve code quality.
- Automated Code Review: Automatically reviews GitLab MRs and provides feedback.
- Code Review email for push: Send email to the pusher when commits are pushed.
- Integration with Dify: Utilizes the Dify workflow for advanced code analysis.
- Docker Trigger Support: Easy deployment using Docker containers to trigger the workflow.
- Logging and Monitoring: Detailed logging and monitoring to ensure robust operation.
Before you begin, ensure you have the following installed:
- GitLab (Version 17 or newer) This reviewer can be applied to free GitLab instance. You need a personal access token to an account with access (Role
developer
at least) to the repository. - Dify The AI workflow platform. You have to get the workflow URL and access token.
- Docker To proxy the GitLab system hook requests to Dify
Please note the token must have the api
scope. This GitLab account will post comments when reviewing MRs. So please remember the GitLab account name.
The token will be used as GITLAB_PRIVATE_TOKEN
and the account name will be used as GITLAB_REVIEWER_USERNAME
.
Select the file dify-workflow-zh.yml
to import. Or you can import the English version dify-workflow-en.yml
.
Then adjust your workflow environment variables.
Sample:
GITLAB_HOST = https://gitlab.your-company.com
GITLAB_PRIVATE_TOKEN = <The token you retrived from the first step>
GITLAB_REVIEWER_USERNAME = <The GitLab account name you retrived from the first step>
The workflow is default using the Google Gemini 2.0 Flash Exp. You can change to any other LLM model.
This is for autommatically trigger the workflow.
Get the workflow URL, it will be refered as DIFY_URL
in following steps. It looks like:
https://your-dify-host/v1/workflows/run
And the API key from the workflow page, it will be refered as DIFY_API_KEY
in follwoing steps:
You will need the URL and API key to trigger the workflow.
Build the docker image:
cd trigger
docker build -t gitlab-mr-reviewer .
Run the docker container. The host should be accessible from the GitLab server.
docker run --name ai-code-review-trigger -d --restart always -p 4195:4195 -v $(pwd)/logs:/var/log/supervisor/ gitlab-mr-reviewer
Your GitLab server should be able to access this 4195 port. For example http://localhost:4195
.
Go to your GitLab admin area, navigate to System hooks > Add new webhook
.
Fill up the URL as http://localhost:4195/hook?dify=<DIFY_URL>
Fill up the Secret token as <DIFY_API_KEY>
(it will be masked as ***)
Triggers should be Push events
and Merge request events
only.
Then click Add webhook
to save the settings.
That's all settings. You can try to create a new merge request, or push your commits, then let's see what the AI would say!
Q: Why I don't receive the code review email?
A: You have to go to your GitLab account settings, the profile page, and enable the Public Email
option.
Contributions are welcome! Please read the contributing guidelines to get started.
This project is licensed under the MIT License. See the LICENSE file for details.