This tool automates code reviews for GitLab merge requests and GitHub pull requests using OpenAI's GPT model.
- Supports both GitLab and GitHub repositories
- Generates detailed, line-specific feedback on code changes
- Provides summary reviews
- Can be used as a CLI tool or run as a FastAPI server
- Python 3.7+
- FastAPI
- GitPython
- PyGitHub
- python-gitlab
- OpenAI Python Client
- python-dotenv
- uvicorn (for running the FastAPI server)
-
Clone the repository:
git clone https://github.com/sydowma/codeReviewBot.git cd codeReviewBot
-
Install the required packages:
pip install -r requirements.txt
-
Set up your configuration:
- Create a
config.json
file with your GitLab, GitHub, and OpenAI API credentials. - Alternatively, set up environment variables in a
.env
file.
- Create a
python main.py <url_to_merge_request_or_pull_request> [--summary-only]
-
Start the server:
uvicorn main:app --host 0.0.0.0 --port 8000
-
Send a POST request to
http://localhost:8000/review
with the following JSON body:{ "url": "https://gitlab.com/your-project/merge_requests/1", "summary_only": false }
The tool uses the following configuration options:
GITLAB_URL
: Your GitLab instance URLGITLAB_TOKEN
: Your GitLab personal access tokenGITHUB_TOKEN
: Your GitHub personal access tokenOPENAI_API_KEY
: Your OpenAI API keyOPENAI_HTTP_PROXY
: (Optional) HTTP proxy for OpenAI API calls
You can set these in config.json
or as environment variables.
You can customize the review prompts by modifying the detailed_prompt.txt
and summary_prompt.txt
files.
这个工具使用OpenAI的GPT模型自动化GitLab合并请求和GitHub拉取请求的代码审查。
- 支持GitLab和GitHub仓库
- 生成详细的、针对具体行的代码变更反馈
- 提供摘要审查
- 可以作为CLI工具使用,也可以作为FastAPI服务器运行
- Python 3.7+
- FastAPI
- GitPython
- PyGitHub
- python-gitlab
- OpenAI Python客户端
- python-dotenv
- uvicorn(用于运行FastAPI服务器)
-
克隆仓库:
git clone https://github.com/sydowma/codeReviewBot.git cd codeReviewBot
-
安装所需包:
pip install -r requirements.txt
-
设置配置:
- 创建一个
config.json
文件,包含您的GitLab、GitHub和OpenAI API凭证。 - 或者,在
.env
文件中设置环境变量。
- 创建一个
python main.py <合并请求或拉取请求的url> [--summary-only]
-
启动服务器:
uvicorn main:app --host 0.0.0.0 --port 8000
-
向
http://localhost:8000/review
发送POST请求,JSON体如下:{ "url": "https://gitlab.com/your-project/merge_requests/1", "summary_only": false }
该工具使用以下配置选项:
GITLAB_URL
:您的GitLab实例URLGITLAB_TOKEN
:您的GitLab个人访问令牌GITHUB_TOKEN
:您的GitHub个人访问令牌OPENAI_API_KEY
:您的OpenAI API密钥OPENAI_HTTP_PROXY
:(可选)OpenAI API调用的HTTP代理
您可以在config.json
中设置这些选项,或者作为环境变量设置。
您可以通过修改detailed_prompt.txt
和summary_prompt.txt
文件来自定义审查提示。