/laravel-agent:git:pr
Create pull request with auto-generated description and review
Overview
The /git:pr command creates a pull request with an automatically generated description based on your commits and code changes. It includes an optional code review step to ensure quality before submission, and automatically handles branch validation, commit analysis, and PR creation with proper formatting.
Usage
/laravel-agent:git:pr [--base=branch] [--draft] [--no-review]
Examples
# Create PR to develop (default)
/laravel-agent:git:pr
# Create PR to main branch
/laravel-agent:git:pr --base=main
# Create a draft PR
/laravel-agent:git:pr --draft
# Create PR without code review
/laravel-agent:git:pr --no-review
Options
- --base=branch - Specify the target branch (default: develop)
- --draft - Create the PR as a draft
- --no-review - Skip the automated code review step
Process Flow
The command follows a structured process to ensure high-quality pull requests:
1. Validate Branch State
Before creating a PR, the command validates your current branch state:
- Ensures you're not on main or develop branches
- Checks for uncommitted changes (must be clean)
- Identifies unpushed commits
- Verifies branch is ready for PR creation
# Check current branch
current_branch=$(git branch --show-current)
# Ensure not on main/develop
if [[ "$current_branch" == "main" || "$current_branch" == "develop" ]]; then
echo "Cannot create PR from $current_branch"
exit 1
fi
# Check for unpushed commits
unpushed=$(git log @{u}.. --oneline 2>/dev/null)
# Check for uncommitted changes
if [ -n "$(git status --porcelain)" ]; then
echo "Uncommitted changes detected. Commit or stash first."
exit 1
fi
2. Gather Commit History
The command analyzes all commits since your branch diverged from the base branch:
# Get base branch (default: develop)
base_branch=${BASE:-develop}
# Get all commits since branching
git log $base_branch..HEAD --oneline
# Get detailed changes
git log $base_branch..HEAD --pretty=format:"- %s" --no-merges
3. Run Code Review
Unless --no-review is specified, the command runs an automated code review:
/review:pr $current_branch
# Results used for PR description
4. Generate PR Description
A comprehensive PR description is automatically generated including:
- Summary of changes from commit messages and branch name
- List of all commits with proper formatting
- Files changed with statistics
- Code review results (security, quality, tests)
- Testing instructions and checklist
- Related issues and tickets
5. Create and Configure PR
The command creates the PR and applies additional configuration:
# Push branch if needed
if [ -n "$(git log @{u}.. --oneline 2>/dev/null)" ]; then
git push -u origin $current_branch
fi
# Create PR
gh pr create \
--base "$base_branch" \
--title "" \
--body "$(cat pr-description.md)" \
${DRAFT:+--draft}
6. Post-Create Actions
After PR creation, the command adds metadata:
# Add reviewers (from CODEOWNERS or config)
gh pr edit --add-reviewer
# Add labels based on changes
gh pr edit --add-label "feature" # or "bug", "refactor", etc.
# Link to project board if configured
gh pr edit --add-project "Sprint Board"
Generated PR Description Format
The command generates a comprehensive PR description following this structure:
## Summary
### What does this PR do?
-
### Why is this change needed?
-
## Changes
- feat(invoice): add PDF export service
- feat(invoice): add export endpoint
- test(invoice): add PDF generation tests
## Files Changed
| File | Changes |
|------|---------|
| app/Services/InvoiceService.php | +45 -12 |
| app/Http/Controllers/InvoiceController.php | +23 -5 |
| tests/Feature/InvoiceTest.php | +67 -0 |
## Code Review
### Security
- Status: PASSED
- Issues: None
### Quality
- Status: 2 suggestions
- Suggestions:
- Consider adding index to `invoices.user_id`
- Extract PDF configuration to config file
### Tests
- Coverage: 85%
- New tests: 3
## Testing
### How to test
1.
2.
### Checklist
- [ ] Tests pass locally
- [ ] Manual testing completed
- [ ] Documentation updated (if needed)
## Screenshots
## Related
- Closes #
- Related to #
PR Templates
The command uses different templates based on the type of changes:
Feature PR Template
## Feature:
### What
### Why
### How
Bug Fix PR Template
## Bug Fix:
### Problem
### Root Cause
### Solution
### Verification
Hotfix PR Template
## HOTFIX:
### Severity
CRITICAL / HIGH
### Impact
### Fix
### Rollback Plan
Example Output
After successful PR creation, you'll receive a summary:
## Pull Request Created
**URL:** https://github.com/org/repo/pull/123
**Title:** feat(invoice): add PDF export functionality
**Base:** develop ← feature/invoice-pdf-export
**Review Status:**
- Security: PASSED
- Quality: 2 suggestions (non-blocking)
- Tests: PASSED
**Next Steps:**
1. Address review suggestions (optional)
2. Wait for CI checks
3. Request team review
4. Merge when approved
Example PR Creation Flow
Here's a complete example of creating a feature PR:
# 1. You've been working on a feature branch
git checkout -b feature/invoice-pdf-export
# 2. Made several commits
git commit -m "feat(invoice): add PDF export service"
git commit -m "feat(invoice): add export endpoint"
git commit -m "test(invoice): add PDF generation tests"
# 3. Create PR with automated review
/laravel-agent:git:pr
# Command will:
# - Validate your branch is ready
# - Analyze all 3 commits
# - Run code review on changes
# - Generate comprehensive PR description
# - Push branch if needed
# - Create PR on GitHub
# - Add reviewers and labels
# - Return PR URL
Integration with Code Review
By default, the command integrates with the /review:pr command to provide:
- Security Analysis - Checks for common vulnerabilities
- Code Quality - Identifies potential improvements
- Test Coverage - Verifies adequate testing
- Best Practices - Ensures Laravel conventions
These results are automatically included in the PR description to help reviewers.
Best Practices
- Write clear commit messages - They're used to generate the PR description
- Follow conventional commits - Use prefixes like feat:, fix:, refactor:
- Keep PRs focused - One feature or fix per PR
- Run review before creating - Don't skip the review step
- Add screenshots - Include them when UI changes are made
- Link related issues - Reference ticket numbers in commits
- Test locally first - Ensure tests pass before creating PR
- Use draft PRs - For work-in-progress that needs early feedback
Common Scenarios
Creating a Feature PR
# Create PR with full review to develop
/laravel-agent:git:pr
Creating a Hotfix PR
# Create urgent PR directly to main
/laravel-agent:git:pr --base=main
Creating a WIP PR
# Create draft PR for early feedback
/laravel-agent:git:pr --draft
Quick PR Without Review
# Skip review for minor changes
/laravel-agent:git:pr --no-review
Requirements
- GitHub CLI - The
ghcommand must be installed and authenticated - Git Repository - Must be in a git repository with a remote
- Clean Working Tree - All changes must be committed
- Feature Branch - Cannot create PR from main or develop
Troubleshooting
Cannot create PR from main/develop
You must be on a feature branch. Create a new branch first:
git checkout -b feature/my-feature
Uncommitted changes detected
Commit or stash your changes before creating a PR:
git add .
git commit -m "feat: your changes"
GitHub CLI not authenticated
Authenticate with GitHub CLI:
gh auth login
Related Commands
- /laravel-agent:review:pr - Run code review on PR
- /laravel-agent:git:commit - Create semantic commits
- /laravel-agent:test:run - Run tests before PR