AgentSkillsCN

pull-request

执行拉取请求创建工作流,包括身份验证、分支验证、变更分析,以及gh CLI操作。当您被要求创建PR、打开拉取请求、提交变更以供审查,或在完成工作且创建PR合乎逻辑时使用此技能。此技能负责PR创建的“怎么做”(工作流步骤、命令、验证)。关于PR标题与描述的格式化规则,请使用合适的技能。

SKILL.md
--- frontmatter
name: pull-request
description: Execute Pull Request creation workflow including authentication, branch verification, change analysis, and gh CLI operations. Use when asked to create a PR, open a pull request, submit changes for review, or after completing work where PR creation is logical. This skill handles the HOW of creating PRs (workflow steps, commands, verification). For PR title and description FORMAT rules, use the appropriate skill.

Pull Request Skill

Execute Pull Request creation following a structured workflow that ensures authentication, branch safety, and proper change analysis.

Workflow

Step 1: Verify GitHub CLI Authentication

Before any GitHub operation, verify authentication status:

bash
gh auth status

If authentication fails:

  1. Inform the user: "GitHub CLI authentication is missing or expired."
  2. Provide the command to re-authenticate:
    bash
    gh auth login --web
    
  3. Wait for the user to complete authentication before proceeding.

Step 2: Verify Branch State

CRITICAL: Never create a PR from a protected branch.

bash
# Get current branch
git branch --show-current

# Get the repository's default branch
gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'

Protected branches (cannot be PR source):

  • The default branch (usually main or master)
  • develop or development
  • Any branch matching release/* or hotfix/* patterns

If on protected branch, inform user and switch to or create a feature branch first.

Branch state verification:

bash
# Verify commits ahead of base
DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')
git log --oneline "${DEFAULT_BRANCH}..HEAD"

# Check for uncommitted changes
git status --short

# Push branch if needed
git push -u origin $(git branch --show-current)

Pre-PR checklist:

  • Current branch is NOT a protected branch
  • Branch has commits ahead of base branch
  • No uncommitted changes (commit or stash first)
  • Branch is pushed to remote

Step 3: Analyze Changes for PR Description

Gather context for the PR description:

bash
# Get default branch name
DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')

# Get all commits in this PR
git log --format="%s%n%b" $DEFAULT_BRANCH..HEAD

# Get list of changed files
git diff --name-only $DEFAULT_BRANCH..HEAD

# Get diff stats
git diff --stat $DEFAULT_BRANCH..HEAD

Analyze for:

ElementSource
TypePrimary commit type (feat, fix, refactor, chore, perf)
IntentBusiness/technical goal from commit messages
Entry PointMost critical or complex changed file
Sensitive AreasFiles requiring extra scrutiny (auth, payments, data)
Breaking ChangesLook for ! in commits or BREAKING CHANGE footer
MigrationsDatabase or schema changes

Step 4: Create the Pull Request

bash
# Get default branch for base
DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')

# Do NOT use double quotes for --body
gh pr create \
  --title "<type>: <description>" \
  --body '<generated description>' \
  --base "$DEFAULT_BRANCH"

For draft PRs:

bash
# Do NOT use double quotes for --body
gh pr create \
  --title "<type>: <description>" \
  --body '<generated description>' \
  --base "$DEFAULT_BRANCH" \
  --draft

Follow the PR Description Convention.

IMPORTANT: Do NOT use double quotes for --body to avoid shell interpolation issues.

Step 5: Confirm Success

After creating, verify and report:

bash
# Get PR URL
gh pr view

Report to the user:

  • PR number and URL
  • Title
  • Base and head branches

Error Handling

ErrorCauseResolution
"pull request already exists"PR open for this branchUse gh pr view to see existing PR
"no commits between"Branch same as baseVerify commits exist on branch
"repository not found"Wrong remote or no accessCheck git remote -v and permissions