Files
NewSzxcn-Email/.github/workflows/ai-pr-review.yml
T
LanQin_ e35b0985ee ci(.github/workflows): 扩展 AI PR Review 触发方式
- 新增 `issue_comment` 和 `workflow_dispatch` 触发入口,支持通过评论或手动指定 PR 运行审查。
- 调整并发键与权限配置,兼容多事件场景并补充 `issues: write`。
- 收紧执行条件,仅在仓库内 PR、手动触发或授权评论指令下执行,并按事件类型动态注入 `PR_NUMBER` 与 `PR_HEAD_SHA`。
2026-06-22 14:12:48 +08:00

90 lines
3.3 KiB
YAML

name: AI PR Review
on:
pull_request:
branches:
- main
types: [opened, synchronize, reopened]
issue_comment:
types: [created]
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to review'
required: true
type: number
permissions:
contents: read
issues: write
pull-requests: write
concurrency:
group: ai-pr-review-${{ github.event_name == 'issue_comment' && github.event.issue.number || github.event_name == 'workflow_dispatch' && inputs.pr_number || github.event.pull_request.number }}
cancel-in-progress: true
jobs:
ai-review:
name: AI PR Review
if: >
(
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository
) ||
github.event_name == 'workflow_dispatch' ||
(
github.event_name == 'issue_comment' &&
github.event.issue.pull_request != null &&
(
contains(github.event.comment.body, '/ai-review') ||
contains(github.event.comment.body, '@ai-reviewer review')
) &&
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)
)
runs-on: ubuntu-latest
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Skip when API key is not configured
if: ${{ env.OPENAI_API_KEY == '' }}
run: echo "::notice::OPENAI_API_KEY secret is not configured; skipping AI PR review."
- name: Run AI PR reviewer
if: ${{ env.OPENAI_API_KEY != '' }}
run: npx --yes github-ai-pr-reviewer@latest --post
env:
OPENAI_API_KEY: ${{ env.OPENAI_API_KEY }}
OPENAI_MODEL: ${{ vars.OPENAI_MODEL || 'gpt-5.5' }}
OPENAI_API_MODE: ${{ vars.OPENAI_API_MODE || 'responses' }}
# 可选:reasoning 模型推理强度,例如 minimal / low / medium / high / xhigh;留空使用模型默认
OPENAI_REASONING_EFFORT: ${{ vars.OPENAI_REASONING_EFFORT }}
# 可选:Responses API reasoning summary,例如 auto / concise / detailed
OPENAI_REASONING_SUMMARY: ${{ vars.OPENAI_REASONING_SUMMARY }}
OPENAI_BASE_URL: ${{ vars.OPENAI_BASE_URL || 'https://api.openai.com/v1' }}
OPENAI_TIMEOUT_MS: ${{ vars.OPENAI_TIMEOUT_MS || '120000' }}
OPENAI_RETRIES: ${{ vars.OPENAI_RETRIES || '2' }}
GITHUB_TOKEN: ${{ github.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event_name == 'issue_comment' && github.event.issue.number || github.event_name == 'workflow_dispatch' && inputs.pr_number || github.event.pull_request.number }}
PR_HEAD_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || '' }}
REVIEW_RULES: .github/ai-review.md,AGENTS.md
REVIEW_IGNORE: .ai-reviewignore
REVIEW_SEVERITY_THRESHOLD: P3
SUMMARY_MODE: review
REVIEW_EVENT: AUTO
REQUEST_CHANGES_ON: P1
APPROVE_WHEN_CLEAN: 'false'
GITHUB_TIMEOUT_MS: '30000'
GITHUB_RETRIES: '2'
# 可选:发现 P1/P0 时让 CI 失败
# FAIL_ON: P1