AgentSkillsCN

squash-merge

利用 gh API 对 GitHub PR 执行压缩合并,撰写完美提交信息,精准概括分支上的所有变更。当您需要合并 PR、完成功能分支,或当用户说“压缩合并”“合并 PR”“完成此 PR”“上线此分支”时,均可使用此技能。同时遵循仓库的提交规范。

SKILL.md
--- frontmatter
name: squash-merge
description: Squash merge a GitHub PR using the gh API, crafting the perfect commit message that summarizes all changes on the branch. Use when merging PRs, finishing feature branches, or when user says "squash merge", "merge PR", "finish this PR", or "land this branch". Follows the repo's commit conventions.

Squash Merge PR

Squash merge a GitHub PR with a well-crafted commit message following the repo's conventions.

Workflow

1. Gather Context

bash
# PR details
gh pr view --json number,title,body,baseRefName,headRefName

# All commits on the branch
gh pr view --json commits --jq '.commits[] | "\(.oid[:7]) \(.messageHeadline)"'

# Full diff
gh pr diff

2. Detect Commit Convention

bash
# Check for commitlint config
ls commitlint.config.* .commitlintrc* 2>/dev/null

# Sample recent commits on base branch
git log origin/$(gh pr view --json baseRefName -q .baseRefName) --oneline -15

Use Conventional Commits if the repo uses it, otherwise match existing style.

3. Craft the Commit Message

Subject line:

  • Primary change type (feat, fix, refactor, etc.)
  • Optional scope from affected area
  • Imperative summary of overall change
  • Under 70 characters

Body:

  • What changed and why (not how)
  • Summarize key changes from all commits
  • Reference PR number

Structure:

code
<type>(<scope>): <summary>

<motivation and context>

<bullet points if multiple significant changes>

PR: #<number>

4. Execute Squash Merge

bash
gh pr merge <PR_NUMBER> --squash --delete-branch \
  --subject "<type>(<scope>): <summary>" \
  --body "$(cat <<'EOF'
<body content>

PR: #<PR_NUMBER>
EOF
)"

5. Verify

bash
gh pr view <PR_NUMBER> --json state,mergedAt

Type Selection

TypeUse for
featNew user functionality
fixBug fix
refactorCode restructuring, no behavior change
perfPerformance improvement
docsDocumentation only
testTest changes only
buildBuild system or deps
ciCI configuration
choreMaintenance

Choose the type representing the overall change. If mixed, use the most significant.

Examples

Feature:

code
feat(auth): Add OAuth2 login with Google and GitHub

Enable users to sign in using existing Google or GitHub accounts.
Includes session management and account linking.

PR: #142

Bug fix:

code
fix(api): Prevent race condition in concurrent requests

Multiple simultaneous requests could corrupt shared state.
Add mutex lock around critical section.

PR: #89

Refactor:

code
refactor(validation): Extract shared validation to core module

Consolidate duplicate validation from 5 endpoints into reusable
validators. No behavior change.

PR: #201