Fix Issue Github Auto
Fully automate resolving a GitHub issue: create a linked branch, apply code changes, commit, open a PR, and resolve any conflicts.
Fully automate resolving a GitHub issue: create a linked branch, apply code changes, commit, open a PR, and resolve any conflicts.
$ARGUMENTS is the issue number. If $ARGUMENTS is empty, ask the user to provide an issue number and stop.
Steps:
-
Check that
ghis installed and authenticated by runninggh auth status. If not, tell the user and stop. Rungh issue view $ARGUMENTS --json title,stateto confirm the issue exists and is open. If it doesn't exist or is already closed, tell the user and stop. -
Check if
gh issue developis available by runninggh issue develop --help 2>/dev/null. Then:- If available: run
gh issue develop $ARGUMENTS --checkout. GitHub names the branch<number>-<issue-title-slug>automatically and links it to the issue. - If not available (older gh): derive the branch name from the issue number and title — lowercase, spaces and special characters replaced with hyphens, truncated to ~5 words, prefixed with the issue number (e.g.
12-add-decision-command). Rungit checkout -b <branch-name>.
- If available: run
-
Run
gh issue view $ARGUMENTS --json title,body,comments,labelsto fetch the full issue context. Analyse the title, body, and comments to understand what is being requested. Explore the codebase to find the relevant files, reading them to understand the current implementation before making any changes. Apply the minimum code changes needed to resolve the issue — fix bugs by correcting the root cause, add features by following existing patterns, and do not refactor or change unrelated code. -
Run
git diff --staged --statto check for staged changes. If nothing is staged, rungit add -Ato stage everything. Rungit diff --stagedto review what will be committed. Runls CHANGELOG.md 2>/dev/null— if a changelog exists, regenerate the## Unreleasedsection treating the new changes as already included, write it back toCHANGELOG.md, and rungit add CHANGELOG.md. Write a commit message in Conventional Commits format (type(scope): short description, imperative tense, under 72 characters). Commit immediately withgit commit -m "...". -
Get the default branch with
gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'. Check if an upstream is set withgit rev-parse --abbrev-ref --symbolic-full-name @{upstream} 2>/dev/null. If not set, rungit push -u origin HEAD. If set, rungit push. Rungit log --oneline <base>..HEADandgit diff <base>...HEAD --statto understand the branch changes. Derive a PR title (imperative tense, under 72 chars) and description from the commits and issue context. IncludeCloses #$ARGUMENTSin the PR body to link the issue. Check if a PR already exists withgh pr view --json url,number 2>/dev/null. If no PR exists, rungh pr create --title "<title>" --body "<description>". If one exists, rungh pr edit --title "<title>" --body "<description>". -
Run
gh pr view --json mergeable --jq '.mergeable'. If the result isCONFLICTING:- Run
git fetch originthengit rebase origin/<base>. - If the rebase stops with conflicts, run
git diff --name-only --diff-filter=Uto list conflicting files. For each file, read it, resolve conflicts by merging both sides if both changes are needed, preferring incoming (theirs) if it supersedes the current change, or keeping current (ours) if the incoming change is unrelated. Rungit add <file>after resolving each file. Rungit rebase --continuewhen all conflicts are resolved. - If a conflict is too ambiguous to resolve safely, run
git rebase --abort, explain what was ambiguous, and ask the user to resolve it manually. - On success, run
git push --force-with-lease.
- Run
-
Print the PR URL, confirm the issue is linked, and summarise what code was changed and why.
$ARGUMENTS