AgentSkillsCN

github-pull-request

通过 GitHub MCP、GitHub CLI(gh),或 GitHub REST API 在 GitHub 上创建拉取请求。适用于用户希望按照仓库标准与模板,以拉取请求的形式提交更改时使用。

SKILL.md
--- frontmatter
name: github-pull-request
description: Create pull requests on GitHub using GitHub MCP, GitHub CLI (gh), or the GitHub REST API. Use this skill when the user wants to submit changes as a pull request, following repository standards and templates.

GitHub Pull Request Skill

When to use this skill

Use this skill when you need to create a pull request for current changes in a repository. It provides a structured workflow for gathering PR details, filling templates, and executing the creation via available tools.

Workflow

  1. Identify Base Branch: Determine the target base branch for the pull request (usually main, master, or as specified by the user or repository settings).
  2. Analyze Changes: Compare the current HEAD commit against the base branch to understand the scope of changes.
    • Use git diff base...HEAD --stat and git log base...HEAD to gather information.
  3. Check for Templates: Check if there's a pull request template in the repository.
    • Common locations: pull_request_template.md, .github/pull_request_template.md, or inside .github/PULL_REQUEST_TEMPLATE/.
  4. Fill the Template:
    • Automatically populate the template using information from the commit logs and diff.
    • If any required information cannot be confidently filled (e.g., "Related Issue Number", "Testing Steps" if not obvious), mark these as "PENDING" and inform the user.
  5. Review with User:
    • ALWAYS show the filled template to the user for review.
    • Explicitly mention any sections that need manual filling.
  6. Create Pull Request:
    • ONLY after the user approves the description, proceed to create the PR.
    • Use tools in this order of precedence:
      1. GitHub MCP Server: Use github.create_pull_request tool if available.
      2. GitHub CLI (gh): Run gh pr create --title "..." --body "..." --base <base> --head <head>.
      3. GitHub REST API (curl): Use curl to POST to /repos/{owner}/{repo}/pulls.

Tools and Commands

GitHub CLI (gh)

bash
# Get default branch
gh repo view --json defaultBranchRef -q .defaultBranchRef.name

# Create PR
gh pr create --title "PR Title" --body-file pr_body.md --base main

GitHub REST API (curl)

If using curl, ensure you have a GITHUB_TOKEN environment variable.

bash
curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer \$GITHUB_TOKEN" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/{owner}/{repo}/pulls \
  -d '{"title":"Title","body":"Body","head":"head-branch","base":"base-branch"}'

Examples

Pull Request Preview and Approval Request

The agent should present the filled template to the user like this:

I have prepared the following pull request description based on your changes and the repository's template.

Title: feat: add user authentication module

Body:

Summary

This PR adds a new authentication module using JWT.

Changes

  • Added src/auth/ directory
  • Implemented login and logout endpoints
  • Updated README.md with setup instructions

Pending Information

  • Related Issue Number: Please provide the issue number this PR addresses.
  • Testing Steps: I have listed basic steps, but please verify if additional scenarios are needed.

Do you approve this description? Once approved, I will create the pull request.

Validation Steps

  1. Template Check: Verify that pull_request_template.md (or equivalent) was searched for and loaded if present.
  2. Content Analysis: Confirm that the PR description includes a summary of changes based on git logs/diffs.
  3. User Approval: Confirm the agent displayed the filled template and received explicit approval before PR creation.
  4. Success Confirmation: Verify the PR was successfully created by checking tool output or PR list.