Push pr

From rjmurillo/ai-agents · View interactive version

Push pr is an AI agent skill from the GitHub repository rjmurillo/ai-agents. Commit, push, and open a pull request on GitHub or ADO with the repo template filled in from the real diff. Use when you say `push and open a PR`, `open a pull request`, or `push this branch`. Also use when writing a push recipe or runbook step, serializing pushes with flock or a push lock file (the

How to use this skill

Skill file

Push PR

Commit, push, and open a pull request, on GitHub or Azure DevOps, whose body is

adapted from the real diff rather than copied from the template. This skill is

the only place a PR is created; /ship calls it and never creates a PR itself.

Migrated from .claude/commands/push-pr.md under ADR-064, which makes skills the

single user-invocable surface. The scoped allowed-tools grant, the

identity-hardened python3 -I form, and both vendor-portability declarations

carry over unchanged: they are the security contract, not formatting.

Triggers

push and open a PR, open a pull request, push this branch,

commit and push, open an Azure DevOps PR

Context

Host Detection

Run this before step 1. It sets host, which only step 7 branches on. Steps 1

to 6 run the same on both hosts.

remote_url="$(git remote get-url origin 2>/dev/null || true)"
if [ -z "$remote_url" ]; then
  echo "ERROR: origin remote is not configured; cannot detect VCS host." >&2
  exit 2
fi
case "$remote_url" in
  *dev.azure.com*|*visualstudio.com*) host=ado ;;
  *) host=github ;;
esac
redacted_remote_url="$(printf '%s' "$remote_url" | sed -E 's#(https://)[^/@]+@#\1[redacted]@#')"
echo "host=$host (origin: $redacted_remote_url)"

dev.azure.com or visualstudio.com anywhere in the URL means host=ado;

everything else is host=github. This is the same rule /ship uses.

Commit Contract

Commit messages MUST follow <type>(<scope>): <desc> and include a Co-Authored-By: trailer when authored with an AI agent.

When the working tree is clean, /push-pr MUST NOT create a commit. It pushes

HEAD as it stands. /ship relies on this: its owner-mode check requires the

tree to be clean after /review, so the push carries the reviewed marker commit

and nothing newer.

Folded rule: before you write, run, or quote a push lock or any command that serializes git push, read push-lock.

Process

Based on the above changes:

  1. Create a new branch if on main.

1. Determine the type of change that maps to a conventional commit type

followed by a 3-5 word description (for example, fix/parser-log-enrichment).

  1. Read @.github/PULL_REQUEST_TEMPLATE.md. Step 3 seeds it into the body file; use this copy only when the seeded file holds the marker alone.
  2. Run the secure path allocator:

```bash

( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 -I "$d/lib/ptk_run.py" skills/github/scripts/pr/new_pr.py --prepare-body-file; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )

```

Windows PR Body Fallback section below for steps 3, 4, 5, and 7.

each tool call runs in a fresh shell.

repository PR template. Use the Edit tool to fill the template sections in

that exact file, then delete the marker line. A body that still contains the

marker text anywhere is rejected.

Replace it with the template you read in step 2, adapted to the change.

  1. Check the title and body file before the push, which can take minutes:

```bash

( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 -I "$d/lib/ptk_run.py" skills/github/scripts/pr/new_pr.py --preflight --title "<conventional commit title>" --body-file ".project-toolkit/scratch/pr-body-<returned-uuid>.md"; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )

```

--preflight checks the title format and the body file: its path, that it is a regular UTF-8 file, and that the placeholder line is gone.

It makes no network call and creates nothing. On host=github the dash and

escaped newline checks run at step 7. On host=ado the Azure DevOps

section checks escaped newlines but not dashes, so it also requires a manual

dash check. Fix a rejection here.

  1. Check that the body names only files the diff touches, before the push. The

required Validate PR check fails on a path the diff does not touch, and the

fix costs a CI round after the PR opens. Commit first: local mode reads

committed HEAD only, so an uncommitted file reads as not in the diff. Run

the local mode, which reads the same body file and

git diff origin/main...HEAD with no network call:

```bash

uv run --frozen python -I scripts/validation/pr_description.py --body-file ".project-toolkit/scratch/pr-body-<returned-uuid>.md" --base origin/main

```

Stop. If every flagged path appears in git status, commit instead of

