Debian Codegraph @

.claude/skills/pr/SKILL.md

raw symbols SCIP
1 ---
2 name: pr
3 description: Prepare outstanding commits on a feature branch for a pull request to upstream
4 ---
5
6 Prepare a pull request from the current feature branch. This skill collects all commits on the current branch that are ahead of `upstream/main`, generates a PR title and description summarizing the changes, and creates the PR against `upstream`.
7
8 ## Arguments
9
10 The skill accepts optional arguments:
11 - No arguments: auto-generate title and description from commits
12 - A short description: used as the PR title (e.g., `/pr Add support for TLS client certs`)
13
14 Example: `/pr` or `/pr Fix saturation search convergence`
15
16 ## Steps
17
18 1. **Verify prerequisites**:
19 - Must NOT be on `main` branch (should be on a feature branch)
20 - The `upstream` remote must exist
21 - The `origin` remote must exist
22
23 ```bash
24 BRANCH=$(git branch --show-current)
25 if [ "$BRANCH" = "main" ]; then
26 echo "Error: Must be on a feature branch, not main"
27 exit 1
28 fi
29 git remote get-url upstream >/dev/null 2>&1 || { echo "Error: 'upstream' remote not found"; exit 1; }
30 git remote get-url origin >/dev/null 2>&1 || { echo "Error: 'origin' remote not found"; exit 1; }
31 ```
32
33 2. **Run `cargo fmt`** and amend the last commit if formatting changes are needed:
34 ```bash
35 cargo fmt
36 if [ -n "$(git status --porcelain)" ]; then
37 git add -u
38 git commit --amend --no-edit
39 fi
40 ```
41
42 After this step, the working directory must be clean. If there are still uncommitted changes (non-formatting), stop and tell the user to commit or stash them first.
43
44 3. **Sync with upstream**:
45 ```bash
46 git fetch upstream
47 git fetch origin
48 ```
49
50 4. **Identify commits for the PR**:
51 - Find the merge base between the current branch and `upstream/main`
52 - List all commits from the merge base to HEAD
53 - Show the full diff against `upstream/main`
54
55 ```bash
56 MERGE_BASE=$(git merge-base upstream/main HEAD)
57 git log --oneline ${MERGE_BASE}..HEAD
58 git diff ${MERGE_BASE}..HEAD --stat
59 ```
60
61 If there are no commits ahead of upstream/main, stop and tell the user there is nothing to submit.
62
63 5. **Generate PR title and description**:
64 - If the user provided a title argument, use that as the PR title
65 - Otherwise, analyze the commits and diff to generate a concise PR title (under 70 characters)
66 - Generate the PR body with:
67 - A `## Summary` section with 1-3 bullet points describing the changes
68 - A `## Changes` section listing the commits
69 - A `## Test plan` section with a checklist of testing suggestions
70
71 Present the title and body to the user for review before creating the PR.
72
73 6. **Push the feature branch to origin**:
74 ```bash
75 BRANCH=$(git branch --show-current)
76 git push -u origin ${BRANCH}
77 ```
78
79 7. **Create the PR against upstream**:
80 ```bash
81 BRANCH=$(git branch --show-current)
82
83 gh pr create \
84 --repo "$(git remote get-url upstream | sed 's/.*github.com[:/]\(.*\)\.git/\1/' | sed 's/.*github.com[:/]\(.*\)/\1/')" \
85 --head "$(git remote get-url origin | sed 's/.*github.com[:/]\(.*\)\.git/\1/' | sed 's/.*github.com[:/]\(.*\)/\1/' | cut -d/ -f1):${BRANCH}" \
86 --base main \
87 --title "${PR_TITLE}" \
88 --body "${PR_BODY}"
89 ```
90
91 8. **Report the PR URL** to the user.
92
93 ## Troubleshooting
94
95 - **No `upstream` remote**: Add it with `git remote add upstream <repo-url>`
96 - **No `origin` remote**: This is your fork. Add with `git remote add origin <fork-url>`
97 - **gh CLI not installed**: `brew install gh` or see https://cli.github.com/
98 - **Not authenticated with gh**: `gh auth login`
99 - **PR already exists**: If a PR already exists for this branch, report the existing PR URL instead