github-pr-merge

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub PR Merge

GitHub PR 合并

Merges Pull Requests after validating pre-merge checklist and handling post-merge cleanup.
在验证合并前检查清单并处理合并后清理工作后合并Pull Requests。

Quick Start

快速开始

bash
undefined
bash
undefined

1. Get PR info

1. 获取PR信息

PR=$(gh pr view --json number -q '.number') REPO=$(gh repo view --json nameWithOwner -q '.nameWithOwner')
PR=$(gh pr view --json number -q '.number') REPO=$(gh repo view --json nameWithOwner -q '.nameWithOwner')

2. Run pre-merge checklist

2. 运行合并前检查清单

make test && make lint && gh pr checks $PR
make test && make lint && gh pr checks $PR

3. Verify all comments replied

3. 验证所有评论已回复

gh api repos/$REPO/pulls/$PR/comments --jq '[.[] | select(.in_reply_to_id == null)] | length'
gh api repos/$REPO/pulls/$PR/comments --jq '[.[] | select(.in_reply_to_id == null)] | length'

4. Merge with concise message (--delete-branch auto-deletes remote)

4. 用简洁消息合并(--delete-branch会自动删除远程分支)

gh pr merge $PR --merge --delete-branch --body "- Change 1
  • Change 2
Reviews: N/N addressed Tests: X passed (Y% cov) Refs: Task N"
gh pr merge $PR --merge --delete-branch --body "- 变更1
  • 变更2
评审:N/N已处理 测试:X项通过(覆盖率Y%) 引用:任务N"

5. Post-merge cleanup (local only, remote already deleted)

5. 合并后清理(仅本地,远程已被删除)

git checkout develop && git pull && git branch -d feature/<name>
undefined
git checkout develop && git pull && git branch -d feature/<name>
undefined

Pre-Merge Checklist

合并前检查清单

ALWAYS verify before merging:
CheckCommandRequired
Tests passing
make test
Yes
Linting passing
make lint
or
make check
Yes
CI checks green
gh pr checks $PR
Yes
All comments repliedVerify only, don't replyYes
No unresolved threadsReview PR pageYes
合并前必须验证以下内容:
检查项命令是否必填
测试通过
make test
代码检查通过
make lint
make check
CI检查通过
gh pr checks $PR
所有评论已回复仅验证,无需回复
无未解决的讨论线程查看PR页面

Core Workflow

核心工作流

1. Identify PR

1. 识别PR

bash
PR=$(gh pr view --json number -q '.number')
REPO=$(gh repo view --json nameWithOwner -q '.nameWithOwner')
echo "PR #$PR in $REPO"
bash
PR=$(gh pr view --json number -q '.number')
REPO=$(gh repo view --json nameWithOwner -q '.nameWithOwner')
echo "PR #$PR in $REPO"

2. Check Comments Status

2. 检查评论状态

bash
undefined
bash
undefined

Count original comments (not replies)

统计原始评论(非回复)数量

ORIGINALS=$(gh api repos/$REPO/pulls/$PR/comments --jq '[.[] | select(.in_reply_to_id == null)] | length')
ORIGINALS=$(gh api repos/$REPO/pulls/$PR/comments --jq '[.[] | select(.in_reply_to_id == null)] | length')

Count comments that have at least one reply

统计至少有一条回复的评论数量

REPLIED=$(gh api repos/$REPO/pulls/$PR/comments --jq ' [.[] | select(.in_reply_to_id)] | [.[].in_reply_to_id] | unique | length ')
echo "Original comments: $ORIGINALS, With replies: $REPLIED"
REPLIED=$(gh api repos/$REPO/pulls/$PR/comments --jq ' [.[] | select(.in_reply_to_id)] | [.[].in_reply_to_id] | unique | length ')
echo "原始评论数:$ORIGINALS,已回复评论数:$REPLIED"

Find unreplied comment IDs

找出未回复的评论ID

UNREPLIED=$(gh api repos/$REPO/pulls/$PR/comments --jq ' [.[] | select(.in_reply_to_id) | .in_reply_to_id] as $replied_ids | [.[] | select(.in_reply_to_id == null) | select(.id | IN($replied_ids[]) | not) | .id] ') echo "Unreplied: $UNREPLIED"

All original comments should have at least one reply.

**If unreplied comments exist:**
- DO NOT reply from this skill
- STOP the merge process
- Inform user: "Found unreplied comments: [IDs]. Run github-pr-review first."
- Show which comment IDs are missing replies
UNREPLIED=$(gh api repos/$REPO/pulls/$PR/comments --jq ' [.[] | select(.in_reply_to_id) | .in_reply_to_id] as $replied_ids | [.[] | select(.in_reply_to_id == null) | select(.id | IN($replied_ids[]) | not) | .id] ') echo "未回复评论ID:$UNREPLIED"

所有原始评论都应至少有一条回复。

**如果存在未回复评论:**
- 不要通过此技能回复评论
- 停止合并流程
- 告知用户:"发现未回复评论:[ID列表]。请先运行github-pr-review。"
- 显示缺少回复的评论ID

3. Run Validation

3. 运行验证

bash
undefined
bash
undefined

Activate venv if Python project

如果是Python项目,激活虚拟环境

source venv/bin/activate 2>/dev/null
source venv/bin/activate 2>/dev/null

Run tests

运行测试

make test
make test

Run linting

运行代码检查

make lint # or: make check
make lint # 或:make check

Check CI status

检查CI状态

gh pr checks $PR

**All checks MUST pass before proceeding.**
gh pr checks $PR

**所有检查必须通过才能继续。**

4. Show PR Summary

4. 显示PR摘要

