Open Code Review 项目解析知识图谱 / 分组目录 / 集成生态 / GitHub Actions 集成

GitHub Actions 集成

集成生态进阶工具G-E · 集成生态

What · 是什么

composite action(action.yml):24 入参/6 出参,fork-safe PR 解析,评论发布脚本(sticky/增量 IoU 去重/路由)
composite action(action.yml)封装完整审查流程,workflow 中一行引用即可接入
必填入参:llm_url、llm_auth_token、llm_model、llm_use_anthropic
可选入参:language(默认 English)、ocr_version(默认 latest)、review_concurrency、background、rule、upload_artifacts、sticky_summary、incremental(默认 false)、incremental_overlap_threshold(默认 0.6 IoU)、review_comment_batch_size(默认 50)、route_severity_below、route_categories、base_ref、head_sha
输出:comments_total、comments_inline、comments_skipped、comments_routed、comments_failed、summary_comment_url
流程:fork-safe PR 解析(checkout base + fetch pull/N/head)→ merge-base → ocr review --from MERGE_BASE --to HEAD_SHA --audience agent --format json → post-review-comments.js 发评论
post-review-comments.js 实现:sticky 摘要、增量 IoU 去重、50 条批量、severity+category 路由,fail-open 设计不丢 finding;upload_artifacts/sticky_summary/incremental 必须用字面字符串 'true'/'false'

Why · 为什么

原理 · Principle

PR 场景自动审查:push/pull_request 触发即审,评论直达 diff

fork-safe:外部贡献者 PR 也能正确解析 base 与 head,不因 fork 结构失败

fail-open:后处理脚本出错也不丢 finding,审查结果可事后回看

去重+批量+路由控制评论噪音:IoU 0.6 增量去重、50 条批量、按严重级/类别分流

How · 怎么做

基础接入:workflow 中 uses: alibaba/open-code-review@<版本>,配齐 4 个必填入参
增量审查:incremental: 'true' 只审新增/变更区域,IoU 阈值用 incremental_overlap_threshold 调(默认 0.6)
sticky 摘要:sticky_summary: 'true' 固定摘要评论位置
路由分流:route_severity_below / route_categories 按严重级/类别分发
后台模式:background: true 异步执行不阻塞 CI
结果消费:读取 outputs.comments_total/comments_inline 等统计驱动后续步骤
版本与语言:ocr_version 指定 CLI 版本,language 指定评论语言
并发控制:review_concurrency 限制同时审查的任务数

案例 · Cases

代表性案例
标准 PR 审查:pull_request 事件 + 4 个必填入参即可上线
大型 PR 控噪:incremental 'true' + 调小 review_comment_batch_size + route 分流
只关注高危:route_severity_below 屏蔽低危 finding 的评论
外部贡献者 fork PR:内置 fork-safe 解析自动处理 base/head

反模式 · Anti-patterns

正反实例论证 · Evidence

正例 · Pro
标准 PR 审查完整配置
- uses: alibaba/open-code-review@latest with: llm_url: ${{ secrets.LLM_URL }} llm_auth_token: ${{ secrets.LLM_AUTH_TOKEN }} llm_model: deepseek-chat llm_use_anthropic: 'false' language: Chinese incremental: 'true' sticky_summary: 'true'
4 个必填入参 + 增量审查(IoU 默认 0.6 去重)+ sticky 摘要;composite action 内部走 fork-safe PR 解析 → merge-base → ocr review --from MERGE_BASE --to HEAD_SHA --audience agent --format json → post-review-comments.js。
反例 · Con
布尔值陷阱:incremental 等必须用字符串
with: incremental: true sticky_summary: true upload_artifacts: true
upload_artifacts/sticky_summary/incremental 三个入参必须用字面字符串 'true'/'false',写成 YAML 布尔值会解析失效,增量去重与摘要静默不生效。
正例 · Pro
路由分流 + 批量控制评论噪音
with: route_severity_below: info route_categories: security,bug review_comment_batch_size: 50
按严重级/类别路由 finding,评论 50 条批量提交;后处理 fail-open 设计保证即使脚本出错也不丢 finding。
反例 · Con
fork PR 自行 checkout 取错 base
- uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.ref }}
不依赖 action 内置的 fork-safe PR 解析(checkout base + fetch pull/N/head),fork 场景 head.ref 解析易错,merge-base 计算错误导致审查范围错误。
正例 · Pro
消费 outputs 驱动后续步骤
- id: ocr uses: alibaba/open-code-review@latest with: llm_url: ${{ secrets.LLM_URL }} llm_auth_token: ${{ secrets.LLM_AUTH_TOKEN }} llm_model: deepseek-chat llm_use_anthropic: 'false'- run: | echo "total=${{ steps.ocr.outputs.comments_total }}" echo "url=${{ steps.ocr.outputs.summary_comment_url }}"
outputs 提供 comments_total/comments_inline/comments_skipped/comments_routed/comments_failed/summary_comment_url,可驱动门禁或通知步骤。
反例 · Con
background 模式立即读 outputs 为空
with: background: true# 后续步骤立即读 outputs
background 为异步执行不阻塞 CI,立即读取 outputs 得到空值;应等待审查完成后再收集统计。

实践资产 · Assets

CI 集成
GitHub Actions 自动审查 workflow 示例(PR 事件+评论触发,并发组防重)
examples/github_actions/ocr-review.yml · 5170 B
CI 集成
GitHub Actions composite action 完整定义(24 入参 / 6 出参)
action.yml · 14207 B
脚本
GHA 评论发布脚本(sticky 摘要 / 增量 IoU 去重 / 50 条批量 / severity 路由)
scripts/github-actions/post-review-comments.js · 96540 B

相关边