AgentSkillsCN

Git Create Pr

按照项目规范创建拉取请求,或对现有拉取请求进行更新

SKILL.md
--- frontmatter
description: Create a pull request or update an existing one following project conventions

Create Pull Request

Create a pull request or update an existing one following project conventions.

Usage

  • /git-create-pr - Create PR to main
  • /git-create-pr <base-branch> - Create PR to specified base branch

Reference Files

  • @pr-body-template.md - PR body structure template

Instructions

  1. Gather context (run in parallel):

    • git status - Check for uncommitted changes
    • git branch --show-current - Get current branch name
    • git log origin/main..HEAD --oneline - See commits to include (adjust base as needed)
    • git diff origin/main..HEAD --stat - See files changed
  2. Check for uncommitted changes:

    • If there are uncommitted changes, ask user if they want to commit first
    • Do not proceed with PR creation if there are uncommitted changes
  3. Check for existing PR:

    bash
    gh pr list --head <current-branch>
    
    • If a PR already exists, ask user: "PR #N already exists for this branch. Update its description instead of creating new?"
    • If yes, use gh pr edit <number> --body "..." instead of gh pr create
  4. Determine base branch:

    • If $ARGUMENTS provided, use that as base
    • If branch name suggests a parent (e.g., feature/foo-part2 might be based on feature/foo), ask user
    • Default to main
  5. Check if push needed:

    • If local is ahead of remote, push first: git push -u origin <branch>
  6. Create or update PR using the template from @pr-body-template.md

  7. Run the gh command:

For new PR:

bash
gh pr create --base <base-branch> --title "<title>" --body "$(cat <<'EOF'
<body content>
EOF
)"

For existing PR:

bash
gh pr edit <number> --body "$(cat <<'EOF'
<body content>
EOF
)"
  1. Return the PR URL to the user.