feat(ci): 新增AI代码审查Bot(扣子原生API) #426

Merged
xiaoxia merged 9 commits from feature/ai-code-review into develop 2026-07-17 01:24:59 +08:00
Collaborator

变更内容

  1. 新增 scripts/ci_code_review.py - AI代码审查脚本,支持扣子原生Bot API
  2. 新增 .gitea/workflows/code-review.yml - 独立的Code Review workflow

功能

  • PR触发时自动拉取diff,调用扣子Bot进行代码审查
  • 审查结果以评论形式回写到PR
  • continue-on-error,不阻断CI流水线
  • 支持diff截断(默认30000字符),避免超大PR超时

前置依赖

需要在仓库Secrets中配置:

  • GITEA_TOKEN - Gitea访问令牌(用于回写评论)
  • LLM_API_KEY - 扣子SAT token
  • COZE_BOT_ID - 扣子Bot ID
## 变更内容 1. 新增 `scripts/ci_code_review.py` - AI代码审查脚本,支持扣子原生Bot API 2. 新增 `.gitea/workflows/code-review.yml` - 独立的Code Review workflow ## 功能 - PR触发时自动拉取diff,调用扣子Bot进行代码审查 - 审查结果以评论形式回写到PR - continue-on-error,不阻断CI流水线 - 支持diff截断(默认30000字符),避免超大PR超时 ## 前置依赖 需要在仓库Secrets中配置: - `GITEA_TOKEN` - Gitea访问令牌(用于回写评论) - `LLM_API_KEY` - 扣子SAT token - `COZE_BOT_ID` - 扣子Bot ID
auto-approve-bot added 2 commits 2026-07-16 23:14:10 +08:00
feat(ci): add code review workflow
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (pull_request) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 9s
AI Code Review / AI Code Review (pull_request) Failing after 32s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 35s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 54s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m24s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m33s
6b1b2e710e
auto-approve-bot added 1 commit 2026-07-17 00:23:01 +08:00
fix: rename GITEA_TOKEN to GITEA_API_TOKEN to avoid conflict with built-in variable
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 7s
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 32s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 57s
AI Code Review / AI Code Review (pull_request) Failing after 1m45s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m29s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m38s
e1db127123
xiaoxia added 1 commit 2026-07-17 00:29:42 +08:00
fix: rename secret to REVIEW_GITEA_TOKEN (GITEA_ prefix is reserved)
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 8s
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 39s
AI Code Review / AI Code Review (pull_request) Failing after 51s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 1m0s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m31s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m35s
5abc6552f4
xiaoxia added 1 commit 2026-07-17 00:36:24 +08:00
fix: remove setup-python action, use system python3 (not available in runner cache)
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (pull_request) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 11s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 44s
AI Code Review / AI Code Review (pull_request) Successful in 59s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 1m1s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m47s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m55s
aeef4011de
xiaoxia added 1 commit 2026-07-17 00:45:00 +08:00
fix: Coze v3 API异步轮询 - GET方法+query参数,等待answer消息
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (pull_request) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 10s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 47s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 57s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m30s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m35s
AI Code Review / AI Code Review (pull_request) Successful in 3m55s
ac1ae892ac
Author
Collaborator

代码审查结果 - PR #426

⚠️ 问题(3个需要修改)

  1. scripts/ci_code_review.py 第 475-481 行:过滤逻辑未生效,代码中识别了需要跳过的文件(如 .lock, .png)并记录日志,但并未从 diff_text 中实际移除这些文件的内容。后果是 LLM 仍然会消耗 Token 审查这些二进制或非关键文件,甚至可能产生幻觉。
  2. scripts/ci_code_review.py 第 157-166, 580 行:评论去重逻辑未连接。虽然定义了 get_existing_review_comments 函数用于查找旧评论,但在 main 函数中并未调用它。后果是每次 PR 更新都会发布一条新的评论,导致 PR 页面充斥着重复的审查记录,而不是更新旧评论。
  3. scripts/ci_code_review.py 第 518, 533, 544, 609 行:异常处理掩盖错误。代码在多处异常或配置缺失时执行 sys.exit(0)(正常退出),配合 YAML 中的 continue-on-error: true,会导致 CI 任务永远显示绿色(成功)。后果是当配置错误或 API 调用失败时,开发者难以从 CI 状态中发现机器人已失效。建议脚本在遇到错误时应返回非 0 状态码,由 YAML 层面控制是否阻断 CI。

