Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 0 additions & 76 deletions .claude/commands/review-commit.md

This file was deleted.

136 changes: 0 additions & 136 deletions .claude/commands/review-pr.md

This file was deleted.

49 changes: 41 additions & 8 deletions .github/workflows/commit-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,45 @@ jobs:
- name: Review Commits with Claude
id: review
uses: anthropics/claude-code-action@v1
env:
ANTHROPIC_BASE_URL: ${{ secrets.ANTHROPIC_BASE_URL }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 环境变量传递方式变更

与 PR review workflow 相同的问题,需要确认 claude-code-action@v1 是否支持通过 env.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: |
/review-commit REPO: ${{ github.repository }} SHA: ${{ github.sha }} BRANCH: ${{ github.ref_name }}
你是一个代码审查助手。请对最新的 commit 进行简单审查。

## 审查信息
- 仓库: ${{ github.repository }}
- 分支: ${{ github.ref_name }}
- Commit SHA: ${{ github.sha }}

## 审查步骤

1. 使用 git show 查看 commit 详情和变更
2. 检查 commit 信息是否清晰、代码变更是否合理、是否有明显问题

## 输出格式(简体中文)

## 📝 Commit 审查 - ${{ github.ref_name }}

**Commit**: {short_sha}
**信息**: {commit message}

### 变更概要
{变更文件列表}

### 审查结果
✅/⚠️/❌ {简要评价}

{如有问题,列出1-3个要点}

## 注意事项
1. 保持简洁
2. 只关注明显问题
3. 使用简体中文
claude_args: |
--allowedTools "Bash(gh *)" "Bash(git *)" "Read" "Glob" "Grep"
--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"]}'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

相同的可读性问题:

pr-review.yml:76 相同的问题,建议采用相同的格式优化方案。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

配置不一致问题:

Commit Review 的 allowedTools 配置与 PR Review 完全相同,但 Commit Review 不需要创建 PR 评论。

当前工具包括:

  • mcp__github_inline_comment__create_inline_comment - 用于 PR inline 评论
  • Bash(gh pr comment:*), Bash(gh pr diff:*), Bash(gh pr view:*) - 都是 PR 相关命令

建议: Commit Review 应该使用不同的工具集,移除 PR 相关工具,可能需要添加 Bash(git *) 等 git 命令支持。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ 工具权限配置错误

Commit Review 不涉及 PR 操作,但配置中包含了 PR 相关的工具:

  • mcp__github_inline_comment__create_inline_comment - 用于 PR inline comment
  • Bash(gh pr comment:*) - PR 评论命令
  • Bash(gh pr diff:*) - PR diff 命令
  • Bash(gh pr view:*) - PR 查看命令

建议修改为:

--allowedTools "Bash(git show:*),Bash(git diff:*),Bash(git log:*),Read,Glob,Grep"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 重要问题:allowedTools 配置不匹配实际需求

Commit Review 工作流使用了 mcp__github_inline_comment__create_inline_comment 工具,但这个工具主要用于 PR 的代码评论,不适用于 commit 审查场景。

建议修改为:

--allowedTools "Bash(git *)"

Commit Review 只需要 Git 操作工具即可完成审查任务。


- name: Notify Feishu
if: always()
Expand All @@ -36,13 +68,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

# 根据结论设置样式
Expand Down
74 changes: 61 additions & 13 deletions .github/workflows/pr-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
jobs:
review:
runs-on: ubuntu-latest
# 跳过 draft PR
if: github.event.pull_request.draft == false
permissions:
contents: read
Expand All @@ -22,29 +21,78 @@ jobs:
- name: PR Review with Claude
id: review
uses: anthropics/claude-code-action@v1
env:
ANTHROPIC_BASE_URL: ${{ secrets.ANTHROPIC_BASE_URL }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 环境变量传递方式变更

需要确认 claude-code-action@v1 是否支持通过 env.ANTHROPIC_BASE_URL 传递。

如果不确定,建议保留原有方式:

with:
  anthropic_base_url: ${{ secrets.ANTHROPIC_BASE_URL }}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 重要问题:环境变量配置方式需要验证

ANTHROPIC_BASE_URL 使用了 env 方式设置,需要确认 claude-code-action v1 是否支持通过环境变量读取此配置。

在之前的版本中使用的是 anthropic_base_url 参数。建议查看官方文档确认正确的配置方式。

with:
github_token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 重要问题:github_token 配置缺少回退机制

如果 CUSTOM_GITHUB_TOKEN secret 未配置,workflow 将会失败。

建议添加回退机制:

github_token: ${{ secrets.CUSTOM_GITHUB_TOKEN || github.token }}

这样在没有自定义 token 时会自动使用默认的 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: |
/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"
请对当前 PR 进行全面审查.

## 审查维度

**代码质量**:代码风格、复杂度、重复代码、命名规范、错误处理、潜在 bug

**架构设计**:项目结构一致性、依赖合理性、设计模式、关注点分离

## 输出格式(简体中文)

请按以下格式输出审查报告, 作为:

## 🔍 PR 代码审查报告

### 📋 概要
- **变更文件数**: {changedFiles}
- **新增/删除行数**: +{additions} / -{deletions}

### 🎯 审查结论
{APPROVE/REQUEST_CHANGES/COMMENT 及简要说明}

### 🔴 严重问题 (Critical)
{严重问题列表,如无则显示"无"}

### 🟠 重要问题 (Important)
{重要问题列表,如无则显示"无"}

### 🟢 改进建议 (Suggestions)
{改进建议列表,如无则显示"无"}

### 💡 总体评价
{对本次 PR 的整体评价}

## 注意事项
1. 所有评论使用简体中文
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"]}'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码可读性问题:

这一行的 claude_args 参数格式非常难以阅读和维护:

  • JSON schema 直接写在一行中,无法辨识结构
  • 工具列表混在一起,不易理解

建议改进:

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"]
  }'

或者考虑使用 YAML 的多行格式提高可读性。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 改进建议:JSON Schema 格式可读性差

单行的 JSON Schema 难以维护和阅读。建议使用更清晰的格式:

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"]
  }'

或者将 schema 定义在单独的文件中引用。

- 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
Expand Down
Loading