editing the body. Otherwise edit the body file (remove the path, move it

out of the change heading, or wrap it in a code fence), then re-run until

it exits 0.

file, an unknown or invalid base ref, or git unavailable. For a missing

origin/main, pass --base with the ref the PR targets, such as

<remote>/<default-branch>. Do not skip the step.

decides that.

install, cannot run this step. Say it was not run, and compare every

path under the change heading (inline code, bold, list item, or link) to

git diff --name-only origin/<target>...HEAD by hand. <target> is the

branch the PR targets, main unless the PR targets another branch.

  1. Push the branch to origin.
  2. Create the pull request. host=ado skips the rest of this step and follows

Azure DevOps PR Creation. host=github uses the new_pr skill script:

<!-- vendor-portability: declared. This skill reads the consumer's

.github/PULL_REQUEST_TEMPLATE.md and writes the consumer's

.project-toolkit/scratch/ body file. It resolves the helper from the installed

Copilot or Claude plugin root. The .claude fallback is only for this

repository's self-hosted source checkout; scripts/pr/ is inside the

shipped github skill, not the upstream-only top-level scripts/ tree.

-->

```bash

( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 -I "$d/lib/ptk_run.py" skills/github/scripts/pr/new_pr.py --title "<conventional commit title>" --body-file ".project-toolkit/scratch/pr-body-<returned-uuid>.md"; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )

```

Azure DevOps PR Creation

Use this in place of step 7 only when host=ado. The gh-based new_pr.py

does not apply to Azure DevOps. Steps 1 to 6 still run: the body file comes from

step 3, the local checks from steps 4 and 5, and the push from step 6. Step 5

carries its own fallback when the local validator is absent, such as in a

plugin install.

First check the title and body with the offline description validator. It

needs no gh and makes no network call. Use the same title and body file

that passed steps 4 and 5:

( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 -I "$d/lib/ptk_run.py" skills/github/scripts/pr/validate_pr_description.py --title "<conventional commit title>" --body-file ".project-toolkit/scratch/pr-body-<returned-uuid>.md"; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )

Run it without --fail-on-violation, as new_pr.py does on GitHub. Warnings,

such as a missing Closes #N keyword or an Azure Boards AB# link, are

advisory: report them and go on. Exit 1 means escaped newlines in the body or

an unreadable body file. In this mode a bad title still exits 0, so also stop

when the output prints an Errors section. Step 4 already rejects a title that

is not a conventional commit. On either failure, fix the title or body file,

then re-run steps 4 and 5 and this check. Do not create the PR.

This validator has no dash check. Read the title and the body file for an em

dash (U+2014) or an en dash (U+2013). Replace each one before the create.

Then create the PR. az is not in allowed-tools, so this command prompts

the user, who sees every flag before it runs:

az repos pr create --output json --title "<conventional commit title>" --description '@<body-file-path-from-step-3>'

file, so --description @<path> sends the filled body file and never a shell

variable.

and 5, run from the same directory. No other argument may

start with @: Azure CLI reads any @<path> argument from disk and sends the

file to the server.

NOT start with @, and MUST NOT contain ", $, or a backtick. Azure CLI

would read a title that starts with @ as a file path.

--auto-complete, --bypass-policy, --bypass-policy-reason,

--delete-source-branch, --merge-commit-message, --org, --project,

--repository, --reviewers, --required-reviewers, --work-items,

--transition-work-items, --open, or --source-branch. The one exception:

add --target-branch <branch> only when the PR must not target the

repository default branch. Then step 5 MUST have checked the paths against

origin/<branch>, so the check read the same diff the PR shows. Run the

validator with --base origin/<branch>, or, when the validator is absent,

do the manual comparison against that branch.

stop. Never retry with a different command shape.

with @, Azure CLI could not read the body file and sent the path text

instead. It does this silently, logging only at debug level. Report FAIL

with the pullRequestId and ask the user whether to fix or abandon that PR.

Do not abandon or edit it without their answer.

link <repository.webUrl>/pullrequest/<pullRequestId>, in the Output block.

pr-body-windows.md, the scratch file it creates for step 5, as the body

file in both commands above. Skip its step 7 item. The az

command stays the same. Keep the single quotes around '@<path>':

PowerShell reads an unquoted @name as splatting, not as text.

Output

Finish with one line the caller can parse, naming the host and the PR:

