Install
openclaw skills install issue-to-prissue-to-pr — Automatically fix GitHub issues end-to-end: reads the issue, analyzes repository code, implements a fix, and submits a pull request. Use when the user provides a GitHub issue URL, mentions fixing a GitHub issue, or uses the /fix-issue command. Supports URLs in the format https://github.com/{owner}/{repo}/issues/{number}.
openclaw skills install issue-to-prYou are an autonomous agent that reads a GitHub issue, understands the problem, locates the relevant code, implements a fix, and prepares everything for review. Follow the phases below in order, using the checklist to track progress.
Use this checklist to track your progress through the workflow:
Extract the GitHub issue reference from the user's input.
Supported input formats:
| Format | Example |
|---|---|
| Full URL | https://github.com/owner/repo/issues/123 |
| Shorthand | owner/repo#123 |
| Issue number only | #123 or 123 (requires being in a git repo) |
https://github.com/{owner}/{repo}/issues/{number} and extract components directly.{owner}/{repo}#{number} pattern.#number) is provided:
git remote -v to detect the current repository's GitHub remote.owner and repo from the remote URL (supports both HTTPS and SSH formats).Parsed issue: {owner}/{repo}#{number}
Retrieve the full issue content including title, body, labels, and comments.
gh CLI (preferred)Run in the terminal:
gh issue view {number} --repo {owner}/{repo} --comments
If the command succeeds, extract from the output:
fetch_contentIf gh is not installed or the command fails:
fetch_content tool with the issue URL: https://github.com/{owner}/{repo}/issues/{number}From the issue content, identify and note:
| Field | Description |
|---|---|
| Problem summary | One-sentence description of the bug or feature gap |
| Reproduction steps | How to trigger the issue |
| Expected behavior | What should happen |
| Actual behavior | What actually happens |
| Error messages | Stack traces, log output, error codes |
| File path hints | Any files, modules, or functions mentioned |
| Related issues/PRs | Cross-references that provide context |
Ensure you have local access to the repository source code.
git remote -v 2>/dev/null
github.com/{owner}/{repo} (or github.com:{owner}/{repo}), you are already in the correct repo. Skip to Step 3.If the current workspace is not the target repository, clone it:
gh repo clone {owner}/{repo} /tmp/{repo} 2>/dev/null || git clone https://github.com/{owner}/{repo}.git /tmp/{repo}
Then inform the user about the clone location.
After locating or cloning the repository, cd into the repository directory before running any git commands:
cd {repo_path}
Determine if you have push access to the repository:
gh api repos/{owner}/{repo}/collaborators/$(gh api user --jq '.login') --silent 2>/dev/null
has_push=$?
If has_push is non-zero (no write access), fork the repository now:
gh repo fork {owner}/{repo} --remote-name fork --clone=false
This ensures the fork is ready before creating the fix branch. Note which remote to push to:
originforkFirst, detect the default branch:
# Detect the default branch (prefer GitHub API, fallback to git)
default_branch=$(gh api repos/{owner}/{repo} --jq '.default_branch' 2>/dev/null)
if [ -z "$default_branch" ]; then
default_branch=$(git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null | sed 's|^origin/||')
fi
if [ -z "$default_branch" ]; then
default_branch="main"
fi
Then check out the default branch and pull latest changes:
git checkout $default_branch
git pull --ff-only
Check if the fix branch already exists:
if git show-ref --verify --quiet refs/heads/fix/issue-{number} 2>/dev/null || \
git show-ref --verify --quiet refs/remotes/origin/fix/issue-{number} 2>/dev/null; then
echo "Branch fix/issue-{number} already exists"
fi
If the branch already exists, ask the user whether to:
fix/issue-{number}-v2 (or incrementing suffix)Create the fix branch:
git checkout -b fix/issue-{number}
Systematically locate the problem in the codebase.
Use the error messages, file paths, and function names from the issue to search:
grep_code to search for error strings, function names, or variable names mentioned in the issue.search_codebase for semantic searches when the issue describes behavior rather than specific code.search_file to find files by name if the issue mentions specific filenames.Once you find candidate files:
git log --oneline -10 -- {file_path}
Before writing any code, produce a structured analysis:
### Analysis Result
- **Root Cause:** {Why the bug occurs}
- **Affected Files:** {file1 (function_name), file2 (function_name)}
- **Fix Strategy:** {What the minimal change should be}
- **Risk Assessment:** Low / Medium / High
- **Estimated Changes:** {N files, ~M lines}
This structured output will be referenced in Phase 5 (implementation) and Phase 7 (summary).
Before proceeding to implementation, assess the scope:
workspaces in package.json, pnpm-workspace.yaml, lerna.json, or similar workspace config files. If found, narrow your search scope to the relevant package/workspace.Apply the minimal code change to resolve the issue.
search_replace tool to make precise edits.get_problems.Validate that the fix works and doesn't break anything.
Look for common indicators:
| File | Likely runner |
|---|---|
package.json | npm test or npx jest or npx vitest |
Cargo.toml | cargo test |
go.mod | go test ./... |
pyproject.toml / setup.py | pytest |
Makefile | make test |
pom.xml | mvn test |
build.gradle | ./gradlew test |
# Run the full test suite or scoped tests related to the changed files
{test_command}
If no test runner or test files are found:
get_problems on all changed files to catch syntax errors and type issues.No automated test framework was detected in this project. The fix was verified via static analysis and manual code review.
Check if the project has lint or format tools configured, and run them:
# Examples
npm run lint 2>/dev/null
cargo clippy 2>/dev/null
go vet ./... 2>/dev/null
Fix any lint issues introduced by your changes.
Present the fix to the user and wait for explicit approval before proceeding.
## Fix Summary for {owner}/{repo}#{number}
**Issue:** {issue_title}
**Root Cause:** {brief explanation}
**Changes:**
- `{file_path_1}`: {what was changed and why}
- `{file_path_2}`: {what was changed and why}
Display the actual code changes so the user can review them:
git diff
Highlight the key modifications and explain their impact.
Ask the user:
Would you like me to submit these changes as a Pull Request? If anything needs adjustment, let me know.
Only execute this phase after the user has approved the changes in Phase 7.
git add -A
git commit -m "fix: {short description} (#{number})
{Detailed explanation of what was wrong and how this commit fixes it.}
Closes #{number}"
Push to the appropriate remote based on the permission check from Phase 3:
# If you have write access (push succeeded in Phase 3 check):
git push origin fix/issue-{number}
# If you forked the repository in Phase 3:
git push fork fix/issue-{number}
pr_template=""
for f in .github/PULL_REQUEST_TEMPLATE.md .github/pull_request_template.md docs/pull_request_template.md PULL_REQUEST_TEMPLATE.md; do
if [ -f "$f" ]; then
pr_template="$f"
break
fi
done
If a PR template is found, use it as the base for the PR body and fill in the relevant sections. Otherwise, use the default template below.
## Summary
Fixes #{number}.
### Problem
{Brief problem description from issue analysis}
### Solution
{Brief solution description from fix implementation}
### Changes
- {change 1}
- {change 2}
### Testing
- [x] Existing tests pass
- [x] {Any additional verification performed}
---
<sub>🔧 Generated by [issue-to-pr](https://github.com/4yDX3906/issue-to-pr)</sub>
gh pr create \
--repo {owner}/{repo} \
--title "fix: {short description}" \
--body "$pr_body" \
--base {default_branch} \
--head {head_ref}
{head_ref}isfix/issue-{number}for direct push or{your_username}:fix/issue-{number}for fork push.
Tip: Add the
--draftflag to create a draft PR if the fix needs further review before marking as ready.
gh pr create output.✅ PR created successfully: {PR_URL} Please review the PR page for any CI checks or reviewer feedback.
If the user declines auto-submission or any step fails, present:
fix: {short description} (#{number})
{Detailed explanation}
Closes #{number}
gh pr create \
--title "fix: {short description}" \
--body "..." \
--base {default_branch}
git diff {default_branch}Handle these common failure scenarios gracefully:
| Scenario | Action |
|---|---|
gh CLI not installed | Fall back to git clone and fetch_content. Suggest installing gh: brew install gh or see https://cli.github.com |
gh auth not configured | Prompt user to run gh auth login and retry |
| Repository is private / 403 | Inform the user that authentication is required and guide them to authenticate |
| Issue not found / 404 | Double-check the URL and ask the user to verify |
No write access to /tmp | Clone to the workspace directory instead |
| Tests fail after fix | Analyze failure output, revise the fix, and re-verify |
| Cannot determine root cause | Present findings so far and ask the user for guidance |
| Large / complex issue | Break the issue into sub-tasks, fix the most critical part first, and note remaining work |
git push permission denied | Auto-fork the repository and push to fork |
gh pr create fails | Show error details and provide manual command |
User's gh not authenticated | Prompt user to run gh auth login first |
| Branch already exists on remote | Ask user whether to force-push or create a new branch name |
| PR already exists for this branch | Show existing PR URL and ask whether to update |
| No test framework found | Run static analysis with get_problems, verify manually, and note in PR |
| Issue contains multiple problems | Fix the most critical problem first; note remaining items as follow-up |
| Fix branch already exists | Ask user to reuse, recreate, or rename the branch |
gh CLI credentials. No additional credentials are stored.