Skip to content
Agentmart
Submit a tool

cnb-pr-diff

获取 PR 的 diff 变更信息。

Skill by wopal-cn

IndexedMIT★ 3
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/wopal-cn-cnb-pr-diff

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

获取 PR 的 diff 变更信息。

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/cnb-pr-diff

What's inside

Skill name
cnb-pr-diff
Description
获取 PR 的 diff 变更信息。
License
MIT
Instructions
93 lines in SKILL.md · view on GitHub

Before installing

  • Instructions call the network

Files (2)

  • README.md
  • SKILL.md

SKILL.md (first lines)

# 获取 PR Diff

获取 PR 的代码变更差异信息,用于代码评审、变更总结等场景。

## 1. 判断场景并获取 SHA

### 场景 A:PR 评论触发(`CNB_PULL_REQUEST_IID` 存在)

直接从环境变量获取:
- head SHA:`CNB_PULL_REQUEST_SHA`
- target SHA:`CNB_PULL_REQUEST_TARGET_SHA`

若环境变量不存在,通过 API 查询当前 PR 详情。

### 场景 B:Issue 或其他场景引用 PR

用户输入中提及了 PR 编号(如 `!45`),需要:
1. 从用户输入中解析 PR 编号
2. 通过 API 查询该 PR 详情获取 SHA
3. fetch 对应的 commit(本地可能没有)

### API 查询 PR 详情

```bash
# 将 ${pr_iid} 替换为实际 PR 编号
pr_info=$(curl -s \
  "${CNB_API_ENDPOINT:-https://api.cnb.cool}/${CNB_REPO_SLUG}/-/pulls/${pr_iid}" \
  -H "Accept: application/vnd.cnb.api+json" \
  -H "Authorization: Bearer $CNB_TOKEN")

head_sha=$(echo "$pr_info" | jq -r '.head.sha')
target_sha=$(echo "$pr_info" | jq -r '.base.sha')

# 场景 B 需要确保本地有这些 commit
git fetch origin "$head_sha" "$target_sha" 2>/dev/null || git fetch origin
```

## 2. 获取 Diff

### 获取变更文件列表

```bash
git diff --name-only "${target_sha}...${head_sha}"
```

### 获取变更统计

```bash
git diff --stat "${target_sha}...${head_sha}"
```

### 获取完整 Diff

```bash
git diff -U5 "${target_sha}...${head_sha}"
```

### 获取特定文件的 Diff

```bash
git diff -U5 "${target_sha}...${head_sha}" -- path/to/file.ts
```

## 3. 过滤文件

根据使用场景,可排除无需关注的文件:

```bash
# 常见排除模式
git diff -U5 "${target_sha}...${head_sha}" -- . \
  ':!package-lock.json' ':!yarn.lock' ':!pnpm-lock.yaml' ':!go.sum' ':!*.lock' \
  ':!*.png' ':!*.jpg' ':!*.gif' ':!*.svg' ':!*.ico' \
  ':!*.min.js' ':!*.min.css' ':!*.map' \
  ':!dist/*' ':!build/*' ':!node_modules/*'
```

**可排除的文件类型**:
- 锁文件:`package-lock.json`、`yarn.lock`、`pnpm-lock.yaml`、`go.sum`、`Cargo.lock`
- 图片/字体:`*.png`、`*.jpg`、`*.gif`、`*.svg`、`*.woff`、`*.ttf`
- 二进制:`*.exe`、`*.dll`、`*.so`、`*.jar`、`*.pyc`
- 压缩包:`*.zip`、`*.tar.gz`、`*.rar`
- 构建产物:`dist/`、`build/`、`out/`、`target/`、`.next/`
- 依赖目录:`node_modules/`、`vendor/`、`.venv/`
- 压缩文件:`*.min.js`、`*.min.css`、`*.map`

## 4. 使用建议

1. **diff 过大时**:先用 `--name-only` 查看文件列表,再按需获取具体文件
2. **代码评审**:建议排除锁文件、图片、构建产物
3. **变更总结**:可保留更多文件,但排除二进制和依赖目录
4. **上下文行数**:`-U5` 提供 5 行上下文,可按需调整

From wopal-cn/wopal-space-ontology, MIT.

More from wopal-cn/wopal-space-ontology

Signals

Stars
3
Forks
1
Open issues
0
Last commit (this folder)
Sep 15, 2026 (1 month ago)
Last release
Oct 24, 2026 (5 days ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from wopal-cn

Cite this page

cnb-pr-diff skill. Agent Mart. https://agentmart.dev/skills/wopal-cn-cnb-pr-diff (last updated 2026-10-24)