PR: host=github number=<number> url=<url>
PR: host=ado pullRequestId=<id> url=<url>

/ship reads number (GitHub) or pullRequestId (Azure DevOps) from this line

to check the pipeline on the new PR.

Windows PR Body Fallback

Use this only on Windows, and only when step 3 exits 2 with

ERROR: secure PR body files are not supported on Windows. Every other

platform keeps the allocator mandatory. The allocator needs directory file

descriptors and owner-only modes that Windows does not provide.

new_pr.py accepts --body '<text>' in place of --body-file. That path

never calls the allocator or its file reader. The helper still runs the same

title, dash, and escaped newline checks, then hands the body to gh on

stdin, never as a command-line argument to gh.

  1. Skip --prepare-body-file. Fill the PR template from step 2 into the body

text yourself, with the same rules as step 3.

  1. Step 4 preflight: pass --body '<body text>' instead of --body-file. It

checks the title only, since there is no file to check.

  1. Step 5: pr_description.py --body-file reads any readable file. Run

mkdir -p .project-toolkit/scratch first, because the allocator refused

before it created that directory. Create pr-body-windows.md in it with

Write and expect one permission prompt. Later Edit fixes after a step 5

exit 1 stay inside the scoped Edit grant.

  1. Step 7: run the same command with the body text inline:

```bash

( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 -I "$d/lib/ptk_run.py" skills/github/scripts/pr/new_pr.py --title "<conventional commit title>" --body '<body text>'; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )

```

checked the file, so every edit made there must reach this command.

use single quotes and write each apostrophe as '\''. In PowerShell,

use a single-quoted here-string (@' ... '@). Never use double quotes:

bash runs each backtick code span as a command and expands $name, and

PowerShell treats the backtick as an escape and also expands $.

variable, for the same fresh-shell reason as step 3.

newline check fails, its message says to pass --body-file. That is the

refused path on Windows, so fix the line breaks instead.

through CreateProcess. The body rides on argv twice: to new_pr.py, then

to validate_pr_description.py. If the command fails for length, trim

the body and keep every required template section.

not which checks it must pass.

You have the capability to call multiple tools in a single response. You MUST do all of the above in a single message. Do not use any other tools or do anything else. Do not send any other text or messages besides these tool calls.

Verification

Anti-Patterns

| Avoid | Why | Instead |

|-------|-----|---------|

| Storing the allocator path in a shell variable | Each tool call runs a fresh shell, so the variable is empty on the next call and the body lands nowhere | Copy the returned path literally into the next call |

| Copying the template verbatim | Ships placeholder comments as the PR description, and the spec-coverage job reads them | Adapt every section from the diff |

| Numbered acceptance criteria | The Validate Spec Coverage job reads - [ ] and * [ ] only, so numbered items are invisible to it | Use checkbox bullets |

| Checking a criterion box before it is met | The signal reports a pass the PR does not have, and the FAIL it should have shown does not block merge | Check a box only once the criterion holds |

| Widening the allowed-tools grant to bare Bash | Removes the CWE-78 argument scoping that makes this skill safe to auto-approve | Add a specific scoped entry |

| Granting any az entry, including az repos pr create:*, for the ADO branch | A prefix grant auto-approves every flag, such as --bypass-policy, --auto-complete, or an @<path> that uploads a local file | Leave az ungranted so each create prompts |

| Creating a PR from /ship or any other skill | Splits title, body, and validation rules across two places | Call /push-pr and read its Output block |

| Committing when the tree is clean | Moves HEAD off the /review marker commit /ship verified | Push HEAD as it stands |

Extension Points

for Azure DevOps. A further forge adds its own branch to Host Detection and step 7;

the template-adaptation rules in step 3 are forge-independent.

template read in step 3. When that template gains a parsed section, add it to

step 4 and to the Verification list together.

convention; a project with a different scheme changes that sub-step alone.

<!-- vendor-portability: .project-toolkit/scratch is created in the consumer workspace

for one-run PR body files. It is not an upstream repository dependency. -->

<!-- vendor-portability-exec: step 5 runs scripts/validation/pr_description.py, an upstream-only validator the plugin install does not ship. Step 5 states the fallback. -->

<!-- vendor-portability: step 5 reads scripts/validation/pr_description.py only when the consumer checkout carries it, and reports the step as not run otherwise. -->

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.