Add /pr command for quick PR creation from current branch

Creates a lighter-weight PR creation flow for when you're already on a
branch with commits. Features:
- Auto-generates title from branch name or commits
- Auto-generates description summarizing changes
- Links to related issue if branch name contains issue number
- Triggers code-reviewer agent after PR creation

Closes #19

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit was merged in pull request #80.
This commit is contained in:
2026-01-10 19:19:16 +01:00
parent 6dd760fffd
commit 110c3233be

147
commands/pr.md Normal file
View File

@@ -0,0 +1,147 @@
---
description: Create a PR from current branch. Auto-generates title and description from branch name and commits.
---
# Create Pull Request
@~/.claude/skills/gitea/SKILL.md
Quick PR creation from current branch - lighter than full `/work-issue` flow for when you're already on a branch with commits.
## Prerequisites
- Current branch is NOT main/master
- Branch has commits ahead of main
- Changes have been pushed to origin (or will be pushed)
## Process
### 1. Verify Branch State
```bash
# Check current branch
git branch --show-current
# Ensure we're not on main
# If on main, abort with message: "Cannot create PR from main branch"
# Check for commits ahead of main
git log main..HEAD --oneline
```
### 2. Push if Needed
```bash
# Check if branch is tracking remote
git status -sb
# If not pushed or behind, push with upstream
git push -u origin <branch-name>
```
### 3. Generate PR Title
**Option A: Branch contains issue number** (e.g., `issue-42-add-feature`)
Extract issue number and use format: `[Issue #<number>] <issue-title>`
```bash
tea issues <number> # Get the actual issue title
```
**Option B: No issue number**
Generate from branch name or recent commit messages:
- Convert branch name from kebab-case to title case: `add-user-auth` -> `Add user auth`
- Or use the most recent commit subject line
### 4. Generate PR Description
Analyze the diff and commits to generate a description:
```bash
# Get diff against main
git diff main...HEAD --stat
# Get commit messages
git log main..HEAD --format="- %s"
```
Structure the description:
```markdown
## Summary
[1-2 sentences describing the overall change]
## Changes
[Bullet points summarizing commits or key changes]
[If issue linked: "Closes #<number>"]
```
### 5. Create PR
Use tea CLI to create the PR:
```bash
tea pulls create --title "<generated-title>" --description "<generated-description>"
```
Capture the PR number from the output (e.g., "Pull Request #42 created").
### 6. Auto-review
Inform the user that auto-review is starting, then spawn the `code-reviewer` agent in background:
```
Task tool with:
- subagent_type: "code-reviewer"
- run_in_background: true
- prompt: |
Review PR #<PR_NUMBER> in the repository at <REPO_PATH>.
1. Checkout the PR: tea pulls checkout <PR_NUMBER>
2. Get the diff: git diff main...HEAD
3. Analyze for code quality, bugs, security, style, test coverage
4. Post structured review comment with tea comment
5. Merge with rebase if LGTM, otherwise leave for user
```
### 7. Display Result
Show the user:
- PR URL/number
- Generated title and description
- Status of auto-review (spawned in background)
## Issue Linking
To detect if branch is linked to an issue:
1. Check branch name for patterns:
- `issue-<number>-*`
- `<number>-*`
- `*-#<number>`
2. If issue number found:
- Fetch issue title from Gitea
- Use `[Issue #N] <issue-title>` format for PR title
- Add `Closes #N` to description
## Example Output
```
Created PR #42: [Issue #15] Add /pr command
## Summary
Adds /pr command for quick PR creation from current branch.
## Changes
- Add commands/pr.md with auto-generation logic
- Support issue linking from branch name
Closes #15
---
Auto-review started in background. Check status with: tea pulls 42 --comments
```