From 71edbe9da682c51ba14bbfc871d5bd295cbce7b6 Mon Sep 17 00:00:00 2001 From: DJJ Date: Thu, 4 Dec 2025 21:47:59 +0800 Subject: [PATCH 01/10] doc: format --- .claude/commands/review-commit.md | 4 ++++ .claude/commands/review-pr.md | 1 + 2 files changed, 5 insertions(+) diff --git a/.claude/commands/review-commit.md b/.claude/commands/review-commit.md index 8f4a9b4..56bd35f 100644 --- a/.claude/commands/review-commit.md +++ b/.claude/commands/review-commit.md @@ -28,6 +28,7 @@ git show $SHA ### 步骤 2: 快速分析 检查以下内容: + - commit 信息是否清晰 - 代码变更是否合理 - 是否有明显问题 @@ -47,6 +48,7 @@ EOF ``` **重要**: 必须将摘要写入 `/tmp/review-summary.json`,格式为 JSON: + - `conclusion`: 审查结论 (PASS/WARN/FAIL) - `summary`: 一句话总结(不超过 50 字) @@ -61,9 +63,11 @@ EOF **信息**: {commit message} ### 变更概要 + {变更文件列表} ### 审查结果 + ✅ / ⚠️ / ❌ {简要评价} {如有问题,列出 1-3 个要点} diff --git a/.claude/commands/review-pr.md b/.claude/commands/review-pr.md index f26fad3..361467f 100644 --- a/.claude/commands/review-pr.md +++ b/.claude/commands/review-pr.md @@ -78,6 +78,7 @@ EOF ``` **重要**: 必须在发布评论前将摘要写入 `/tmp/review-summary.json`,格式为 JSON: + - `conclusion`: 审查结论 (APPROVE/REQUEST_CHANGES/COMMENT) - `summary`: 一句话总结(不超过 50 字) - `critical_count`: 严重问题数量 From 455554ed215ba0c21ae7746723d173e3a5dc468b Mon Sep 17 00:00:00 2001 From: DJJ Date: Thu, 4 Dec 2025 21:56:26 +0800 Subject: [PATCH 02/10] add custom github token --- .github/workflows/commit-review.yml | 1 + .github/workflows/pr-review.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/commit-review.yml b/.github/workflows/commit-review.yml index 04f3497..f04f4cf 100644 --- a/.github/workflows/commit-review.yml +++ b/.github/workflows/commit-review.yml @@ -22,6 +22,7 @@ jobs: id: review uses: anthropics/claude-code-action@v1 with: + github_token: ${{ secrets.CUSTOM_GITHUB_TOKEN }} anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} anthropic_base_url: ${{ secrets.ANTHROPIC_BASE_URL }} prompt: | diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml index 3cf0146..88e717f 100644 --- a/.github/workflows/pr-review.yml +++ b/.github/workflows/pr-review.yml @@ -23,6 +23,7 @@ jobs: id: review uses: anthropics/claude-code-action@v1 with: + github_token: ${{ secrets.CUSTOM_GITHUB_TOKEN }} anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} anthropic_base_url: ${{ secrets.ANTHROPIC_BASE_URL }} prompt: | From 11f6be63d1d5c151e4830b16726e74a03a9542d6 Mon Sep 17 00:00:00 2001 From: DJJ Date: Thu, 4 Dec 2025 22:00:14 +0800 Subject: [PATCH 03/10] remote stupid args --- .github/workflows/commit-review.yml | 4 ++-- .github/workflows/pr-review.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/commit-review.yml b/.github/workflows/commit-review.yml index f04f4cf..086f343 100644 --- a/.github/workflows/commit-review.yml +++ b/.github/workflows/commit-review.yml @@ -27,8 +27,8 @@ jobs: anthropic_base_url: ${{ secrets.ANTHROPIC_BASE_URL }} prompt: | /review-commit REPO: ${{ github.repository }} SHA: ${{ github.sha }} BRANCH: ${{ github.ref_name }} - claude_args: | - --allowedTools "Bash(gh *)" "Bash(git *)" "Read" "Glob" "Grep" + # claude_args: | + # --allowedTools "Bash(gh *)" "Bash(git *)" "Read" "Glob" "Grep" - name: Notify Feishu if: always() diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml index 88e717f..520ea76 100644 --- a/.github/workflows/pr-review.yml +++ b/.github/workflows/pr-review.yml @@ -28,8 +28,8 @@ jobs: anthropic_base_url: ${{ secrets.ANTHROPIC_BASE_URL }} prompt: | /review-pr REPO: ${{ github.repository }} PR_NUMBER: ${{ github.event.pull_request.number }} - claude_args: | - --allowedTools "Bash(gh pr *)" "Bash(git *)" "Read" "Glob" "Grep" "Task" "WebFetch" + # claude_args: | + # --allowedTools "Bash(gh pr *)" "Bash(git *)" "Read" "Glob" "Grep" "Task" "WebFetch" - name: Notify Feishu if: always() From f0022d977b1c5802b5254876d920803274caef4f Mon Sep 17 00:00:00 2001 From: DJJ Date: Thu, 4 Dec 2025 22:08:28 +0800 Subject: [PATCH 04/10] use direct_prompt --- .github/workflows/commit-review.yml | 61 ++++++++++++++++++++-- .github/workflows/pr-review.yml | 81 +++++++++++++++++++++++++++-- 2 files changed, 134 insertions(+), 8 deletions(-) diff --git a/.github/workflows/commit-review.yml b/.github/workflows/commit-review.yml index 086f343..5eb66ee 100644 --- a/.github/workflows/commit-review.yml +++ b/.github/workflows/commit-review.yml @@ -25,10 +25,63 @@ jobs: github_token: ${{ secrets.CUSTOM_GITHUB_TOKEN }} anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} anthropic_base_url: ${{ secrets.ANTHROPIC_BASE_URL }} - prompt: | - /review-commit REPO: ${{ github.repository }} SHA: ${{ github.sha }} BRANCH: ${{ github.ref_name }} - # claude_args: | - # --allowedTools "Bash(gh *)" "Bash(git *)" "Read" "Glob" "Grep" + direct_prompt: | + 你是一个代码审查助手。请对最新的 commit 进行简单审查。 + + ## 审查信息 + - 仓库: ${{ github.repository }} + - 分支: ${{ github.ref_name }} + - Commit SHA: ${{ github.sha }} + + ## 审查步骤 + + ### 1. 获取 Commit 信息 + 执行以下命令: + ```bash + git show --stat ${{ github.sha }} + git show ${{ github.sha }} + ``` + + ### 2. 快速分析 + 检查: + - commit 信息是否清晰 + - 代码变更是否合理 + - 是否有明显问题 + + ### 3. 保存审查摘要 + 将结果写入文件(用于飞书通知): + ```bash + cat > /tmp/review-summary.json << 'EOF' + { + "conclusion": "PASS 或 WARN 或 FAIL", + "summary": "一句话总结(不超过50字)" + } + EOF + ``` + 请根据实际审查结果填写。 + + ## 输出格式(简体中文) + + 直接输出简要报告: + ``` + ## 📝 Commit 审查 - ${{ github.ref_name }} + + **Commit**: {short_sha} + **信息**: {commit message} + + ### 变更概要 + {变更文件列表} + + ### 审查结果 + ✅/⚠️/❌ {简要评价} + + {如有问题,列出1-3个要点} + ``` + + ## 注意事项 + 1. 保持简洁 + 2. 只关注明显问题 + 3. 使用简体中文 - name: Notify Feishu if: always() diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml index 520ea76..71cc07e 100644 --- a/.github/workflows/pr-review.yml +++ b/.github/workflows/pr-review.yml @@ -26,10 +26,83 @@ jobs: github_token: ${{ secrets.CUSTOM_GITHUB_TOKEN }} anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} anthropic_base_url: ${{ secrets.ANTHROPIC_BASE_URL }} - prompt: | - /review-pr REPO: ${{ github.repository }} PR_NUMBER: ${{ github.event.pull_request.number }} - # claude_args: | - # --allowedTools "Bash(gh pr *)" "Bash(git *)" "Read" "Glob" "Grep" "Task" "WebFetch" + direct_prompt: | + 你是一个专业的代码审查助手。请对 PR #${{ github.event.pull_request.number }} 进行全面审查。 + + ## 审查信息 + - 仓库: ${{ github.repository }} + - PR 编号: ${{ github.event.pull_request.number }} + - PR 标题: ${{ github.event.pull_request.title }} + + ## 审查步骤 + + ### 1. 获取 PR 信息 + 执行以下命令获取 PR 详情和代码变更: + ```bash + gh pr view ${{ github.event.pull_request.number }} --json number,title,body,author,baseRefName,headRefName,files,additions,deletions,changedFiles + gh pr diff ${{ github.event.pull_request.number }} + ``` + + ### 2. 分析代码 + 审查以下维度: + + **代码质量**:代码风格、复杂度、重复代码、命名规范、错误处理、潜在 bug + + **架构设计**:项目结构一致性、依赖合理性、设计模式、关注点分离 + + ### 3. 保存审查摘要 + 将审查结果写入文件(用于飞书通知): + ```bash + cat > /tmp/review-summary.json << 'EOF' + { + "conclusion": "APPROVE 或 REQUEST_CHANGES 或 COMMENT", + "summary": "一句话总结(不超过50字)", + "critical_count": 0, + "important_count": 0, + "suggestion_count": 0 + } + EOF + ``` + 请根据实际审查结果填写 JSON 内容。 + + ### 4. 发布审查评论 + 使用以下格式发布评论: + ```bash + gh pr review ${{ github.event.pull_request.number }} --comment --body "评论内容" + ``` + + ## 输出格式(简体中文) + + ```markdown + ## 🔍 PR 代码审查报告 + + ### 📋 概要 + - **PR 标题**: {title} + - **作者**: {author} + - **变更文件数**: {changedFiles} + - **新增/删除行数**: +{additions} / -{deletions} + + ### 🎯 审查结论 + {APPROVE/REQUEST_CHANGES/COMMENT 及简要说明} + + ### 🔴 严重问题 (Critical) + {严重问题列表,如无则显示"无"} + + ### 🟠 重要问题 (Important) + {重要问题列表,如无则显示"无"} + + ### 🟢 改进建议 (Suggestions) + {改进建议列表,如无则显示"无"} + + ### 💡 总体评价 + {对本次 PR 的整体评价} + ``` + + ## 注意事项 + 1. 所有评论使用简体中文 + 2. 给出具体的文件名和行号 + 3. 对好的实践也要给予肯定 + 4. 保持客观、专业 - name: Notify Feishu if: always() From 61d69b1603cb89588f10bd6ba92ec6d8cda37221 Mon Sep 17 00:00:00 2001 From: DJJ Date: Thu, 4 Dec 2025 22:10:03 +0800 Subject: [PATCH 05/10] fuck, use prompt --- .github/workflows/commit-review.yml | 2 +- .github/workflows/pr-review.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/commit-review.yml b/.github/workflows/commit-review.yml index 5eb66ee..cb4bb9a 100644 --- a/.github/workflows/commit-review.yml +++ b/.github/workflows/commit-review.yml @@ -25,7 +25,7 @@ jobs: github_token: ${{ secrets.CUSTOM_GITHUB_TOKEN }} anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} anthropic_base_url: ${{ secrets.ANTHROPIC_BASE_URL }} - direct_prompt: | + prompt: | 你是一个代码审查助手。请对最新的 commit 进行简单审查。 ## 审查信息 diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml index 71cc07e..e094f4c 100644 --- a/.github/workflows/pr-review.yml +++ b/.github/workflows/pr-review.yml @@ -26,7 +26,7 @@ jobs: github_token: ${{ secrets.CUSTOM_GITHUB_TOKEN }} anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} anthropic_base_url: ${{ secrets.ANTHROPIC_BASE_URL }} - direct_prompt: | + prompt: | 你是一个专业的代码审查助手。请对 PR #${{ github.event.pull_request.number }} 进行全面审查。 ## 审查信息 From b34ff47c2289fad774d05dc583b70fde44678e58 Mon Sep 17 00:00:00 2001 From: DJJ Date: Thu, 4 Dec 2025 22:19:05 +0800 Subject: [PATCH 06/10] remove commands --- .claude/commands/review-commit.md | 80 ---------------- .claude/commands/review-pr.md | 137 ---------------------------- .github/workflows/commit-review.yml | 42 ++------- .github/workflows/pr-review.yml | 67 ++++---------- 4 files changed, 26 insertions(+), 300 deletions(-) delete mode 100644 .claude/commands/review-commit.md delete mode 100644 .claude/commands/review-pr.md diff --git a/.claude/commands/review-commit.md b/.claude/commands/review-commit.md deleted file mode 100644 index 56bd35f..0000000 --- a/.claude/commands/review-commit.md +++ /dev/null @@ -1,80 +0,0 @@ ---- -description: "简单审查分支的最新 commit" -argument-hint: "[REPO: owner/repo SHA: commit_sha BRANCH: branch_name]" ---- - -# /review-commit - -对分支的最新 commit 进行简单审查。 - -## 输入参数 - -- `REPO`: 仓库名称 -- `SHA`: Commit SHA -- `BRANCH`: 分支名称 - -## 审查流程 - -### 步骤 1: 获取 Commit 信息 - -```bash -# 获取 commit 详情 -git show --stat $SHA - -# 获取 commit diff -git show $SHA -``` - -### 步骤 2: 快速分析 - -检查以下内容: - -- commit 信息是否清晰 -- 代码变更是否合理 -- 是否有明显问题 - -### 步骤 3: 保存审查摘要 - -将审查摘要写入文件供通知使用: - -```bash -# 写入摘要到文件(用于飞书通知) -cat > /tmp/review-summary.json << 'EOF' -{ - "conclusion": "PASS 或 WARN 或 FAIL", - "summary": "一句话总结审查结果" -} -EOF -``` - -**重要**: 必须将摘要写入 `/tmp/review-summary.json`,格式为 JSON: - -- `conclusion`: 审查结论 (PASS/WARN/FAIL) -- `summary`: 一句话总结(不超过 50 字) - -### 步骤 4: 输出简要报告 - -## 输出格式 - -```markdown -## 📝 Commit 审查 - {BRANCH} - -**Commit**: `{SHA}` -**信息**: {commit message} - -### 变更概要 - -{变更文件列表} - -### 审查结果 - -✅ / ⚠️ / ❌ {简要评价} - -{如有问题,列出 1-3 个要点} -``` - -## 注意事项 - -1. 保持简洁,不需要详细分析 -2. 只关注明显问题 -3. 使用简体中文 diff --git a/.claude/commands/review-pr.md b/.claude/commands/review-pr.md deleted file mode 100644 index 361467f..0000000 --- a/.claude/commands/review-pr.md +++ /dev/null @@ -1,137 +0,0 @@ ---- -description: "对 GitHub Pull Request 进行自动化代码审查" -argument-hint: "[REPO: owner/repo PR_NUMBER: number]" ---- - -# /review-pr - -对 GitHub Pull Request 进行全面的自动化代码审查,包括代码质量和架构设计分析。 - -## 输入参数 - -- `REPO`: 仓库名称,格式为 `owner/repo` -- `PR_NUMBER`: Pull Request 编号 - -## 审查流程 - -### 步骤 1: 获取 PR 信息 - -首先获取 PR 的详细信息和代码变更: - -```bash -# 获取 PR 详情 -gh pr view $PR_NUMBER --repo $REPO --json number,title,body,author,baseRefName,headRefName,files,additions,deletions,changedFiles - -# 获取代码变更 -gh pr diff $PR_NUMBER --repo $REPO -``` - -### 步骤 2: 并行分析 - -使用 subagent 并行分析以下维度: - -#### 分析 A - 代码质量 - -分析代码变更中的: - -- 代码风格一致性 -- 代码复杂度 -- 重复代码 -- 命名规范 -- 错误处理 -- 潜在的 bug 或安全问题 - -#### 分析 B - 架构设计 - -分析代码变更中的: - -- 与项目现有结构的一致性 -- 新增依赖的合理性 -- 设计模式的使用 -- 关注点分离 -- 模块化程度 -- API 设计合理性 - -### 步骤 3: 生成审查报告 - -将分析结果整合为结构化的审查报告,按严重程度分类: - -- **严重 (Critical)**: 必须修复的问题,如安全漏洞、严重 bug -- **重要 (Important)**: 建议修复的问题,如设计缺陷、性能问题 -- **建议 (Suggestion)**: 可选的改进建议,如代码风格优化 - -### 步骤 4: 保存审查摘要 - -将审查摘要写入文件供通知使用: - -```bash -# 写入摘要到文件(用于飞书通知) -cat > /tmp/review-summary.json << 'EOF' -{ - "conclusion": "APPROVE 或 REQUEST_CHANGES 或 COMMENT", - "summary": "一句话总结审查结果", - "critical_count": 0, - "important_count": 0, - "suggestion_count": 0 -} -EOF -``` - -**重要**: 必须在发布评论前将摘要写入 `/tmp/review-summary.json`,格式为 JSON: - -- `conclusion`: 审查结论 (APPROVE/REQUEST_CHANGES/COMMENT) -- `summary`: 一句话总结(不超过 50 字) -- `critical_count`: 严重问题数量 -- `important_count`: 重要问题数量 -- `suggestion_count`: 建议数量 - -### 步骤 5: 发布审查评论 - -使用以下命令发布审查评论: - -```bash -gh pr review $PR_NUMBER --repo $REPO --comment --body "审查内容" -``` - -## 输出格式 - -审查评论采用以下 Markdown 格式(简体中文): - -```markdown -## 🔍 PR 代码审查报告 - -### 📋 概要 - -- **PR 标题**: {title} -- **作者**: {author} -- **变更文件数**: {changedFiles} -- **新增/删除行数**: +{additions} / -{deletions} - -### 🎯 审查结论 - -{APPROVE/REQUEST_CHANGES/COMMENT 及简要说明} - -### 🔴 严重问题 (Critical) - -{严重问题列表,如无则显示"无"} - -### 🟠 重要问题 (Important) - -{重要问题列表,如无则显示"无"} - -### 🟢 改进建议 (Suggestions) - -{改进建议列表,如无则显示"无"} - -### 💡 总体评价 - -{对本次 PR 的整体评价和建议} -``` - -## 注意事项 - -1. 所有评论使用简体中文 -2. 关注代码质量和架构设计两个维度 -3. 给出具体的代码行号和改进建议 -4. 对于好的实践也要给予肯定 -5. 保持客观、专业的审查态度 diff --git a/.github/workflows/commit-review.yml b/.github/workflows/commit-review.yml index cb4bb9a..b5b4f83 100644 --- a/.github/workflows/commit-review.yml +++ b/.github/workflows/commit-review.yml @@ -35,35 +35,11 @@ jobs: ## 审查步骤 - ### 1. 获取 Commit 信息 - 执行以下命令: - ```bash - git show --stat ${{ github.sha }} - git show ${{ github.sha }} - ``` - - ### 2. 快速分析 - 检查: - - commit 信息是否清晰 - - 代码变更是否合理 - - 是否有明显问题 - - ### 3. 保存审查摘要 - 将结果写入文件(用于飞书通知): - ```bash - cat > /tmp/review-summary.json << 'EOF' - { - "conclusion": "PASS 或 WARN 或 FAIL", - "summary": "一句话总结(不超过50字)" - } - EOF - ``` - 请根据实际审查结果填写。 + 1. 使用 git show 查看 commit 详情和变更 + 2. 检查 commit 信息是否清晰、代码变更是否合理、是否有明显问题 ## 输出格式(简体中文) - 直接输出简要报告: - ``` ## 📝 Commit 审查 - ${{ github.ref_name }} **Commit**: {short_sha} @@ -76,12 +52,13 @@ jobs: ✅/⚠️/❌ {简要评价} {如有问题,列出1-3个要点} - ``` ## 注意事项 1. 保持简洁 2. 只关注明显问题 3. 使用简体中文 + claude_args: | + --json-schema '{"type":"object","properties":{"conclusion":{"type":"string","enum":["PASS","WARN","FAIL"]},"summary":{"type":"string","maxLength":50}},"required":["conclusion","summary"]}' - name: Notify Feishu if: always() @@ -90,13 +67,14 @@ jobs: SHORT_SHA="${{ github.sha }}" SHORT_SHA="${SHORT_SHA:0:7}" - # 读取审查摘要 - if [ -f /tmp/review-summary.json ]; then - CONCLUSION=$(jq -r '.conclusion // "UNKNOWN"' /tmp/review-summary.json) - SUMMARY=$(jq -r '.summary // "审查完成"' /tmp/review-summary.json) + # 解析结构化输出 + STRUCTURED_OUTPUT='${{ steps.review.outputs.structured_output }}' + if [ -n "$STRUCTURED_OUTPUT" ] && [ "$STRUCTURED_OUTPUT" != "null" ]; then + CONCLUSION=$(echo "$STRUCTURED_OUTPUT" | jq -r '.conclusion // "UNKNOWN"') + SUMMARY=$(echo "$STRUCTURED_OUTPUT" | jq -r '.summary // "审查完成"') else CONCLUSION="UNKNOWN" - SUMMARY="未获取到审查摘要" + SUMMARY="未获取到审查结果" fi # 根据结论设置样式 diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml index e094f4c..6ee68f2 100644 --- a/.github/workflows/pr-review.yml +++ b/.github/workflows/pr-review.yml @@ -7,7 +7,6 @@ on: jobs: review: runs-on: ubuntu-latest - # 跳过 draft PR if: github.event.pull_request.draft == false permissions: contents: read @@ -26,59 +25,23 @@ jobs: github_token: ${{ secrets.CUSTOM_GITHUB_TOKEN }} anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} anthropic_base_url: ${{ secrets.ANTHROPIC_BASE_URL }} + use_sticky_comment: true prompt: | - 你是一个专业的代码审查助手。请对 PR #${{ github.event.pull_request.number }} 进行全面审查。 + 你是一个专业的代码审查助手。请对当前 PR 进行全面审查。 - ## 审查信息 - - 仓库: ${{ github.repository }} - - PR 编号: ${{ github.event.pull_request.number }} - - PR 标题: ${{ github.event.pull_request.title }} - - ## 审查步骤 - - ### 1. 获取 PR 信息 - 执行以下命令获取 PR 详情和代码变更: - ```bash - gh pr view ${{ github.event.pull_request.number }} --json number,title,body,author,baseRefName,headRefName,files,additions,deletions,changedFiles - gh pr diff ${{ github.event.pull_request.number }} - ``` - - ### 2. 分析代码 - 审查以下维度: + ## 审查维度 **代码质量**:代码风格、复杂度、重复代码、命名规范、错误处理、潜在 bug **架构设计**:项目结构一致性、依赖合理性、设计模式、关注点分离 - ### 3. 保存审查摘要 - 将审查结果写入文件(用于飞书通知): - ```bash - cat > /tmp/review-summary.json << 'EOF' - { - "conclusion": "APPROVE 或 REQUEST_CHANGES 或 COMMENT", - "summary": "一句话总结(不超过50字)", - "critical_count": 0, - "important_count": 0, - "suggestion_count": 0 - } - EOF - ``` - 请根据实际审查结果填写 JSON 内容。 - - ### 4. 发布审查评论 - 使用以下格式发布评论: - ```bash - gh pr review ${{ github.event.pull_request.number }} --comment --body "评论内容" - ``` - ## 输出格式(简体中文) - ```markdown + 请按以下格式输出审查报告: + ## 🔍 PR 代码审查报告 ### 📋 概要 - - **PR 标题**: {title} - - **作者**: {author} - **变更文件数**: {changedFiles} - **新增/删除行数**: +{additions} / -{deletions} @@ -96,29 +59,31 @@ jobs: ### 💡 总体评价 {对本次 PR 的整体评价} - ``` ## 注意事项 1. 所有评论使用简体中文 2. 给出具体的文件名和行号 3. 对好的实践也要给予肯定 4. 保持客观、专业 + claude_args: | + --json-schema '{"type":"object","properties":{"conclusion":{"type":"string","enum":["APPROVE","REQUEST_CHANGES","COMMENT"]},"summary":{"type":"string","maxLength":50},"critical_count":{"type":"integer"},"important_count":{"type":"integer"},"suggestion_count":{"type":"integer"}},"required":["conclusion","summary","critical_count","important_count","suggestion_count"]}' - name: Notify Feishu if: always() run: | STATUS="${{ job.status }}" - # 读取审查摘要 - if [ -f /tmp/review-summary.json ]; then - CONCLUSION=$(jq -r '.conclusion // "UNKNOWN"' /tmp/review-summary.json) - SUMMARY=$(jq -r '.summary // "审查完成"' /tmp/review-summary.json) - CRITICAL=$(jq -r '.critical_count // 0' /tmp/review-summary.json) - IMPORTANT=$(jq -r '.important_count // 0' /tmp/review-summary.json) - SUGGESTION=$(jq -r '.suggestion_count // 0' /tmp/review-summary.json) + # 解析结构化输出 + STRUCTURED_OUTPUT='${{ steps.review.outputs.structured_output }}' + if [ -n "$STRUCTURED_OUTPUT" ] && [ "$STRUCTURED_OUTPUT" != "null" ]; then + CONCLUSION=$(echo "$STRUCTURED_OUTPUT" | jq -r '.conclusion // "UNKNOWN"') + SUMMARY=$(echo "$STRUCTURED_OUTPUT" | jq -r '.summary // "审查完成"') + CRITICAL=$(echo "$STRUCTURED_OUTPUT" | jq -r '.critical_count // 0') + IMPORTANT=$(echo "$STRUCTURED_OUTPUT" | jq -r '.important_count // 0') + SUGGESTION=$(echo "$STRUCTURED_OUTPUT" | jq -r '.suggestion_count // 0') else CONCLUSION="UNKNOWN" - SUMMARY="未获取到审查摘要" + SUMMARY="未获取到审查结果" CRITICAL=0 IMPORTANT=0 SUGGESTION=0 From 5e177410d42b344cb60dbef8c46e128880247116 Mon Sep 17 00:00:00 2001 From: DJJ Date: Thu, 4 Dec 2025 22:21:11 +0800 Subject: [PATCH 07/10] why? --- .github/workflows/pr-review.yml | 1 + README.md | 40 +++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml index 6ee68f2..126d69e 100644 --- a/.github/workflows/pr-review.yml +++ b/.github/workflows/pr-review.yml @@ -26,6 +26,7 @@ jobs: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} anthropic_base_url: ${{ secrets.ANTHROPIC_BASE_URL }} use_sticky_comment: true + show_full_output: true prompt: | 你是一个专业的代码审查助手。请对当前 PR 进行全面审查。 diff --git a/README.md b/README.md index bfddb2e..a50edf9 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ | Commit Review | v* 分支 push 时自动审查最新 commit | | 飞书通知 | 审查完成后发送卡片消息到飞书群 | | 中文输出 | 所有审查报告和通知使用简体中文 | +| Sticky Comment | PR 多次审查会更新同一条评论 | ## 快速开始 @@ -21,10 +22,6 @@ .github/workflows/ ├── pr-review.yml # PR 审查工作流 └── commit-review.yml # Commit 审查工作流 - -.claude/commands/ -├── review-pr.md # PR 审查命令 -└── review-commit.md # Commit 审查命令 ``` ### 2. 配置 GitHub Secrets @@ -35,6 +32,7 @@ |------------|:----:|------| | `ANTHROPIC_API_KEY` | ✅ | Anthropic API 密钥 | | `ANTHROPIC_BASE_URL` | ❌ | API 基础 URL(使用代理时需要) | +| `CUSTOM_GITHUB_TOKEN` | ❌ | 自定义 GitHub Token(默认使用 GITHUB_TOKEN) | | `FEISHU_WEBHOOK_TOKEN` | ✅ | 飞书机器人 Webhook Token | ### 3. 获取飞书 Webhook Token @@ -102,8 +100,6 @@ ## 🔍 PR 代码审查报告 ### 📋 概要 -- **PR 标题**: feat: 添加用户认证模块 -- **作者**: developer - **变更文件数**: 5 - **新增/删除行数**: +120 / -15 @@ -195,9 +191,27 @@ on: - 'main' # 添加 main 分支 ``` -### 修改审查维度 +### 修改审查 Prompt + +编辑 workflow 文件中的 `prompt` 字段: + +```yaml +- name: PR Review with Claude + uses: anthropics/claude-code-action@v1 + with: + prompt: | + 你是一个专业的代码审查助手... + # 自定义审查要求 +``` + +### 修改结构化输出 -编辑 `.claude/commands/review-pr.md` 或 `review-commit.md` 中的审查流程。 +编辑 `claude_args` 中的 `--json-schema`: + +```yaml +claude_args: | + --json-schema '{"type":"object","properties":{...}}' +``` ## 文件结构 @@ -207,13 +221,15 @@ on: │ └── workflows/ │ ├── pr-review.yml # PR 审查工作流 │ └── commit-review.yml # Commit 审查工作流 -├── .claude/ -│ └── commands/ -│ ├── review-pr.md # PR 审查命令定义 -│ └── review-commit.md # Commit 审查命令定义 └── README.md ``` +## 技术说明 + +- 使用 [claude-code-action](https://github.com/anthropics/claude-code-action) v1 +- 通过 `--json-schema` 获取结构化输出用于飞书通知 +- PR Review 使用 `use_sticky_comment` 合并多次评论 + ## License MIT From eb11e327c1b14dcfba3509cc7e778c32f2fafc3d Mon Sep 17 00:00:00 2001 From: DJJ Date: Thu, 4 Dec 2025 22:27:12 +0800 Subject: [PATCH 08/10] base_url --- .github/workflows/commit-review.yml | 3 ++- .github/workflows/pr-review.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/commit-review.yml b/.github/workflows/commit-review.yml index b5b4f83..335b9c4 100644 --- a/.github/workflows/commit-review.yml +++ b/.github/workflows/commit-review.yml @@ -21,10 +21,11 @@ jobs: - name: Review Commits with Claude id: review uses: anthropics/claude-code-action@v1 + env: + ANTHROPIC_BASE_URL: ${{ secrets.ANTHROPIC_BASE_URL }} with: github_token: ${{ secrets.CUSTOM_GITHUB_TOKEN }} anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} - anthropic_base_url: ${{ secrets.ANTHROPIC_BASE_URL }} prompt: | 你是一个代码审查助手。请对最新的 commit 进行简单审查。 diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml index 126d69e..1741601 100644 --- a/.github/workflows/pr-review.yml +++ b/.github/workflows/pr-review.yml @@ -21,10 +21,11 @@ jobs: - name: PR Review with Claude id: review uses: anthropics/claude-code-action@v1 + env: + ANTHROPIC_BASE_URL: ${{ secrets.ANTHROPIC_BASE_URL }} with: github_token: ${{ secrets.CUSTOM_GITHUB_TOKEN }} anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} - anthropic_base_url: ${{ secrets.ANTHROPIC_BASE_URL }} use_sticky_comment: true show_full_output: true prompt: | From 74b212e8f6d8aa3e46c879534f2e28a31452c187 Mon Sep 17 00:00:00 2001 From: DJJ Date: Thu, 4 Dec 2025 22:36:34 +0800 Subject: [PATCH 09/10] add allowed tools --- .github/workflows/commit-review.yml | 2 +- .github/workflows/pr-review.yml | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/commit-review.yml b/.github/workflows/commit-review.yml index 335b9c4..7fb9962 100644 --- a/.github/workflows/commit-review.yml +++ b/.github/workflows/commit-review.yml @@ -59,7 +59,7 @@ jobs: 2. 只关注明显问题 3. 使用简体中文 claude_args: | - --json-schema '{"type":"object","properties":{"conclusion":{"type":"string","enum":["PASS","WARN","FAIL"]},"summary":{"type":"string","maxLength":50}},"required":["conclusion","summary"]}' + --allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)" --json-schema '{"type":"object","properties":{"conclusion":{"type":"string","enum":["PASS","WARN","FAIL"]},"summary":{"type":"string","maxLength":50}},"required":["conclusion","summary"]}' - name: Notify Feishu if: always() diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml index 1741601..36307a5 100644 --- a/.github/workflows/pr-review.yml +++ b/.github/workflows/pr-review.yml @@ -29,7 +29,12 @@ jobs: use_sticky_comment: true show_full_output: true prompt: | - 你是一个专业的代码审查助手。请对当前 PR 进行全面审查。 + 你是一个专业的代码审查助手。请对当前 PR 进行全面审查. + + 总是使用 `gh` 命令在github上评论PR, 尽可能的使用一条评论, 不断的更新. + 使用 `mcp__github_inline_comment__create_inline_comment` to highlight specific code issues. + + 但是注意, 这个PR可能存在多个comment , 不提出重复的问题 ## 审查维度 @@ -68,8 +73,7 @@ jobs: 3. 对好的实践也要给予肯定 4. 保持客观、专业 claude_args: | - --json-schema '{"type":"object","properties":{"conclusion":{"type":"string","enum":["APPROVE","REQUEST_CHANGES","COMMENT"]},"summary":{"type":"string","maxLength":50},"critical_count":{"type":"integer"},"important_count":{"type":"integer"},"suggestion_count":{"type":"integer"}},"required":["conclusion","summary","critical_count","important_count","suggestion_count"]}' - + --allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)" --json-schema '{"type":"object","properties":{"conclusion":{"type":"string","enum":["APPROVE","REQUEST_CHANGES","COMMENT"]},"summary":{"type":"string","maxLength":50},"critical_count":{"type":"integer"},"important_count":{"type":"integer"},"suggestion_count":{"type":"integer"}},"required":["conclusion","summary","critical_count","important_count","suggestion_count"]}' - name: Notify Feishu if: always() run: | From 0ebb0b1ccf20794060ec6dc423d1e645d288da2b Mon Sep 17 00:00:00 2001 From: DJJ Date: Thu, 4 Dec 2025 22:52:46 +0800 Subject: [PATCH 10/10] add note --- .github/workflows/pr-review.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml index 36307a5..a648d9e 100644 --- a/.github/workflows/pr-review.yml +++ b/.github/workflows/pr-review.yml @@ -29,13 +29,8 @@ jobs: use_sticky_comment: true show_full_output: true prompt: | - 你是一个专业的代码审查助手。请对当前 PR 进行全面审查. - - 总是使用 `gh` 命令在github上评论PR, 尽可能的使用一条评论, 不断的更新. - 使用 `mcp__github_inline_comment__create_inline_comment` to highlight specific code issues. + 请对当前 PR 进行全面审查. - 但是注意, 这个PR可能存在多个comment , 不提出重复的问题 - ## 审查维度 **代码质量**:代码风格、复杂度、重复代码、命名规范、错误处理、潜在 bug @@ -44,7 +39,7 @@ jobs: ## 输出格式(简体中文) - 请按以下格式输出审查报告: + 请按以下格式输出审查报告, 作为: ## 🔍 PR 代码审查报告 @@ -72,6 +67,14 @@ jobs: 2. 给出具体的文件名和行号 3. 对好的实践也要给予肯定 4. 保持客观、专业 + + Note: The PR branch is already checked out in the current working directory. + + Use `gh pr comment` for top-level feedback. + Use `mcp__github_inline_comment__create_inline_comment` to highlight specific code issues. + Only post GitHub comments - don't submit review text as messages. + + ALWAYS Answer in 简体中文. claude_args: | --allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)" --json-schema '{"type":"object","properties":{"conclusion":{"type":"string","enum":["APPROVE","REQUEST_CHANGES","COMMENT"]},"summary":{"type":"string","maxLength":50},"critical_count":{"type":"integer"},"important_count":{"type":"integer"},"suggestion_count":{"type":"integer"}},"required":["conclusion","summary","critical_count","important_count","suggestion_count"]}' - name: Notify Feishu