PR Review Loop: 自动化代码审查与修复 - Openclaw Skills

作者:互联网

2026-03-30

AI教程

什么是 PR Review Loop?

PR Review Loop 是为 AI 智能体设计的强大自动化技能,用于处理端到端的拉取请求(PR)生命周期。通过与 Greptile 集成,此 Openclaw Skills 扩展允许智能体提交代码、接收专业级反馈,并迭代修复问题,直到代码达到高质量评分。它确保每个 PR 在合并前都符合特定的质量门槛,从而弥补了人工审查与完全自主开发之间的差距。

该技能对于在不放慢开发周期的前提下保持代码质量至关重要。它使用 GitHub CLI 与仓库交互,直接从 API 获取评论和评分。无论您是运行单智能体项目还是复杂的多智能体系统,PR Review Loop 都能确保所有贡献一致地符合代码标准。

下载入口:https://github.com/openclaw/skills/tree/main/skills/cemoso/pr-review-loop

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install pr-review-loop

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 pr-review-loop。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

PR Review Loop 应用场景

  • 智能体生成的拉取请求的自动化代码质量保证。
  • 人工审查成为瓶颈的持续集成工作流。
  • 需要自主修复与验证循环的高速开发周期。
  • 使用 Openclaw Skills 在多个仓库中标准化代码审查评分。
PR Review Loop 工作原理
  1. 该技能通过 PR URL 或来自 Greptile 审查的 Webhook 触发。
  2. 智能体使用 GitHub API 获取最新的审查数据和行内评论。
  3. 从审查正文中提取质量评分(通常总分为 5 分)。
  4. 如果评分等于或高于 4 分,智能体将自动合并 PR 并删除分支。
  5. 如果评分低于 4 分,智能体将解析每条评论,应用必要的代码更改,并推送新的提交。
  6. 智能体重新触发 Greptile 审查并重复该过程,直到达到目标评分或达到最大轮次限制。

PR Review Loop 配置指南

要在您的 Openclaw Skills 生态系统中使用此技能,请确保您已安装 GitHub CLI 并完成身份验证。

# 确保 GitHub CLI 已通过身份验证
gh auth status

# 在特定 PR 上运行审查循环
bash scripts/pr-review-loop.sh  

您还应该配置好 Greptile 以坚控您的仓库,并根据您的参考定义提供反馈模式。

PR Review Loop 数据架构与分类体系

该技能维护一个名为 review-state.json 的本地状态文件,以跟踪多个审查周期的进度并防止死循环。

属性 描述
rounds 当前已完成的修复与审查周期数。
maxRounds 自主尝试的限制次数(默认为 5 次)。
lastScore 上一次 Greptile 审查的数值质量评分。
sameScoreCount 跟踪质量评分是否陷入停滞,以便触发人工介入。
name: pr-review-loop
description: Autonomous PR review loop with Greptile. Use when an agent creates a PR and needs to autonomously handle code review feedback — reading Greptile reviews, fixing issues, pushing fixes, re-triggering review, and auto-merging when score is 4/5+. Trigger on commands like "pr review {url}", "review my PR", or when a Greptile review webhook/poll delivers feedback.

PR Review Loop

Autonomous cycle: Greptile reviews PR → agent fixes feedback → pushes → re-triggers → repeats until score ≥ 4/5 or max rounds.

Quick Start

When triggered with a PR URL or review payload:

# Run the review loop
bash scripts/pr-review-loop.sh  

Or invoke steps manually — see below.

Workflow

1. Fetch Review

# Get latest Greptile review
gh api "/repos/{owner}/{repo}/pulls/{pr}/reviews" r
  --jq '[.[] | select(.user.login == "greptile-apps[bot]")] | last'

# Get inline comments
gh api "/repos/{owner}/{repo}/pulls/{pr}/comments" r
  --jq '[.[] | select(.user.login == "greptile-apps[bot]")]'

2. Parse Score

Look for confidence/quality score in review body. Greptile typically includes a score like Score: X/5 or Confidence: X/5. Extract it:

  • Score ≥ 4/5 → auto-merge
  • Score < 4/5 → fix issues
  • No score found → treat as needing fixes if there are comments, otherwise merge

3. Auto-Merge (score ≥ 4)

gh pr merge  --merge --delete-branch --repo 

4. Fix Issues (score < 4)

For each Greptile comment:

  1. Read the file and line referenced
  2. Understand the feedback
  3. Apply the fix
  4. Stage changes

Commit with a descriptive message listing each fix:

Address Greptile review feedback (round N)

- Fix X in path/to/file.ts
- Fix Y in path/to/other.ts
- Improve Z per reviewer suggestion

Push and re-trigger:

git push
gh pr comment  --repo  --body "@greptileai review"

5. Track State

Maintain review-state.json in workspace:

{
  "owner/repo#123": {
    "rounds": 2,
    "maxRounds": 5,
    "lastScore": 3,
    "sameScoreCount": 1
  }
}

Update after each round. Check exit conditions:

  • rounds ≥ 5 → merge anyway, notify Master
  • sameScoreCount ≥ 2 (same score 2 rounds in a row) → merge anyway, notify Master

6. Escalation

  • Architectural decisions (review mentions architecture, design patterns, breaking changes) → ping Master on T@elegrimm, don't auto-fix
  • Max rounds reached → merge + notify Master with summary
  • Unclear feedback → ask Master

Command Interface

Agents should respond to:

  • pr review — start review loop on a PR
  • pr review — same, by reference
  • pr status — show active review loops and their state

References

See references/greptile-patterns.md for common Greptile feedback patterns and fix strategies.