forked from zhouruizhe/gmTouringMiniApp
Initial commit
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
# AI 代码审查:每次 PR 触发,用 Claude Code 调用智谱 GLM(glm-5.2) 审查 diff,
|
||||
# 并把结论评论到 PR。走 GLM 的 Anthropic 兼容端点,无需访问 Anthropic 官方。
|
||||
name: AI Code Review
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
jobs:
|
||||
review:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
# 关键:把 Claude Code 指向智谱 GLM 的 Anthropic 兼容端点(已验证可用)
|
||||
ANTHROPIC_BASE_URL: https://open.bigmodel.cn/api/anthropic
|
||||
ANTHROPIC_API_KEY: ${{ secrets.ZHIPU_API_KEY }}
|
||||
ANTHROPIC_MODEL: glm-5.2
|
||||
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1" # 关闭遥测,避免访问被墙地址
|
||||
DISABLE_AUTOUPDATER: "1"
|
||||
IS_SANDBOX: "1" # CI 容器以 root 运行,需此项才能用 --dangerously-skip-permissions
|
||||
steps:
|
||||
- name: 检出代码
|
||||
# 手动克隆,避免从 github.com 下载 actions/checkout(内网不可达)
|
||||
env:
|
||||
REVIEW_PAT: ${{ secrets.REVIEW_PAT }}
|
||||
run: |
|
||||
git clone "http://oauth2:${REVIEW_PAT}@gitea:3000/${{ gitea.repository }}.git" .
|
||||
git checkout "${{ gitea.event.pull_request.head.ref }}"
|
||||
|
||||
- name: 生成 PR diff
|
||||
run: |
|
||||
BASE="${{ gitea.event.pull_request.base.ref }}"
|
||||
git fetch origin "$BASE"
|
||||
git diff "origin/$BASE...HEAD" > pr.diff
|
||||
echo "diff 行数: $(wc -l < pr.diff)"
|
||||
|
||||
- name: 安装 Claude Code
|
||||
run: npm install -g @anthropic-ai/claude-code --registry=https://registry.npmmirror.com
|
||||
|
||||
- name: 运行 AI 审查
|
||||
# Claude Code 会自动读取本仓库 CLAUDE.md 与 .claude/skills/*
|
||||
run: |
|
||||
claude -p "$(cat .claude/review-prompt.md)" \
|
||||
--model glm-5.2 \
|
||||
--output-format text \
|
||||
--dangerously-skip-permissions \
|
||||
--max-turns 15 > review.md || true
|
||||
|
||||
- name: 把审查结论评论到 PR
|
||||
env:
|
||||
REVIEW_PAT: ${{ secrets.REVIEW_PAT }}
|
||||
API: ${{ vars.MAIN_API }}
|
||||
REPO: ${{ gitea.repository }}
|
||||
PR: ${{ gitea.event.pull_request.number }}
|
||||
run: |
|
||||
if [ -s review.md ]; then
|
||||
BODY=$(node -e 'let d="";process.stdin.on("data",c=>d+=c).on("end",()=>process.stdout.write(JSON.stringify({body:d})))' < review.md)
|
||||
curl -fsS -X POST "$API/repos/$REPO/issues/$PR/comments" \
|
||||
-H "Authorization: token $REVIEW_PAT" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$BODY"
|
||||
else
|
||||
echo "review.md 为空,跳过评论"
|
||||
fi
|
||||
Reference in New Issue
Block a user