Files
gmTouringMiniApp/.gitea/workflows/ai-review.yml
T

63 lines
2.7 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# AI 代码审查:每次 PR 触发(含 fork 跨仓库 PR),用 Claude Code 调用智谱 GLM(glm-5.2) 审查 diff
# 把结论评论到 PR。ANTHROPIC_API_KEY / REVIEW_PAT 由 runner 的 envs 注入(不经 Gitea secret
# 故 fork PR 也能拿到);MAIN_API 用组织变量。
name: AI Code Review
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
review:
runs-on: ubuntu-latest
env:
ANTHROPIC_BASE_URL: https://open.bigmodel.cn/api/anthropic
ANTHROPIC_MODEL: glm-5.2
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1"
DISABLE_AUTOUPDATER: "1"
IS_SANDBOX: "1"
# ANTHROPIC_API_KEY 和 REVIEW_PAT 不要写在这里 —— 由 runner envs 注入
steps:
- name: 检出代码(兼容 fork PR:克隆 head 仓库)
run: |
git config --global http.extraHeader "Authorization: Basic $(printf 'oauth2:%s' "$REVIEW_PAT" | base64 -w0)"
HEAD_URL=$(echo "${{ gitea.event.pull_request.head.repo.clone_url }}" | sed 's|http://[^/]*/|http://gitea:3000/|')
git clone "$HEAD_URL" .
git checkout "${{ gitea.event.pull_request.head.sha }}"
- name: 生成 PR diff(从 base 仓库取目标分支做对比)
run: |
BASE_REPO=$(echo "${{ gitea.event.pull_request.base.repo.clone_url }}" | sed 's|http://[^/]*/|http://gitea:3000/|')
BASE_REF="${{ gitea.event.pull_request.base.ref }}"
git remote add base "$BASE_REPO"
git fetch base "$BASE_REF"
git diff "base/$BASE_REF...HEAD" > pr.diff
echo "diff 行数: $(wc -l < pr.diff)"
- name: 安装 Claude Code(已装则跳过)
run: |
if command -v claude >/dev/null 2>&1; then echo "claude 已存在,跳过安装"
else npm install -g @anthropic-ai/claude-code --registry=https://registry.npmmirror.com
fi
- name: 运行 AI 审查
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:
API: ${{ vars.MAIN_API }}
run: |
if [ -s review.md ]; then
node -e 'let d="";process.stdin.on("data",c=>d+=c).on("end",()=>process.stdout.write(JSON.stringify({body:d})))' < review.md > /tmp/body.json
curl -fsS -X POST "$API/repos/${{ gitea.repository }}/issues/${{ gitea.event.pull_request.number }}/comments" \
-H "Authorization: token $REVIEW_PAT" \
-H "Content-Type: application/json" \
--data @/tmp/body.json
else
echo "review.md 为空,跳过评论"
fi