---
name: pr
description: >-
  Write or revise a pull request body, or push a GitHub branch, open a GitHub
  pull request, or verify its publication.
---

# Pull Request Workflow

> Upstream attribution: Adapted from the original [`github-pr` skill](https://github.com/damacus/skills/blob/b97d545a1099c1096bbaf9e346f833526b849a56/skills/workflow/github-pr/SKILL.md) authored by Dan Webb in `damacus/skills` commit `b97d545`.

This skill replaces `github-pr`. For PR body drafts and edits, use the format
below. For GitHub branch pushes and PR publication, follow the applicable
workflow steps. Before preparing a new PR, set `<base>` to the branch the user
explicitly requests, or `main` by default. Use the selected base throughout.

Run GitHub CLI commands with elevated network access. Check `gh auth status` before the first GitHub write and ask the user to run `gh auth login` if authentication fails.

## Workflow

### 1. Inspect the work and current publication state

- Inspect `git status --short`, `git diff`, and `git diff --cached` before staging anything.
- Identify the exact files that belong to the requested work. Preserve unrelated staged, unstaged, and untracked changes.
- Check whether the current branch already has a PR with `gh pr list --head <branch> --state all`. If it has an open PR, verify and summarize that PR instead of creating a duplicate. If it is closed or merged, do not reuse the branch without explicit user direction.
- Refresh `origin/<base>` before creating a new feature branch. Do not silently rebase, reset, stash, or rewrite any worktree state.

### 2. Create or verify the feature branch

- Never commit the requested work directly on `main`.
- If starting from the default branch or the selected base, create a feature branch from refreshed `origin/<base>` with `git switch -c codex/<type>-<short-slug> origin/<base>`.
- If the current branch is detached, create an appropriately named branch before committing. If it is an existing feature branch, confirm that it is the intended branch and does not already have a conflicting PR.
- Prefer `codex/` branch names, with an appropriate type such as `feat`, `fix`, `docs`, `chore`, or `refactor`.

### 3. Verify the change

- Identify the repository's normal validation commands from its documented project contract, CI configuration, or task runner.
- Check that automated tests exercise the changed behaviours the PR claims to
  verify. Add or update focused tests for new behaviour and regressions that CI
  can exercise. For behaviours CI cannot exercise, run a targeted manual check
  when the required environment is available.
- Run the relevant checks before publishing. For documentation-only work, use focused validation such as repository-provided linting plus `git diff --check` when no runtime test applies.
- Report the exact commands and outcomes. Do not claim tests passed when they were not run.
- If required validation fails because of this change, fix it before publishing. If it is demonstrably pre-existing, report that evidence and ask whether to publish a draft PR.

### 4. Summarize and stage only the selected changes

- Summarize the selected diff in plain language before writing the commit message.
- Produce a concise conventional commit subject that describes the user-visible intent. Keep it under 50 characters when practical.
- Stage explicit paths only: `git add -- <selected-paths>`. Never use `git add .` or `git add -A` by default.
- Inspect `git diff --cached --stat` and run `git diff --cached --check` before committing. If unrelated files are staged, stop and ask the user which changes belong in the PR.

- Include the selected tests added or updated during verification. Compare the
  staged paths with the files that were tested. If any selected file changes
  after verification, rerun the affected checks and repeat explicit-path staging
  and staged-diff checks before committing.

### 5. Commit and push

- Commit only after the staged diff and validation match the requested scope: `git commit -m "<conventional subject>"`.
- Push the current branch with upstream tracking: `git push -u origin HEAD`.
- After pushing, check again for an existing PR for the exact branch. Do not create a second PR if one already exists.

### 6. Create and verify the PR

- Create a ready PR only when the relevant validation passed. If validation is incomplete or failed for a reason the user accepts, ask whether to create a draft instead.
- Use explicit, non-interactive GitHub CLI arguments:

  ```fish
  gh pr create --base <base> --head <branch> --title "<conventional subject>" --body "<PR body>"
  ```

- Write the PR body using the format below.
- Verify the created or existing PR with `gh pr view <number> --json number,url,state,isDraft,baseRefName,headRefName,title`.
- Report the PR URL, branch, commit, selected base, validation results, and any known follow-up.

## PR body

Adapted from [Matt Pocock’s /pr skill](https://www.aihero.dev/skills-pr#the-template).
Use Markdown H2 headings in this order. When the repository requires a PR
template, fill its corresponding sections and add any missing H2 sections the
template allows.

- `## Summary` — Say what changes and why. Include an issue-closing reference
  when applicable. Use a short diff, pseudocode, or diagram when it makes the
  change easier to understand.
- `## Verification` — Name the changed behaviours that automated tests cover
  and what they assert. Link to specific tests where useful. Show a before and
  after when available, such as a regression test failing on the base and
  passing on the branch. Keep routine lint output, test totals, and CI status
  in the task report. State any material gap in coverage.
- `## Manual verification` — Include this section when relevant behaviour
  requires an environment or capability unavailable in CI. Say why CI cannot
  exercise it, what was checked, and what was observed. Name the environment
  and any material limits. If a required check is pending, say so.
- `## Merge Danger` — Include this section only for high-risk changes.
  Explain what makes the change high risk, what could break, who would be
  affected, and any effects that reverting the commit would leave behind.

## Write Safety

- Use ordinary Git for commit-only requests.
- Follow the requested scope. A push request ends with the push. A PR draft,
  status check, or body edit requires only the actions needed for that request.
- Do not amend existing commits, force-push, rebase, reset, stash, close PRs, or alter unrelated files unless the user explicitly asks.
- Do not create a duplicate PR. Existing PR status is a result to report, not an error to work around.
- Do not add reviewers, labels, assignees, projects, or milestones unless the user requests them.
- If GitHub authentication, repository access, branch push, or PR creation fails, report the precise blocker and leave the local commit intact.

## Completion Criteria

A publication request is complete only when the selected change is committed, pushed to its intended feature branch, represented by one verified PR against the selected base, and accompanied by an accurate validation summary.
