pr
npx machina-cli add skill NorthShoreAutomation/trellis/pr --openclawFiles (1)
SKILL.md
4.4 KB
User Input
$ARGUMENTS
You MUST consider the user input before proceeding (if not empty).
Create a pull request for the current branch.
Instructions
1. Verify Branch State
- Run
git branch --show-currentto get current branch name - If empty (detached HEAD state): STOP and inform user they must checkout a branch first
- If on main/master: STOP and inform user they must be on a feature branch to create a PR
- Run
gh pr view --json number,state,urlto check if a PR already exists- If command succeeds with state "OPEN": STOP and inform user with the PR URL
- If command succeeds with state "CLOSED" (not merged): Ask user if they want to reopen the existing PR or create a new one
- If command succeeds with state "MERGED": Warn user the branch was already merged; suggest creating a new branch
- If command fails with exit code 1 (no PR): Continue to create one
- If command fails with other errors (auth, network, rate limit): STOP and inform user of the connectivity/auth issue
2. Check for Uncommitted Changes
- Run
git statusto see all staged and unstaged changes - If there are uncommitted changes:
- Ask user if they want to commit them before creating the PR
- If yes, follow the commit process from
/trellis:push(includes changelog updates) - If no, warn that uncommitted changes won't be in the PR
3. Sync Beads (if configured)
- If beads is configured (
.beads/directory exists andbdcommand available):- Run
bd sync --from-mainto pull latest beads updates - Run
bd list --status=in_progressto see related issues for the PR description - If
bdcommands fail with "not a beads repository": Continue without beads - If
bdcommands fail with "database locked" or "merge conflict": Warn user to runbd syncmanually before merging
- Run
4. Push to Remote
- Check if branch has an upstream:
git rev-parse --abbrev-ref @{upstream} 2>/dev/null - If no upstream, push with:
git push -u origin $(git branch --show-current) - If upstream exists, push with:
git push - If push fails: STOP and inform user with the error
5. Create Pull Request
- Analyze the commits and changes to draft a PR description:
- Run
git log main..HEAD --onelinefor commit summary (usemasterifmaindoesn't exist) - Run
git diff main..HEAD --statfor files changed - If beads in-progress issues were found in step 3, include them in Related Issues
- Run
- Determine if this should be a draft PR:
- If user arguments include "draft" or "--draft", add
--draftflag - Otherwise, create a regular PR
- If user arguments include "draft" or "--draft", add
- Create the PR:
gh pr create --title "<title>" --body "$(cat <<'EOF'
## Summary
<!-- 1-3 bullet points describing the changes -->
## Changes
<!-- List of specific changes made -->
## Test Plan
<!-- How to test these changes -->
## Related Issues
<!-- Link to any related beads issues or GitHub issues -->
EOF
)" [--draft]
- Use a concise, descriptive title following conventional commit style when appropriate
- If user provided arguments (other than "draft"), incorporate them into the title or description
- If PR creation fails: STOP and inform user with the specific error message. Common failures:
- "pull request already exists": Another PR was created between check and create
- "required status check": Branch protection rules blocking PR creation
- "permission denied": User lacks write access to repository
6. Report Success
- Run
gh pr view --json url -q .urlto get the PR URL- If this fails, inform user: "PR created but URL retrieval failed. Run
gh pr viewto see the PR."
- If this fails, inform user: "PR created but URL retrieval failed. Run
- Display the PR URL to the user
- Inform user they can now:
- Request reviews
- Run
/trellis:releasewhen ready to merge and release
Important
- Must be on a feature branch — will not create PR from main/master
- One PR per branch — will not create duplicate PRs
- Supports draft PRs — add "draft" to arguments to create a draft PR
- Keep PR titles short and meaningful (50 chars or less if possible)
- Do not include files that look like secrets (.env, credentials, etc.) without asking
- If there are multiple unrelated changes, suggest splitting into separate PRs
- NEVER use
--forceor--force-with-leasepush unless explicitly requested by the user - Warn the user if they request a force push to main/master branches
Source
git clone https://github.com/NorthShoreAutomation/trellis/blob/main/skills/pr/SKILL.mdView on GitHub Overview
This skill automates opening a pull request for your active feature branch. It validates branch state, checks for an existing PR, and composes a structured description so you can quickly solicit reviews and merge changes.
How This Skill Works
It identifies the active branch and its upstream, checks PR status with gh pr view, and pushes changes when needed. It then drafts and creates the PR with gh pr create, including a clear title and body and an optional --draft flag, and reports the resulting URL.
When to Use It
- Open a PR for your current feature branch after finishing work on it.
- Your branch is on main/master or detached HEAD; switch to a feature branch before creating a PR.
- A PR does not already exist for this branch (no existing OPEN PR), so you can create one.
- There are uncommitted changes you want included or staged for the PR.
- Beads are configured and you want related issues included in the PR description.
Quick Start
- Step 1: Ensure you’re on a feature branch: git branch --show-current (don’t be on detached HEAD or on main).
- Step 2: Push if needed and create the PR: git push -u origin $(git branch --show-current) (or git push if upstream exists), then gh pr create --title <title> --body <body> [--draft].
- Step 3: Retrieve and share the PR URL: gh pr view --json url -q .url and provide it to reviewers.
Best Practices
- Always work on a feature branch; do not create PRs from main.
- Review and commit changes you intend to include before PR creation.
- Provide a clear, conventional title and a structured body with test plans.
- Include related beads issues in the PR description when applicable.
- Verify upstream/push permissions and address any merge conflicts before PR creation.
Example Use Cases
- Opening a PR for feature/authentication after implementing a login flow.
- Draft PR for bugfix/timeout with the --draft flag while awaiting reviews.
- PR includes Related Issues from beads to link related work.
- Pushing to origin when there is no upstream, then creating the PR.
- Sharing the OPEN PR URL with teammates after gh pr view.
Frequently Asked Questions
Add this skill to your agents