ci(.github/workflows): 扩展 AI PR Review 触发方式

- 新增 `issue_comment` 和 `workflow_dispatch` 触发入口,支持通过评论或手动指定 PR 运行审查。
- 调整并发键与权限配置,兼容多事件场景并补充 `issues: write`。
- 收紧执行条件,仅在仓库内 PR、手动触发或授权评论指令下执行,并按事件类型动态注入 `PR_NUMBER` 与 `PR_HEAD_SHA`。
This commit is contained in:
LanQin_
2026-06-22 14:12:48 +08:00
parent 002c097def
commit e35b0985ee
+27 -3
View File
@@ -5,18 +5,42 @@ on:
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.pull_request.number }}
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 }}
@@ -50,8 +74,8 @@ jobs:
OPENAI_RETRIES: ${{ vars.OPENAI_RETRIES || '2' }}
GITHUB_TOKEN: ${{ github.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
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