AgentSkillsCN

Github Pr Lifecycle

GitHub Pull Request 生命周期管理

SKILL.md

GitHub Pull Request Lifecycle

Overview

Pull request lifecycle management covers the complete workflow from branch creation through merge and post-merge activities. This skill covers PR workflows, review processes, automation, and best practices for managing pull requests efficiently using GitHub's features.

When to use this skill: When creating, reviewing, or managing pull requests in GitHub repositories.

Table of Contents

  1. PR Lifecycle Stages
  2. PR Creation Workflow
  3. Review and Approval
  4. Merge Strategies
  5. Post-Merge Activities
  6. PR Lifecycle Checklist
  7. Quick Reference

PR Lifecycle Stages

Complete Lifecycle Flow

mermaid
graph LR
    A[Create Branch] --> B[Make Changes]
    B --> C[Commit Changes]
    C --> D[Push to Remote]
    D --> E[Create PR]
    E --> F[Automated Checks]
    F --> G{Checks Pass?}
    G -->|No| H[Fix Issues]
    H --> C
    G -->|Yes| I[Request Review]
    I --> J[Review Process]
    J --> K{Approved?}
    K -->|Changes Requested| L[Update PR]
    L --> C
    K -->|Approved| M[Merge PR]
    M --> N[Delete Branch]
    N --> O[Close Issue]

PR States

StateDescriptionNext Action
DraftWork in progress, not ready for reviewMark as ready when complete
OpenReady for reviewReviewers review changes
MergedChanges merged into target branchDelete feature branch
ClosedPR closed without mergeMay need reopening

PR Creation Workflow

Branch Naming Conventions

bash
# Feature branches
feature/user-authentication
feature/add-payment-gateway

# Bugfix branches
bugfix/login-error
bugfix/memory-leak

# Hotfix branches
hotfix/security-patch
hotfix/critical-bug

# Release branches
release/v2.0.0
release/v2.1.0

Creating a Pull Request

bash
# Using GitHub CLI
gh pr create \
  --title "feat: Add user authentication" \
  --body "Implements #123" \
  --base main \
  --head feature/user-auth \
  --label enhancement \
  --reviewer @tech-lead \
  --assignee @me

# Using Git
git checkout -b feature/user-auth
git push origin feature/user-auth
# Then create PR via GitHub web UI

PR Description Template

markdown
## Description
Brief description of what this PR does.

## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring

## Related Issue
Closes #123

## Changes Made
- Added user authentication flow
- Implemented JWT token validation
- Added login/logout endpoints
- Updated tests for auth module

## Testing
- [ ] Unit tests pass
- [ ] Integration tests pass
- [ ] Manual testing completed
- [ ] Added new tests

## Screenshots (if applicable)
![Screenshot](link-to-screenshot)

## Checklist
- [ ] Code follows style guidelines
- [ ] Self-review performed
- [ ] Commented complex code
- [ ] Documentation updated
- [ ] No console.log statements
- [ ] No merge conflicts

## Breaking Changes
Describe any breaking changes and migration steps.

## Additional Notes
Any additional context for reviewers.

Review and Approval

Requesting Reviews

bash
# Request specific reviewers
gh pr edit 123 --add-reviewer @username1,@username2

# Request team review
gh pr edit 123 --add-team-reviewer @backend-team

# Request code owner review
gh pr edit 123 --reviewer codeowners

# Request review from all team members
gh pr edit 123 --add-reviewer @team-name --reviewer-count 3

Review Types

Review TypeDescriptionWhen to Use
Required ReviewerMust approve before mergeCritical code paths
Optional ReviewerNice to have feedbackGeneral changes
Team ReviewAny team member can approveTeam-managed code
Code Owner ReviewOwners of changed filesCross-team changes

Review Response Workflow

mermaid
graph TD
    A[Review Submitted] --> B{Feedback Type}
    B -->|Approve| C[PR Approved]
    B -->|Comment| D[Author Responds]
    B -->|Request Changes| E[Author Updates]
    D --> F{Resolved?}
    E --> F
    F -->|Yes| G[Reviewer Approves]
    F -->|No| H[Discussion Continues]
    G --> I[Ready to Merge]

Merge Strategies

Merge Types

StrategyDescriptionWhen to Use
Merge CommitCreates merge commitPreserve history
Squash and MergeCombines all commitsClean history
Rebase and MergeReplays commits on targetLinear history
Fast-forwardMoves pointer forwardNo merge commit

Merge Best Practices

bash
# Squash merge for clean history
gh pr merge 123 --squash --delete-branch

# Rebase merge for linear history
gh pr merge 123 --rebase --delete-branch

# Create merge commit
gh pr merge 123 --merge --delete-branch