💡 建议(3个可选)

  1. .gitea/workflows/code-review.yml 第 26 行:建议将 actions/checkout@v3 升级到 v4,以获得最新的安全补丁和功能支持。
  2. scripts/ci_code_review.py 第 36 行get_env_or_fail 函数定义后未被使用,建议删除或在 main 函数中复用该逻辑以简化代码。
  3. scripts/ci_code_review.py 第 587 行:判断是否有严重问题的逻辑("问题" in review_result)较为脆弱,如果 LLM 返回“没有发现问题”,该判断也会误判为包含问题。建议结合正则表达式或更严格的格式解析来判断。

格式检查通过 | 逻辑审查需修改 | 性能无明显问题


🤖 由 AI 代码审查机器人自动生成 | 2026-07-17 00:48:54 | 模型:

## 代码审查结果 - PR #426 ### ⚠️ 问题(3个需要修改) 1. **scripts/ci_code_review.py 第 475-481 行**:过滤逻辑未生效,代码中识别了需要跳过的文件(如 .lock, .png)并记录日志,但并未从 `diff_text` 中实际移除这些文件的内容。后果是 LLM 仍然会消耗 Token 审查这些二进制或非关键文件,甚至可能产生幻觉。 2. **scripts/ci_code_review.py 第 157-166, 580 行**:评论去重逻辑未连接。虽然定义了 `get_existing_review_comments` 函数用于查找旧评论,但在 `main` 函数中并未调用它。后果是每次 PR 更新都会发布一条新的评论,导致 PR 页面充斥着重复的审查记录,而不是更新旧评论。 3. **scripts/ci_code_review.py 第 518, 533, 544, 609 行**:异常处理掩盖错误。代码在多处异常或配置缺失时执行 `sys.exit(0)`(正常退出),配合 YAML 中的 `continue-on-error: true`,会导致 CI 任务永远显示绿色(成功)。后果是当配置错误或 API 调用失败时,开发者难以从 CI 状态中发现机器人已失效。建议脚本在遇到错误时应返回非 0 状态码,由 YAML 层面控制是否阻断 CI。 ### 💡 建议(3个可选) 1. **.gitea/workflows/code-review.yml 第 26 行**:建议将 `actions/checkout@v3` 升级到 `v4`,以获得最新的安全补丁和功能支持。 2. **scripts/ci_code_review.py 第 36 行**:`get_env_or_fail` 函数定义后未被使用,建议删除或在 `main` 函数中复用该逻辑以简化代码。 3. **scripts/ci_code_review.py 第 587 行**:判断是否有严重问题的逻辑(`"问题" in review_result`)较为脆弱,如果 LLM 返回“没有发现问题”,该判断也会误判为包含问题。建议结合正则表达式或更严格的格式解析来判断。 --- ✅ 格式检查通过 | ❌ 逻辑审查需修改 | ✅ 性能无明显问题 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-17 00:48:54 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia added 1 commit 2026-07-17 01:01:25 +08:00
fix(ci): 修复AI代码审查3个bug - 过滤生效/评论去重/异常退出码
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (pull_request) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 10s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 50s
AI Code Review / AI Code Review (pull_request) Successful in 58s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 49s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m33s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m27s
cdb68636bf
- Bug1: 过滤逻辑实际从diff中移除跳过的文件(lock/图片等),节省token
- Bug2: 评论去重接上,每次新审查先删除旧的AI评论,避免刷屏
- Bug3: 异常情况sys.exit(1)替代sys.exit(0),配合continue-on-error也能看到失败
xiaoxia added 1 commit 2026-07-17 01:13:20 +08:00
style: black format ci_code_review.py
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (pull_request) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 8s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 36s
AI Code Review / AI Code Review (pull_request) Successful in 51s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 54s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m18s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m23s
d83d0a5d69
xiaoxia added 1 commit 2026-07-17 01:17:46 +08:00
style: isort fix imports
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 8s
CI Build & Deploy Pipeline / Deploy Production (pull_request) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Has been skipped
AI Code Review / AI Code Review (pull_request) Successful in 1m37s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m22s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 3m32s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 4m34s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m35s
d3c8b5f1a2
xiaoxia merged commit b891eced23 into develop 2026-07-17 01:24:59 +08:00
Sign in to join this conversation.