Skip to main content
ClaudeWave
Skill28.2k estrellas del repoactualizado today

pr-review

The pr-review skill performs local code review of pull requests with full project context by reading source files directly. Use it when you need thorough code analysis with CI status verification, supporting both interactive mode for manual review workflows and automation mode for programmatic integration with optional PR number and automation flags.

Instalar en Claude Code
Copiar
git clone --depth 1 https://github.com/iOfficeAI/AionUi /tmp/pr-review && cp -r /tmp/pr-review/.claude/skills/pr-review ~/.claude/skills/pr-review
Después abre una sesión nueva de Claude Code; el skill carga automáticamente.

SKILL.md

# PR Code Review (Local)

Perform a thorough local code review with full project context — reads source files directly, no API truncation limits.

**Announce at start:** "I'm using pr-review skill to review the pull request."

## Usage

```
/pr-review [pr_number]
```

`$ARGUMENTS` may contain an optional PR number and/or `--automation` flag.

- Without `--automation`: interactive mode (prompts for confirmation, comment, cleanup)
- With `--automation`: non-interactive mode (auto-post comment, auto-delete branch, output machine-readable result)

---

## Steps

### Step 1 — Determine PR Number

If `$ARGUMENTS` is non-empty, use it as the PR number.

Otherwise run:

```bash
gh pr view --json number -q .number
```

If this also fails (not on a PR branch), abort with:

> No PR number provided and cannot detect one from the current branch. Usage: `/pr-review <pr_number>`

Also parse `--automation` from `$ARGUMENTS`:

```bash
AUTOMATION_MODE=false
if echo "$ARGUMENTS" | grep -q -- '--automation'; then
  AUTOMATION_MODE=true
fi
```

### Step 2 — Check CI Status

```bash
gh pr view <PR_NUMBER> --json statusCheckRollup \
  --jq '.statusCheckRollup[] | {name: .name, status: .status, conclusion: .conclusion}'
```

**必检 job 列表:**

- `Code Quality`
- `Unit Tests (ubuntu-latest)`
- `Unit Tests (macos-14)`
- `Unit Tests (windows-2022)`
- `Coverage Test`
- `i18n-check`

(`build-test` 为可选 job,不纳入必检范围。)

**特殊情形:** 满足以下任一条件时,跳过此步骤,直接继续:

- `statusCheckRollup` 为空(CI 从未触发)
- `statusCheckRollup` 非空,但所有必检 job 均不在列表中(说明 pr-checks.yml 工作流整体未触发,如仅改动 docs/md 文件的 PR)

**解析逻辑:** 分三种情形处理:

**Informational checks exclusion:** `codecov/patch` and `codecov/project` are configured as `informational: true` in `codecov.yml` — they never block merging and must be **excluded** from all failure checks below. Treat them as non-existent when evaluating CI status.

**情形 1 — 全部通过**(所有必检 job 均满足 `status == COMPLETED && conclusion == SUCCESS`,**且** `statusCheckRollup` 中无任何**非 informational** job 的 `conclusion` 为 `FAILURE` 或 `CANCELLED`;`codecov/*` 失败不影响此判断)

直接继续后续步骤,无需提示。

**情形 2 — 部分仍在运行**(存在 `status` 为 `QUEUED` 或 `IN_PROGRESS` 的**必检** job;非必检 job 仍在运行不影响此判断)

显示警告并询问:

> ⏳ 以下 CI job 尚未完成:[job 列表]
> PR CI 未全部完成,建议等待后再 review。是否仍要继续?(yes/no)

- 用户选 **no** → 终止
- 用户选 **yes** → 继续后续步骤

- **Automation mode:** do not prompt. Output signal and stop:
  ```
  <!-- automation-result -->
  CONCLUSION: CI_NOT_READY
  IS_CRITICAL_PATH: false
  CRITICAL_PATH_FILES: (none)
  PR_NUMBER: <PR_NUMBER>
  <!-- /automation-result -->
  ```
  Then exit.

**情形 3 — 存在失败**(`statusCheckRollup` 中存在**任意非 informational** job 的 `conclusion` 为 `FAILURE` 或 `CANCELLED`,不限于必检列表;`codecov/*` 始终排除在外)

显示警告并询问:

> ❌ 以下 CI job 未通过:[job 列表及结论]
> PR CI 存在失败,review 结论可能不准确。是否仍要继续?(yes/no)

