|
| 1 | +--- |
| 2 | +description: Create a PR on GitHub for the current branch |
| 3 | +argument_hint: "[branch] [--dry] [--draft]" |
| 4 | +allowed_tools: Bash, Read, Glob, Grep, Write, AskUserQuestion, mcp__github__create_pull_request, mcp__github__list_pull_requests, mcp__github__get_file_contents, mcp__github__issue_read |
| 5 | +--- |
| 6 | + |
| 7 | +Create a PR on GitHub using the `gh` CLI for the currently checked-out branch. |
| 8 | + |
| 9 | +**Examples:** |
| 10 | +- `/pr` - Interactive mode, prompts for PR type |
| 11 | +- `/pr master` - Interactive with explicit base branch |
| 12 | +- `/pr --dry` - Generate description only, save to `.ai/` |
| 13 | +- `/pr --draft` - Create as draft PR |
| 14 | +- `/pr develop --draft` - Draft PR against develop branch |
| 15 | + |
| 16 | +## Steps |
| 17 | + |
| 18 | +### 1. Check for Existing PR |
| 19 | +Run `gh pr view --json number,url 2>/dev/null` to check if a PR already exists for this branch. |
| 20 | +- If PR exists: Output `PR already exists: [URL]` and stop |
| 21 | +- If no PR: Continue |
| 22 | + |
| 23 | +### 2. Parse Arguments |
| 24 | +- `--dry`: Skip PR creation, only generate and save description |
| 25 | +- `--draft`: Create PR as draft |
| 26 | +- First non-flag argument: base branch (default: `master`) |
| 27 | +- **If no flags provided**: Use `AskUserQuestion` to prompt user: |
| 28 | + - Open PR (create and publish) |
| 29 | + - Draft PR (create as draft) |
| 30 | + - Dry run (save locally only) |
| 31 | + |
| 32 | +### 3. Gather Context |
| 33 | +- Get current branch name: `git branch --show-current` |
| 34 | +- Read PR template from `.github/pull_request_template.md` |
| 35 | +- Fetch 10 most recent PRs (open or closed) from `synonymdev/bitkit-android` for writing style reference |
| 36 | +- Run `git log $base..HEAD --oneline` for commit messages |
| 37 | +- Run `git diff $base...HEAD --stat` for understanding scope of changes |
| 38 | + |
| 39 | +### 4. Extract Linked Issues |
| 40 | +Scan commits for issue references: |
| 41 | +- Pattern to match: `#123` (just the issue number reference) |
| 42 | +- Extract unique issue numbers: `git log $base..HEAD --oneline | grep -oE "#[0-9]+" | sort -u` |
| 43 | +- Fetch each issue title: `gh api "repos/synonymdev/bitkit-android/issues/NUMBER" --jq '.title'` |
| 44 | +- These will be used to start the PR description with linking keywords (see Step 6) |
| 45 | + |
| 46 | +### 5. Identify Suggested Reviewers |
| 47 | +Find potential reviewers based on: |
| 48 | +- `.github/CODEOWNERS` file patterns (if exists) |
| 49 | +- Recent contributors to changed files: `git log --format='%an' -- $(git diff $base..HEAD --name-only) | sort | uniq -c | sort -rn | head -3` |
| 50 | +- Exclude the current user from suggestions |
| 51 | + |
| 52 | +### 6. Generate PR Description |
| 53 | +Starting from the template in `.github/pull_request_template.md`: |
| 54 | + |
| 55 | +**Title Rules:** |
| 56 | +- Format: `prefix: title` (e.g., `feat: add user settings screen`) |
| 57 | +- Keep under 50 characters |
| 58 | +- Use branch name as concept inspiration |
| 59 | +- Prefixes: `feat`, `fix`, `chore`, `refactor`, `docs`, `test` |
| 60 | + |
| 61 | +**Issue Linking (at the very start):** |
| 62 | +If linked issues were found in commit messages, begin the PR description with linking keywords: |
| 63 | +- Use `Fixes #123` for bug fixes |
| 64 | +- Use `Closes #123` for features/enhancements |
| 65 | +- One per line, before the "This PR..." opening separated by one empty line |
| 66 | +- Reference: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests |
| 67 | + |
| 68 | +Example: |
| 69 | +``` |
| 70 | +Fixes #528 |
| 71 | +Closes #418 |
| 72 | +
|
| 73 | +This PR adds support for... |
| 74 | +``` |
| 75 | + |
| 76 | +**Opening Format:** |
| 77 | +- Single change: Start with "This PR [verb]s..." as a complete sentence |
| 78 | + - Example: `This PR adds a Claude Code /pr command for generating PRs.` |
| 79 | +- Multiple changes: Start with "This PR:" followed by a numbered list |
| 80 | + - Example: |
| 81 | + ``` |
| 82 | + This PR: |
| 83 | +
|
| 84 | + 1. Adds a Claude Code /pr command for generating PRs |
| 85 | + 2. Fixes issue preventing Claude Code reviews to be added as PR comments |
| 86 | + 3. Updates reviews workflow to minimize older review comments |
| 87 | + ``` |
| 88 | +- Each list item should start with a verb (Adds, Fixes, Updates, Removes, Refactors, etc.) |
| 89 | +
|
| 90 | +**Description Rules:** |
| 91 | +- Base content around all commit messages in the branch |
| 92 | +- Use branch name as the conceptual anchor |
| 93 | +- Match writing style of recent PRs |
| 94 | +- Focus on functionality over technical details |
| 95 | +- Avoid excessive bold formatting like `**this:** that` |
| 96 | +- Minimize code references like `TheClassName` or `someFunctionName` |
| 97 | +- Exception: for refactoring PRs (1:10 ratio of functionality to code changes), more technical detail is ok |
| 98 | +
|
| 99 | +**QA Notes / Testing Scenarios:** |
| 100 | +- Structure with numbered headings and steps |
| 101 | +- Make steps easily referenceable |
| 102 | +- Be specific about what to test and expected outcomes |
| 103 | +
|
| 104 | +**Preview Section:** |
| 105 | +- Create placeholders for media: `IMAGE_1`, `VIDEO_2`, etc. |
| 106 | +- Add code comment under each placeholder describing what it should show |
| 107 | +- Example: `<!-- VIDEO_1: Record the send flow by scanning a LN invoice and setting amount to 5000 sats -->` |
| 108 | +
|
| 109 | +### 7. Save PR Description |
| 110 | +Before creating the PR: |
| 111 | +- Get next PR number: `gh api "repos/synonymdev/bitkit-android/issues?per_page=1&state=all&sort=created&direction=desc" --jq '.[0].number'` then add 1 |
| 112 | +- Create `.ai/` directory if it doesn't exist |
| 113 | +- Save to `.ai/pr_NN.md` where `NN` is the predicted PR number |
| 114 | +
|
| 115 | +### 8. Create the PR (unless --dry) |
| 116 | +If not dry run: |
| 117 | +```bash |
| 118 | +gh pr create --base $base --title "..." --body "..." [--draft] |
| 119 | +``` |
| 120 | +- Add `--draft` flag if draft mode selected |
| 121 | +- If actual PR number differs from predicted, rename the saved file |
| 122 | + |
| 123 | +### 9. Output Summary |
| 124 | + |
| 125 | +**If PR created:** |
| 126 | +``` |
| 127 | +PR Created: [PR URL] |
| 128 | +Saved: .ai/pr_NN.md |
| 129 | +
|
| 130 | +Suggested reviewers: |
| 131 | +- @username1 (X files modified recently) |
| 132 | +- @username2 (CODEOWNER) |
| 133 | +
|
| 134 | +## TODOs |
| 135 | +- [ ] IMAGE_1: [description] |
| 136 | +- [ ] VIDEO_2: [description] |
| 137 | +``` |
| 138 | + |
| 139 | +**If dry run:** |
| 140 | +``` |
| 141 | +Dry run complete |
| 142 | +Saved: .ai/pr_NN.md |
| 143 | +
|
| 144 | +To create PR: /pr [--draft] |
| 145 | +
|
| 146 | +Suggested reviewers: |
| 147 | +- @username1 (X files modified recently) |
| 148 | +- @username2 (CODEOWNER) |
| 149 | +
|
| 150 | +## TODOs |
| 151 | +- [ ] IMAGE_1: [description] |
| 152 | +- [ ] VIDEO_2: [description] |
| 153 | +``` |
| 154 | + |
| 155 | +List all media placeholders as TODOs with their descriptions. |
0 commit comments