# AI 代码审查服务 这是一个基于 AI 的代码审查服务,支持多种 Git 平台和 AI 服务。 ## 功能特点 - 支持多种 Git 平台:GitLab、Gitea - 支持多种 AI 服务:OpenAI、Ollama - 自动代码审查 - 详细的审查报告 - 可配置的审查规则 - 支持自定义提示词 ## 快速开始 ### 环境要求 - JDK 17+ - Maven 3.8+ - Git 平台(GitLab/Gitea) - AI 服务(OpenAI/Ollama) ### 配置 1. 复制配置文件模板: ```bash cp src/main/resources/application.yml.template src/main/resources/application.yml ``` 2. 编辑配置文件: ```yaml server: port: 53321 logging: level: com.codereview: DEBUG admin: token: your-admin-token ai: services: - type: openai enabled: true api-key: your-openai-api-key model: gpt-3.5-turbo temperature: 0.7 system-msg: 你是一个代码审查助手 - type: ollama enabled: false url: http://localhost:11434 model: codellama temperature: 0.7 system-msg: 你是一个代码审查助手 git: platforms: - name: gitlab type: gitlab api-base: https://gitlab.com/api/v4 token: your-gitlab-token webhook-secret: your-webhook-secret - name: gitea type: gitea api-base: https://gitea.example.com/api/v1 token: your-gitea-token webhook-secret: your-webhook-secret ``` ### 构建 ```bash mvn clean package ``` ### 运行 ```bash java -jar target/ai-code-review.jar ``` ## 使用指南 ### 配置 Git 平台 Webhook 1. GitLab: - 进入项目设置 -> Webhooks - URL: `http://your-server:53321/webhook/gitlab` - Secret Token: 配置文件中设置的 webhook-secret - 触发事件: Push events 2. Gitea: - 进入仓库设置 -> Webhooks - URL: `http://your-server:53321/webhook/gitea` - Secret: 配置文件中设置的 webhook-secret - 触发事件: Push events ### 访问管理界面 - URL: `http://your-server:53321/admin` - 使用配置文件中设置的 admin-token 进行认证 ## 开发指南 ### 项目结构 ``` src/main/java/com/codereview/ ├── config/ # 配置类 ├── controller/ # 控制器 ├── service/ # 服务接口 ├── service/impl/ # 服务实现 └── util/ # 工具类 ``` ### 添加新的 Git 平台支持 1. 创建新的 WebhookEvent 实现类 2. 在 WebhookController 中添加处理逻辑 3. 更新配置文件结构 ### 添加新的 AI 服务支持 1. 创建新的 AIService 实现类 2. 在配置文件中添加服务配置 3. 更新 AIServiceFactory ## 常见问题 1. Webhook 验证失败 - 检查 webhook-secret 配置 - 确认请求头中的签名 2. AI 服务调用失败 - 检查 API 密钥配置 - 确认服务是否可用 - 查看日志获取详细信息 ## 贡献指南 1. Fork 项目 2. 创建特性分支 3. 提交更改 4. 推送到分支 5. 创建 Pull Request ## 许可证 MIT License