$npx -y skills add Codagent-AI/agent-skills --skill push-prCommits changes, pushes to remote, and creates or updates a pull request for the current branch. Use when the user says "push pr", "create pr", "push and create pr", or invokes "codagent:push-pr".
| 1 | # codagent:push-pr |
| 2 | |
| 3 | Commit all changes, push to the remote, and create or update the pull request for the current branch. |
| 4 | |
| 5 | ## Steps |
| 6 | |
| 7 | 1. **Run validator detection** |
| 8 | - Run `agent-validator detect 2>&1` |
| 9 | - **Exit 0** → gates would run, invoke `agent-validator:validator-run` skill and wait for it to pass before proceeding |
| 10 | - **Exit 2** → no gates would run (no changes or no applicable gates), skip to Step 2 |
| 11 | - **Exit 1** → error, report the error to the user and stop |
| 12 | - **Any other exit code** → treat as error, report output to the user, and stop |
| 13 | |
| 14 | 2. **Check for uncommitted changes** using `git status --porcelain` |
| 15 | - If there are changes, create a commit: |
| 16 | - Run `git diff --staged` and `git diff` to see what's changed |
| 17 | - Generate a concise, descriptive commit message based on the changes |
| 18 | - Stage changed files by name (avoid staging sensitive files like `.env` or credentials) |
| 19 | - Commit with: `git commit -m "message"`; add `-m "Co-Authored-By: <Name> <email>"` only when the co-author identity is explicitly configured or provided by the user |
| 20 | - If there are no changes, proceed to push check |
| 21 | |
| 22 | 3. **Push to remote** |
| 23 | - Get current branch: `git branch --show-current` |
| 24 | - Push with upstream tracking: `git push -u origin <branch>` |
| 25 | - If push fails, show the error and stop |
| 26 | |
| 27 | 4. **Check if PR exists** |
| 28 | - Run `gh pr view --json url,title,state,number,headRefOid` while capturing stdout, stderr, and exit code |
| 29 | - If the command exits non-zero and stderr indicates no pull requests were found for the branch, treat it as no PR existing and proceed to creation |
| 30 | - If the command exits non-zero for auth, network, API, or other errors, report stderr and stop |
| 31 | - If the command succeeds but output is empty or invalid JSON, report the unexpected output and stop |
| 32 | - Otherwise, parse the `state` field from the JSON response |
| 33 | - **If PR exists and is OPEN:** |
| 34 | - Check if there are new commits by comparing current HEAD with PR's `headRefOid` |
| 35 | - If new commits exist: |
| 36 | - Get default branch: `gh repo view --json defaultBranchRef --jq .defaultBranchRef.name` |
| 37 | - Get all commits for the description: `git log <default-branch>..HEAD --oneline` |
| 38 | - Regenerate the PR description based on all commits (including the new ones) |
| 39 | - Update the PR: `gh pr edit <pr-number> --body "updated description"` |
| 40 | - Print: "PR updated with new commits: <url>" |
| 41 | - If no new commits: print "PR already exists: <url>" |
| 42 | - **If PR exists but is CLOSED:** |
| 43 | - Print: "Previous PR is closed, creating new PR" |
| 44 | - Create a new PR (follow creation steps below) |
| 45 | - **If no PR exists, create one:** |
| 46 | - Get default branch: `gh repo view --json defaultBranchRef --jq .defaultBranchRef.name` |
| 47 | - Get commit history for PR description: `git log <default-branch>..HEAD --oneline` |
| 48 | - Generate a clear PR title and description based on the commits and change context |
| 49 | - Create PR: `gh pr create --base <default-branch> --title "title" --body "description"` |
| 50 | - Print the PR URL |
| 51 | |
| 52 | 5. **Print the PR URL** at the end so it's easy to find |
| 53 | |
| 54 | ## Notes |
| 55 | |
| 56 | - Operates on the current branch — does NOT create or switch branches |
| 57 | - Uses descriptive commit messages that explain the "why" not just the "what" |
| 58 | - PR descriptions should summarize the changes and their purpose |
| 59 | - Always include the PR URL in the final output |
| 60 | - Can be invoked standalone at any point without prior workflow state |