Create Pull Request
Create a GitHub pull request with validation, template support, and Jira integration.
Instructions
Step 1: Verify Pre-commit Hooks
First, check if pre-commit hooks or linters are configured and run them:
# Check for pre-commit config if [ -f ".pre-commit-config.yaml" ]; then pre-commit run --all-files elif [ -f "Makefile" ] && grep -q "lint" Makefile; then make lint elif [ -f "package.json" ] && grep -q '"lint"' package.json; then npm run lint 2>/dev/null || pnpm run lint 2>/dev/null || yarn lint 2>/dev/null fi
If hooks fail due to environment issues (Docker not running, missing tools, etc.):
Use AskUserQuestion with these options:
- •"Skip verification" - Proceed without running hooks
- •"Block and fix" - Stop PR creation until issues are resolved
If "Block and fix" is selected, help the user fix the issues and re-run. Do NOT proceed until verification passes or user explicitly skips.
Step 2: Get Branch Context
# Get current branch git branch --show-current # Get commits unique to this branch (not on main/master) git log origin/main..HEAD --oneline 2>/dev/null || git log origin/master..HEAD --oneline # Get full commit messages for Jira extraction git log origin/main..HEAD --format="%s%n%b" 2>/dev/null || git log origin/master..HEAD --format="%s%n%b"
Step 3: Extract Jira Ticket
Look for Jira ticket patterns in commit messages:
- •Pattern:
[A-Z]{2,}-[0-9]+(e.g.,PROJ-123,ABC-4567) - •Check commit subjects and bodies
- •If multiple tickets found, use the most frequently mentioned one
- •Store the ticket ID for use in title and description
Step 4: Check for PR Template
# Check for PR template if [ -f ".github/PULL_REQUEST_TEMPLATE.md" ]; then cat .github/PULL_REQUEST_TEMPLATE.md elif [ -f ".github/pull_request_template.md" ]; then cat .github/pull_request_template.md elif [ -f "docs/PULL_REQUEST_TEMPLATE.md" ]; then cat docs/PULL_REQUEST_TEMPLATE.md fi
If a template exists, parse it and fill in each section based on:
- •The commits on the branch
- •Changed files (
git diff --stat origin/main...HEAD) - •Any Jira ticket found
Step 5: Ask Draft vs Ready
Use AskUserQuestion with the prompt:
"How should the PR be created?"
Options (in this order):
- •"Draft" - Create as draft PR (default, most common)
- •"Ready for review" - Create as ready for review immediately
Step 6: Generate PR Title
Format the title:
- •If Jira ticket found:
[TICKET-123] Brief description from branch/commits - •If no ticket: Just the description from branch name or commits
The title should be concise (under 72 chars) and describe the change.
Step 7: Generate PR Description
If a template was found, fill it out. Otherwise, generate:
## Summary [Brief description of changes based on commits] ## Changes [List of main changes from commits] ## Related [Jira ticket link if found: https://yourcompany.atlassian.net/browse/TICKET-123]
Step 8: Create the PR
# Create draft PR gh pr create --draft --title "TITLE" --body "BODY" # OR for ready PR gh pr create --title "TITLE" --body "BODY"
Step 9: Output
After successful creation:
PR created successfully! [PR URL from gh output] Title: [title] Status: Draft / Ready for Review Jira: [ticket if found, or "None detected"]
If creation fails, show the error and help troubleshoot.