# Merge with custom commit message
gh pr merge 123 --squash \
  --subject "feat: Add user authentication" \
  --body "Implements #123. Adds JWT-based authentication."

Branch Protection Rules

yaml
# .github/branch-protection.yml (via GitHub UI)
# Main branch protection settings:
- Require pull request reviews before merging
- Require approval from CODEOWNERS
- Require status checks to pass before merging
- Require branches to be up to date before merging
- Restrict who can push to matching branches
- Allow force pushes
- Include administrators

Post-Merge Activities

Branch Cleanup

bash
# Delete local branch
git branch -d feature/user-auth

# Delete remote branch
git push origin --delete feature/user-auth

# Or use GitHub CLI
gh repo sync --delete-source-branches

Issue Management

bash
# Close related issue when PR merges
gh issue close 123 --comment "Fixed by #456"

# Add comment to issue
gh issue comment 123 --body "Merged in #456. Will be available in next release."

# Link PR to issue (in PR description)
Closes #123
Fixes #123
Resolves #123

Release Notes

markdown
## Version 2.0.0

### Features
- Add user authentication (#456)
- Add payment gateway (#457)
- Improve dashboard performance (#458)

### Bug Fixes
- Fix login error (#459)
- Fix memory leak (#460)

### Breaking Changes
- API endpoint renamed from `/users` to `/accounts`

PR Lifecycle Checklist

Before Creating PR

markdown
## Pre-PR Checklist

- [ ] Branch created from main/master
- [ ] Branch name follows convention
- [ ] Commits are atomic and focused
- [ ] Commit messages are clear
- [ ] Code is tested locally
- [ ] All tests pass
- [ ] No debug code left
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] Related issue referenced

During Review

markdown
## Review Checklist

- [ ] Automated checks pass
- [ ] Code reviewers assigned
- [ ] Reviewers notified
- [ ] PR description is complete
- [ ] Screenshots included (if UI changes)
- [ ] Breaking changes documented
- [ ] Migration guide provided (if needed)
- [ ] Performance impact considered
- [ ] Security implications reviewed

Before Merging

markdown
## Merge Checklist

- [ ] All reviewers approved
- [ ] All automated checks pass
- [ ] All review comments addressed
- [ ] No merge conflicts
- [ ] Branch is up to date with main
- [ ] Related issue linked
- [ ] Release notes updated
- [ ] Documentation reviewed
- [ ] Ready for deployment

After Merge

markdown
## Post-Merge Checklist

- [ ] Feature branch deleted
- [ ] Related issue closed
- [ ] Release notes updated
- [ ] Team notified
- [ ] Deployment scheduled
- [ ] Monitoring configured
- [ ] Follow-up issues created (if needed)

Quick Reference

GitHub CLI Commands

bash
# Create PR
gh pr create --title "feat: Add feature" --body "Description"

# View PR status
gh pr view 123

# List open PRs
gh pr list --state open

# Add reviewer
gh pr edit 123 --add-reviewer @username

# Approve PR
gh pr review 123 --approve

# Request changes
gh pr review 123 --request-changes

# Comment on PR
gh pr comment 123 --body "Looks good!"

# Merge PR
gh pr merge 123 --squash --delete-branch

# Reopen PR
gh pr reopen 123

# Close PR
gh pr close 123 --comment "No longer needed"

# Checkout PR locally
gh pr checkout 123

PR Labels

LabelUsage
ready for reviewPR is ready for review
needs workPR needs changes before merge
wipWork in progress
do not mergeDo not merge yet
breaking changeContains breaking changes
documentationDocumentation changes only
dependenciesDependency updates
bugBug fix
enhancementNew feature
refactorCode refactoring
testsTest updates

PR Status Checks

CheckDescription
CI/CDContinuous integration pipeline
TestsUnit and integration tests
LintCode quality checks
SecuritySecurity vulnerability scan
BuildBuild verification
CoverageCode coverage threshold

Lifecycle Metrics

MetricTargetHow to Track
PR size< 400 linesLines changed per PR
Review time< 24 hoursTime to first review
Merge time< 48 hoursTime to merge
Approval rate> 90%PRs approved on first pass
Reopen rate< 5%PRs reopened after merge

Common Pitfalls

  1. Large PRs - Keep PRs small and focused for easier review
  2. Poor descriptions - Always provide clear context and testing notes
  3. Not self-reviewing - Review your own code before requesting others
  4. Ignoring conflicts - Resolve merge conflicts promptly
  5. Forcing merges - Wait for all approvals and checks
  6. Not cleaning branches - Delete merged branches to keep repo clean
  7. Missing context - Link related issues and provide background
  8. Breaking changes without notice - Always document breaking changes

Additional Resources