bash
gh pr view $PR --json title,body,commits,changedFiles --jq '
  "Title: \(.title)\nCommits: \(.commits | length)\nFiles: \(.changedFiles)"
'
bash
gh pr view $PR --json title,body,commits,changedFiles --jq '
  "标题:\(.title)\n提交数:\(.commits | length)\n修改文件数:\(.changedFiles)"
'

5. Confirm with User

5. 与用户确认

ALWAYS ask before merging:
Pre-merge checklist verified:
- Tests: passing
- Lint: passing
- CI: green
- Comments: all replied

Ready to merge PR #X. Proceed?
执行合并前必须询问用户:
合并前检查清单已验证:
- 测试:已通过
- 代码检查:已通过
- CI:已通过
- 评论:全部已回复

是否准备合并PR #X?请确认。

6. Execute Merge

6. 执行合并

bash
gh pr merge $PR --merge --delete-branch --body "$(cat <<'EOF'
- Key change 1
- Key change 2
- Key change 3

Reviews: N/N addressed
Tests: X passed (Y% cov)
Refs: Task N, Req M
EOF
)"
Merge strategy: Always use
--merge
(merge commit), never squash or rebase per project guidelines.
Note:
--delete-branch
automatically deletes the remote branch after merge.
bash
gh pr merge $PR --merge --delete-branch --body "$(cat <<'EOF'
- 关键变更1
- 关键变更2
- 关键变更3

评审:7/7已处理(Gemini 5, Codex 2)
测试:628项通过(覆盖率88%)
引用:任务8,需求14-15
EOF
)"
合并策略:始终使用
--merge
(合并提交),根据项目规范,绝不要使用压缩或变基。
注意
--delete-branch
会在合并后自动删除远程分支。

7. Post-Merge Cleanup

7. 合并后清理

bash
undefined
bash
undefined

Switch to develop and update (--delete-branch already deleted local+remote)

切换到develop分支并更新(--delete-branch已删除本地和远程分支)

git checkout develop git pull origin develop

**Note**: If you didn't use `--delete-branch`, manually delete:
```bash
git branch -d feature/<branch-name>           # local
git push origin --delete feature/<branch-name> # remote
git checkout develop git pull origin develop

**注意**:如果未使用`--delete-branch`,请手动删除:
```bash
git branch -d feature/<branch-name>           # 本地分支
git push origin --delete feature/<branch-name> # 远程分支

Merge Message Format

合并消息格式

Concise format (recommended for clean git log):
- Key change 1 (what was added/fixed)
- Key change 2
- Key change 3

Reviews: 7/7 addressed (Gemini 5, Codex 2)
Tests: 628 passed (88% cov)
Refs: Task 8, Req 14-15
Guidelines:
  • 3-5 bullet points max for changes
  • One line for reviews summary
  • One line for test results
  • One line for task/requirement references
  • No headers (##), no verbose sections
  • Total: ~10 lines max
简洁格式(推荐用于清晰的Git日志):
- 关键变更1(新增/修复内容)
- 关键变更2
- 关键变更3

评审:7/7已处理(Gemini 5, Codex 2)
测试:628项通过(覆盖率88%)
引用:任务8,需求14-15
规范
  • 变更点最多3-5个项目符号
  • 一行总结评审情况
  • 一行说明测试结果
  • 一行引用任务/需求
  • 不要使用标题(##),不要冗长章节
  • 总长度:最多约10行

Important Rules

重要规则

  • ALWAYS run full pre-merge checklist before merging
  • ALWAYS verify all review comments have replies
  • ALWAYS confirm with user before executing merge
  • ALWAYS use merge commit (--merge), never squash/rebase
  • ALWAYS delete feature branch after successful merge
  • NEVER merge with failing tests or lint
  • NEVER merge with unresolved CI checks
  • NEVER skip user confirmation
  • NEVER reply to PR comments from this skill - use github-pr-review instead
  • STOP merge if unreplied comments exist and direct user to review skill
  • 必须在合并前运行完整的合并前检查清单
  • 必须验证所有评审评论都已回复
  • 必须在执行合并前与用户确认
  • 必须使用合并提交(--merge),绝不要压缩/变基
  • 必须在合并成功后删除功能分支
  • 绝不要在测试或代码检查失败时合并
  • 绝不要在CI检查未解决时合并
  • 绝不要跳过用户确认
  • 绝不要通过此技能回复PR评论 - 请使用github-pr-review
  • 如果存在未回复评论,停止合并并引导用户使用评审技能

Error Handling

错误处理

Tests failing: Stop and inform user. Do not merge.
Lint errors: Stop and inform user. Do not merge.
CI checks pending: Wait or inform user. Do not merge.
Unreplied comments: List unreplied comment IDs. DO NOT reply from this skill. Tell user: "Found N unreplied comments: [IDs]. Run github-pr-review to address them before merge."
Branch protection: If merge fails due to protection rules, inform user of required approvals.
测试失败:停止并告知用户,不要合并。
代码检查错误:停止并告知用户,不要合并。
CI检查pending:等待或告知用户,不要合并。
未回复评论:列出未回复的评论ID。不要通过此技能回复。 告知用户:"发现N条未回复评论:[ID列表]。请先运行github-pr-review处理后再合并。"
分支保护:如果因保护规则导致合并失败,告知用户所需的批准要求。

Related Skills

相关技能

  • github-pr-review - For resolving review comments before merge
  • github-pr-creation - For creating PRs (this skill handles the merge)
  • git-commit - For commit message format during PR work
  • github-pr-review - 用于在合并前解决评审评论
  • github-pr-creation - 用于创建PR(此技能负责合并)
  • git-commit - 用于PR工作中的提交消息格式