- 用户选 **yes** → 继续,并在最终报告"变更概述"段落末尾追加 CI 状态警告(格式见"报告增强"节)
- 用户选 **no** → 终止 review,随即询问:

  > 是否在 PR #\<PR_NUMBER\> 发表评论,提醒作者修复失败的 CI job?(yes/no)
  - 用户选 **yes** → 发布 CI 失败提醒评论(格式见下方"CI 失败提醒评论"节),然后退出
  - 用户选 **no** → 直接退出

- **Automation mode:** do not prompt. Post CI failure comment automatically (same format as "CI 失败提醒评论"), then output signal and stop:
  ```
  <!-- automation-result -->
  CONCLUSION: CI_FAILED
  IS_CRITICAL_PATH: false
  CRITICAL_PATH_FILES: (none)
  PR_NUMBER: <PR_NUMBER>
  <!-- /automation-result -->
  ```
  Then exit.

#### CI 失败提醒评论

当 CI 失败且用户选择不继续 review 但选择发布提醒时,评论格式:

```bash
gh pr comment <PR_NUMBER> --body "<!-- pr-review-bot -->

## CI 检查未通过

以下 job 在本次 review 时未通过,请修复:

| Job | 结论 |
|-----|------|
| <失败的 job 名称> | ❌ <FAILURE 或 CANCELLED> |

本次 code review 暂缓,待 CI 全部通过后将重新执行。"
```

(仅列出实际失败的 job,跳过已通过的。)

#### 报告增强

当 CI 存在失败但用户选择继续时,在最终报告"变更概述"段落末尾追加:

```
> ⚠️ **CI 状态警告**:以下 job 在 review 时未通过:`<job 名称>`(<结论>)。本报告结论仅供参考,建议修复 CI 后重新 review。
```

---

### Step 3 — Create Worktree

Create an isolated worktree for this PR review. The main repo stays on its current branch.

```bash
REPO_ROOT=$(git rev-parse --show-toplevel)
PR_NUMBER=<PR_NUMBER>
WORKTREE_DIR="/tmp/aionui-pr-${PR_NUMBER}"

# Clean up any stale worktree from a previous crash
git worktree remove "$WORKTREE_DIR" --force 2>/dev/null || true

# Fetch PR head AND base branch so the three-dot diff is accurate
git fetch origin pull/${PR_NUMBER}/head
BASE_REF=$(gh pr view ${PR_NUMBER} --json baseRefName --jq '.baseRefName')
git fetch origin "$BASE_REF"
git worktree add "$WORKTREE_DIR" FETCH_HEAD --detach

# Symlink node_modules so lint/tsc/test can run in the worktree
ln -s "$REPO_ROOT/node_modules" "$WORKTREE_DIR/node_modules"
```

Save `REPO_ROOT` and `WORKTREE_DIR` for use in subsequent steps. All file reads, lint, and diff commands from this point forward run inside `WORKTREE_DIR`.

Save the checked-out HEAD info:

```bash
cd "$WORKTREE_DIR"
git log --oneline -1
```

### Step 4 — Collect Context (Parallel)

Run the following in parallel:

**PR metadata:**

```bash
gh pr view <PR_NUMBER> --json title,body,author,labels,headRefName,baseRefName,state,createdAt,updatedAt
```

**Full diff (no truncation):**

```bash
cd "$WORKTREE_DIR"
git diff origin/<baseRefName>...HEAD
```

**Changed file list:**

```bash
cd "$WORKTREE_DIR"
git diff --name-status origin/<baseRefName>...HEAD
```

**PR discussion comments (excluding bot review comments):**

```bash
gh pr view <PR_NUMBER> --json comments \
  --jq '[.comments[] | select(.body | startswith("<!-- pr-review-bot -->") | not) | select(.body | startswith("<!-- pr-automation-bot -->") | not) | {author: .author.login, body: .body, createdAt: .createdAt}]'
```

Save as `pr_discussion`. Use in Step 7 as supplementary context for **方案合理性** evaluation — if participants have explained design decisions or flagged known trade-offs, factor that in. Code is always the authoritative source; comments are context only.

### Step 5 — Run Lint on Changed Files

Run oxlint on all changed `.ts` / `.tsx` files (skip deleted files):

```bash
cd "$WORKTREE_DIR"
bunx oxlint <changed_ts_tsx_files...>
```

Save the lint output as **lint baseline**. Use it when reviewing style and cod