---
name: pr-draft
description: >
  Generates a PR title and description from the current branch's commits and diff.
  Triggers: /pr-draft, PR 만들어줘, PR 초안, pull request 작성, pr draft
---

# PR Draft Generator

Reads branch history + diff → generates PR title and body matching the project's template → optionally creates the PR.

## Procedure

### Step 1 — Read branch context

Run in parallel:
```bash
git branch --show-current
git log main..HEAD --oneline
git diff main..HEAD --stat
```

If no commits ahead of main, tell the user and stop.

### Step 2 — Detect base branch

Check if `main` or `master` or `develop` exists. Use the most likely base.

### Step 3 — Read project PR template

Check `.github/PULL_REQUEST_TEMPLATE.md` — if it exists, use it as the body structure.

Also check project CLAUDE.md for:
- PR title format
- Language (Korean or English)

### Step 4 — Read the diff (if small enough)

```bash
git diff main..HEAD
```

Only read if `--stat` shows ≤ 300 lines changed. If larger, rely on commit messages.

### Step 5 — Generate PR content

**Title:** Follow project format. If issue-based: `[#이슈번호] {이슈 제목}`. If conventional: `feat: {summary}`

**Body:** Fill in the PR template sections. If no template:
```markdown
## 변경 사항
- {bullet points of what changed}

## 이유
{why this change was needed}

## 테스트
- [ ] {key test scenarios}
```

### Step 6 — Confirm and optionally create

Show the draft and ask:
```
PR 초안:

제목: {title}

{body}

---
GitHub에 PR을 생성할까요? (y/n)
```

On confirm:
```bash
gh pr create --title "{title}" --body "$(cat <<'EOF'
{body}
EOF
)"
```

### Step 7 — Report

Return the PR URL, then output:

```
## 사람이 확인해야 할 것
- [ ] PR 범위가 이슈 하나에 해당하는지 (너무 크지 않은지)
- [ ] 테스트 체크리스트가 실제로 실행 가능한지
- [ ] base branch가 올바른지 (main vs develop vs feature)
- [ ] 민감한 변경사항(인증, 결제, DB 스키마)이 있으면 별도 리뷰어 지정 필요
```

## Notes

- Never push to main/master directly
- If the branch isn't pushed yet, run `git push -u origin {branch}` first
- Only add `--assignee`, `--reviewer`, `--label` when the user requests them
