# /pr — Commit, Push & Create Pull Request

One-command shipping: commit all changes, push to remote, create a GitHub PR.

## Usage

```
/pr                        # Auto-generate everything
/pr "description"          # Use custom PR description
```

**Examples:**
- `/pr`
- `/pr "Add Stripe webhook handler for subscription events"`

## Workflow

### Step 1: Pre-flight Checks
1. Verify not on main/master:
   ```bash
   git branch --show-current
   ```
   **REFUSE if on main/master**
2. Check for changes:
   ```bash
   git status
   git diff --staged
   git diff
   ```
3. Check for sensitive files — warn if found
4. Check if branch has a remote tracking branch:
   ```bash
   git rev-parse --abbrev-ref @{upstream} 2>/dev/null
   ```

### Step 2: Commit
1. Stage specific changed files (not `git add .`)
2. Analyze changes and generate conventional commit message
3. Create commit with Co-Authored-By trailer
4. If there are multiple logical changes, ask user if they want separate commits

### Step 3: Push
1. Push to remote with upstream tracking:
   ```bash
   git push -u origin $(git branch --show-current)
   ```
2. If push fails (e.g., diverged), report error and suggest resolution

### Step 4: Create PR
1. Check if a PR already exists for this branch:
   ```bash
   gh pr view 2>/dev/null
   ```
   If PR exists, update it instead of creating a new one
2. Generate PR title and body:
   - Title: short, under 70 characters
   - Body: structured with Summary and Test Plan
3. Analyze ALL commits on the branch (not just latest):
   ```bash
   git log main..HEAD --oneline
   git diff main...HEAD
   ```
4. Create the PR:
   ```bash
   gh pr create --title "<title>" --body "$(cat <<'EOF'
   ## Summary
   - <bullet points>

   ## Test plan
   - [ ] <testing checklist>

   Generated with Claude Code
   EOF
   )"
   ```
5. Report the PR URL to the user

## Key Rules
- NEVER push to main/master
- NEVER commit .env files or secrets
- Always analyze ALL commits on the branch for PR description
- If PR already exists, update instead of creating duplicate
- Keep PR title under 70 characters
- Include test plan in PR body
