|
| 1 | +--- |
| 2 | +name: create-pr |
| 3 | +description: Create a pull request with Conventional Commits formatting, a templated body, and local verification. Use when the user asks to create a PR, open a PR, submit changes for review, or put code up for review. |
| 4 | +--- |
| 5 | + |
| 6 | +# Create Pull Request |
| 7 | + |
| 8 | +Create a PR with proper conventions: local verification, Conventional Commits title, a templated body, and an optional linked ticket. |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +Before starting, verify: |
| 13 | +1. Current branch has commits not on the base branch (`git log origin/<base-branch>..HEAD --oneline`) |
| 14 | +2. Branch is pushed to remote (`git push -u origin HEAD` if not) |
| 15 | +3. No uncommitted changes that should be included (`git status`) |
| 16 | + |
| 17 | +## Workflow |
| 18 | + |
| 19 | +### 1. Understand the Changes |
| 20 | + |
| 21 | +Run in parallel: |
| 22 | +```bash |
| 23 | +git log origin/<base-branch>..HEAD --oneline |
| 24 | +git diff origin/<base-branch>..HEAD --stat |
| 25 | +``` |
| 26 | + |
| 27 | +Determine: |
| 28 | +- **What changed**: Which apps/packages were modified |
| 29 | +- **Change type**: `feat`, `fix`, `docs`, `refactor`, `test`, `chore`, `perf`, `ci`, `build`, `revert` |
| 30 | +- **Scope**: Primary workspace affected (use directory name or `monorepo` for cross-cutting changes) |
| 31 | +- **Is this a code change?**: If the PR modifies code (not only docs, markdown, or config-only changes), run the local verification checklist in step 2 before creating the PR. |
| 32 | + |
| 33 | +### 2. Local Verification (for code changes) |
| 34 | + |
| 35 | +**Skip this step** if the PR only touches documentation, markdown files, or other non-code files. For any change that touches `.ts`, `.tsx`, `.js`, `.jsx`, `.css`, or similar source files, run these checks locally before creating the PR. |
| 36 | + |
| 37 | +Use a filter flag (turbo `--filter`, nx `--projects`, pnpm `--filter`) to target only the affected workspaces when possible — it is faster than running the whole repo. |
| 38 | + |
| 39 | +#### Typecheck |
| 40 | +```bash |
| 41 | +# Repo-wide |
| 42 | +npm run typecheck |
| 43 | +# Filtered to affected workspaces (preferred — faster) |
| 44 | +npm run typecheck -- --filter=<workspace1> --filter=<workspace2> |
| 45 | +``` |
| 46 | + |
| 47 | +#### Lint |
| 48 | +```bash |
| 49 | +# Autofix (preferred — fixes formatting + lint in one pass) |
| 50 | +npm run fix |
| 51 | +# Or filtered |
| 52 | +npm run fix -- --filter=<workspace> |
| 53 | +# Lint-only (no autofix) |
| 54 | +npm run lint |
| 55 | +``` |
| 56 | + |
| 57 | +#### Tests |
| 58 | +```bash |
| 59 | +# Repo-wide (slow — runs all workspaces) |
| 60 | +npm run test |
| 61 | +# Filtered to affected workspaces (preferred) |
| 62 | +npm run test -- --filter=<workspace> |
| 63 | +``` |
| 64 | + |
| 65 | +#### Additional checks (run when relevant) |
| 66 | +- **Knip** (unused exports): `npm run knip` — always run if you added/removed exports. |
| 67 | +- **Depcheck**: `npm run depcheck` — run if you changed dependencies. |
| 68 | +- **Lockfile**: If you modified any `package.json`, run `npm install` at repo root and commit any `package-lock.json` changes. CI fails if the lockfile is out of date. |
| 69 | +- **OpenAPI / codegen**: If your backend has an OpenAPI spec or generated client, regenerate and commit any changes. |
| 70 | +- **Stylelint**: `npm run stylelint` — run if you changed CSS/style files. |
| 71 | + |
| 72 | +Substitute your package manager and check names if you do not use npm / turbo. |
| 73 | + |
| 74 | +### 3. Link to a Ticket (optional) |
| 75 | + |
| 76 | +If your org uses an issue tracker, ask the user whether to: |
| 77 | +- **Create a new ticket**: Use the appropriate tool (Linear, Jira, GitHub Issues, etc.) |
| 78 | +- **Link an existing ticket**: Ask for the identifier (e.g. `TEAM-1234`, `JIRA-567`, `#42`) |
| 79 | +- **Skip**: Only if user explicitly says no ticket is needed |
| 80 | + |
| 81 | +Most CI systems can be configured to require the ticket identifier in the PR body. Follow your org's convention. |
| 82 | + |
| 83 | +### 4. Format PR Title |
| 84 | + |
| 85 | +Follow Conventional Commits: `type(scope): description` |
| 86 | + |
| 87 | +- `type`: `feat`, `fix`, `docs`, `refactor`, `test`, `chore`, `perf`, `ci`, `build`, `revert` |
| 88 | +- `scope`: Workspace name from your `apps/*` or `packages/*` directories, or `monorepo` / `repo` for cross-cutting changes. Multiple scopes can be comma-separated: `fix(a, b, c): ...` |
| 89 | + |
| 90 | +Examples: |
| 91 | +- `feat(web): add dark mode toggle` |
| 92 | +- `fix(cli, daemon): load shell env at entrypoint` |
| 93 | +- `chore(repo): bump dependencies` |
| 94 | + |
| 95 | +### 5. Generate PR Body |
| 96 | + |
| 97 | +Fill in all sections from your PR template. A typical template has four sections: |
| 98 | + |
| 99 | +```markdown |
| 100 | +## Description |
| 101 | + |
| 102 | +<concise summary of what changed and why> |
| 103 | + |
| 104 | +## Related Issue |
| 105 | + |
| 106 | +Closes TEAM-XXXX |
| 107 | +<!-- or: Part of TEAM-XXXX --> |
| 108 | + |
| 109 | +## Potential Risk & Impact |
| 110 | + |
| 111 | +<list risks, performance implications, technical debt> |
| 112 | +<!-- Use "N/A" only if truly no risk --> |
| 113 | + |
| 114 | +## How Has This Been Tested? |
| 115 | + |
| 116 | +<describe testing performed: unit tests, manual testing, typecheck, lint> |
| 117 | +``` |
| 118 | + |
| 119 | +### 6. Create the PR |
| 120 | + |
| 121 | +```bash |
| 122 | +gh pr create \ |
| 123 | + --base <base-branch> \ |
| 124 | + --head <branch-name> \ |
| 125 | + --title "<type>(<scope>): <description>" \ |
| 126 | + --body "<generated body>" |
| 127 | +``` |
| 128 | + |
| 129 | +If the body is long, write it to a temp file and use `--body-file`: |
| 130 | +```bash |
| 131 | +gh pr create --base <base-branch> --head <branch> --title "..." --body-file /tmp/pr-body.md |
| 132 | +``` |
| 133 | + |
| 134 | +### 7. Report Result |
| 135 | + |
| 136 | +Return the PR URL to the user. |
| 137 | + |
| 138 | +## CI Checks Reference (template) |
| 139 | + |
| 140 | +These are typical checks that run on every PR. Map them to your repo's actual commands when adapting this skill. |
| 141 | + |
| 142 | +### Always-run checks |
| 143 | +| Check | What it does | Local equivalent | |
| 144 | +|---|---|---| |
| 145 | +| **Typecheck** | `npm run typecheck` | `npm run typecheck` (or `--filter=<workspace>`) | |
| 146 | +| **ESLint** | `npm run lint` | `npm run lint` or `npm run fix` | |
| 147 | +| **Prettier** | `npm exec prettier -- --check .` | `npm run format` (to fix) | |
| 148 | +| **Stylelint** | `npm run stylelint` | `npm run stylelint` | |
| 149 | +| **Depcheck** | `npm run depcheck` | `npm run depcheck` | |
| 150 | +| **Tests** | `turbo run test` (or equivalent) | `npm run test -- --filter=<workspace>` | |
| 151 | +| **Knip** | `npm run knip` | `npm run knip` | |
| 152 | +| **Lockfile** | Fails if `npm install` would modify `package-lock.json` | Run `npm install` and commit lockfile | |
| 153 | +| **PR Conventions** | Validates branch name, semantic title, ticket presence | Follow the formatting rules above | |
| 154 | + |
| 155 | +### Conditional checks (run only when affected files change) |
| 156 | +- **OpenAPI validation**: Triggered by backend API/spec changes. Regenerate locally. |
| 157 | +- **Desktop/mobile build**: Triggered when those apps are affected. |
| 158 | +- **E2E tests**: Triggered when the consumer app is affected. |
| 159 | + |
| 160 | +### Typical PR conventions CI enforces |
| 161 | +- **Branch name**: Max length, allowed characters (e.g. `[A-Za-z0-9/-]`). |
| 162 | +- **Title**: Conventional Commits format with a valid scope. |
| 163 | +- **Ticket reference**: PR body must contain a ticket identifier (often skipped for `chore:` and `revert:` types). |
| 164 | + |
| 165 | +## Common Mistakes to Avoid |
| 166 | + |
| 167 | +- **Wrong base branch**: Use the branch your org takes PRs into (e.g. `dev`, `main`, `develop`). |
| 168 | +- **Missing scope**: PR title CI check often requires a valid scope. |
| 169 | +- **Missing ticket reference**: Description must reference your ticket ID for CI to pass (except `chore:`/`revert:`). |
| 170 | +- **Forgetting to push**: Branch must be on remote before `gh pr create`. |
| 171 | +- **Lockfile drift**: Always run `npm install` and commit `package-lock.json` after dependency changes. |
| 172 | +- **Skipping local checks on code PRs**: Typecheck, lint, and tests should be run locally before sending out code changes to catch issues early and avoid CI round-trips. |
| 173 | +- **Uncommitted OpenAPI spec / generated client**: After backend API changes, regenerate and commit. |
0 commit comments