GitHub CLI operations and repository management
- version
- 2025-12-15
- GitHub stars
- 12
Install
/plugin install gh@jeffh-claude-pluginsRun it inside Claude Code after adding the marketplace with /plugin marketplace add jeffh/claude-plugins.
Contents
Discovered from sourceCommands 2
Fix PR
You are tasked with fixing issues on a Pull Request based on review feedback, status checks, and CI failures.
Input
The user will provide either:
- A PR number (e.g.,
123) - A PR URL (e.g.,
https://github.com/owner/repo/pull/123)
If just a number is provided, assume it's for the current repository.
Process
1. Gather PR Information
First, collect all relevant information about the PR:
# Get PR details (number, title, state, base branch)
gh pr view {PR} --json number,title,state,baseRefName,headRefName,body
# Get review comments (code review feedback)
gh api repos/{owner}/{repo}/pulls/{PR}/comments --jq '.[] | {path: .path, line: .line, body: .body, user: .user.login, created_at: .created_at}'
# Get PR review summaries (approved, changes requested, etc.)
gh api repos/{owner}/{repo}/pulls/{PR}/reviews --jq '.[] | {state: .state, body: .body, user: .user.login}'
# Get issue comments (general discussion on the PR)
gh api repos/{owner}/{repo}/issues/{PR}/comments --jq '.[] | {body: .body, user: .user.login, created_at: .created_at}'
# Get status checks
gh pr checks {PR} --json name,state,conclusion,description
# Get workflow run details for failed checks
gh run list --branch {head_branch} --limit 5 --json databaseId,name,conclusion,status
For failed workflow runs, get the logs:
gh run view {run_id} --log-failed
2. Analyze Feedback
Categorize all gathered feedback into:
- CI Failures: Failed status checks, workflow errors, test failures
- Review Comments: Code review feedback with specific file/line references
- Change Requests: Reviews marked as "changes requested" with specific asks
- General Comments: Discussion comments that may contain actionable feedback
- Unclear Feedback: Comments that don't have a clear action item
3. Create Task List
Use the TodoWrite tool to create a task list of all issues to fix. Each task should be specific and actionable:
- For CI failures: "Fix [test name] in [file]" or "Resolve [error type] in CI"
- For review comments: "Address review comment on [file:line] - [summary]"
- For change requests: "Implement requested change: [description]"
4. Handle Unclear Feedback
For any feedback that doesn't have a clear recommendation or action:
- Present the unclear feedback to the user using AskUserQuestion
- Ask what action they'd like to take:
- "Implement a specific fix" (let user describe)
- "Reply to comment asking for clarification"
- "Skip this feedback"
Add any user-specified actions to the task list.
5. Checkout the PR Branch
Before making changes, ensure you're on the PR branch:
gh pr checkout {PR}
6. Fix Each Issue
Work through the task list systematically:
- Mark the current task as
in_progress - Make the necessary code changes
- Verify the fix (run tests if applicable)
- Mark the task as
completed - Move to the next task
7. Verify Fixes
After completing all tasks, run verification:
# Run any project-specific tests/checks
# This depends on the project - check for Makefile, package.json scripts, etc.
# For common patterns:
make test # if Makefile exists
npm test # if package.json exists
cargo test # if Cargo.toml exists
pytest # if Python project
go test ./... # if Go project
8. Summarize Changes
After all fixes are complete:
- Show a summary of what was fixed
- Show the git diff of changes made
- Ask the user if they want to:
- Commit the changes (suggest using /commit command)
- Push to update the PR
- Make additional modifications
Important Notes
- Do not push automatically - always ask the user before pushing changes
- Preserve existing code style - match the formatting and conventions of the codebase
- Run tests locally - verify fixes work before considering them complete
- One fix at a time - complete each task fully before moving to the next
- Ask when uncertain - if a fix approach is unclear, ask the user rather than guessing
Example Workflow
User: /fix-pr 123
Set GitHub Branch Ruleset
You are tasked with creating or updating a GitHub branch ruleset to protect the default branch.
Process
1. Get Repository Information
# Get repository details
gh repo view --json name,owner,defaultBranchRef
# Get existing rulesets (if any)
gh api repos/{owner}/{repo}/rulesets --jq '.[] | {id, name, enforcement}'
2. Check Available GitHub Actions
Run this to discover available workflow job names that can be used as status checks:
# List workflow files
gh api repos/{owner}/{repo}/actions/workflows --jq '.workflows[] | {name: .name, path: .path}'
# For each workflow, you can inspect jobs by reading the workflow file
Also check the repository's .github/workflows/ directory to understand job names.
3. Ask User for Configuration
Use AskUserQuestion to ask the user:
Question 1: Protection Type
- "Use Status Checks (require CI jobs to pass)" - Default, recommended if GitHub Actions exist
- "Use Code Scanning Results (require security analysis)" - Use GitHub Advanced Security code scanning
If Status Checks selected and GitHub Actions exist:
Question 2: Which Status Checks to Require Present the discovered workflow job names and ask which ones to require. Common patterns:
- Build/Test jobs (e.g., "Test and Build", "CI")
- Lint/Format jobs (e.g., "Format and Lint", "Lint")
If no GitHub Actions exist: Inform the user that no GitHub Actions were found, so status checks will be skipped. The ruleset will only enforce deletion and non-fast-forward rules.
4. Create the Ruleset
Use the GitHub API to create the ruleset:
gh api repos/{owner}/{repo}/rulesets \
--method POST \
--input - << 'EOF'
{
"name": "Protect default branch",
"target": "branch",
"enforcement": "active",
"bypass_actors": [],
"conditions": {
"ref_name": {
"exclude": [],
"include": ["~DEFAULT_BRANCH"]
}
},
"rules": [
{
"type": "deletion"
},
{
"type": "non_fast_forward"
},
{
"type": "required_status_checks",
"parameters": {
"do_not_enforce_on_create": false,
"strict_required_status_checks_policy": false,
"required_status_checks": [
{
"context": "Format and Lint",
"integration_id": 15368
},
{
"context": "Test and Build",
"integration_id": 15368
}
]
}
}
]
}
EOF
Note: integration_id: 15368 is GitHub Actions. Adjust the context values based on the user's workflow job names.
Alternative: Code Scanning Rule
If user chooses Code Scanning Results instead of Status Checks:
gh api repos/{owner}/{repo}/rulesets \
--method POST \
--input - << 'EOF'
{
"name": "Protect default branch",
"target": "branch",
"enforcement": "active",
"bypass_actors": [],
"conditions": {
"ref_name": {
"exclude": [],
"include": ["~DEFAULT_BRANCH"]
}
},
"rules": [
{
"type": "deletion"
},
{
"type": "non_fast_forward"
},
{
"type": "code_scanning",
"parameters": {
"code_scanning_tools": [
{
"tool": "CodeQL",
"security_alerts_threshold": "high_or_higher",
"alerts_threshold": "errors"
}
]
}
}
]
}
EOF
Alternative: Minimal Ruleset (No CI)
If no GitHub Actions exist and user doesn't want code scanning:
gh api repos/{owner}/{repo}/rulesets \
--method POST \
--input - << 'EOF'
{
"name": "Protect default branch",
"target": "branch",
"enforcement": "active",
"bypass_actors": [],
"conditions": {
"ref_name": {
"exclude": [],
"include": ["~DEFAULT_BRANCH"]
}
},
"rules": [
{
"type": "deletion"
},
{
"type": "non_fast_forward"
}
]
}
EOF
5. Verify the Ruleset
After creation, verify it was set up correctly:
# List all rulesets
gh api repos/{owner}/{repo}/rulesets --jq '.[] | {id, name, enforcement}'
# Get details of the created ruleset
gh api repos/{owner}/{repo}/rulesets/{ruleset_id}
Default Configuration Summary
The default ruleset includes:
| Setting | Value |
|---|---|
| Enforcement | Active |
| Bypass actors | None (cannot be bypassed) |
| Target branches | Default branch only |
| Prevent deletion | Yes |
| Prevent non-fast-forward | Yes |
| Required status checks | Based on available GitHub Actions |
Important Notes
- Integration ID 15368 is the GitHub Actions integration. Use this for all status checks that come from GitHub Actions workflows.
- ~DEFAULT_BRANCH is a special pattern that matches whatever the repository's default branch is (main, master, etc.)
- Rulesets cannot be bypassed when
bypass_actorsis empty - If updating an existing ruleset, use
PATCHinstead ofPOSTwith the ruleset ID in the URL
Sponsors
Details
- Marketplace
- jeffh/claude-plugins
- Source
- gh
- Author
- Jeff Hui
- Category
- Development
