Generate a PR description and open a pull request. Use when the user says /openpr, asks to open a PR, create a pull request, or push and open a PR. Triggers: openpr, open pr, pull request, create pr, push and pr.
Generate a comprehensive pull request description based on all commits on the current branch (compared to the default base branch), then open the PR using the GitHub CLI (gh).
# Try to detect the default branch (main or master)
git remote show origin | grep "HEAD branch" | awk '{print $NF}'
Store the result as BASE_BRANCH.
git branch --show-current
Store the result as CURRENT_BRANCH. If the current branch is the same as BASE_BRANCH, stop and inform the user they need to be on a feature branch.
git log ${BASE_BRANCH}..${CURRENT_BRANCH} --pretty=format:"%h %s" --reverse
This gives the list of all commits on this branch that are not on the base branch, in chronological order.
git diff ${BASE_BRANCH}...${CURRENT_BRANCH} --stat
This gives a summary of files changed, insertions, and deletions.
If the diff is small enough (under ~2000 lines), also read the full diff for richer context:
git diff ${BASE_BRANCH}...${CURRENT_BRANCH}
If the diff is too large, rely on the commit messages and --stat output only.
Add user authentication flow, Fix race condition in job scheduler, Refactor database connection pooling.Use the following markdown template. Fill in every section thoughtfully based on the commits and diff:
## Summary
<!-- 2-4 sentence high-level overview of what this PR does and why -->
## Changes
<!-- Grouped list of meaningful changes. Group by area/theme, not by commit.
Each item should describe WHAT changed and WHY, not just repeat commit messages. -->
- **Area/Module**: Description of change
- **Area/Module**: Description of change
## How to Test
<!-- Step-by-step instructions a reviewer can follow to verify the changes work -->
1. Step one
2. Step two
## Notes for Reviewers
<!-- Optional: anything reviewers should pay attention to, open questions,
trade-offs made, or follow-up work planned -->
Guidelines for the description:
Before opening the PR, display the generated title and description to the user and ask for confirmation or edits.
Once confirmed:
# Ensure the branch is pushed
git push -u origin ${CURRENT_BRANCH}
# Open the PR via GitHub CLI
gh pr create --title "<GENERATED_TITLE>" --body "<GENERATED_DESCRIPTION>" --base ${BASE_BRANCH}
If gh is not installed or not authenticated, inform the user and provide the generated title and description so they can copy/paste it manually.
After the PR is created, display the PR URL to the user.
/openpr draft, add the --draft flag to gh pr create.gh pr view --json url.git (required)gh — GitHub CLI (required for automatic PR creation; graceful fallback if missing)User input:
/openpr
User input (draft):
/openpr draft