Iteratively gets a GitHub pull request's checks green. Detects the PR for the current branch or uses a provided PR number, waits for every check on the latest head SHA to appear and finish, investigates failing checks, fixes actionable code or test issues, pushes, and repeats. Escalates with a precise blocker when failures are external, flaky, or not safely fixable. Use when a PR still has unsuccessful checks after review fixes, including after greploop.
Get a GitHub PR to a fully green check state, or exit with a concrete blocker.
check-pr.check-pr.5.If no PR number is provided, detect it from the current branch:
gh pr view --json number,headRefName,headRefOid,url,isDraft
If needed, switch to the PR branch before making changes.
Stop early if:
gh is not authenticatedAlways work against the current PR head SHA:
PR_JSON=$(gh pr view "$PR_NUMBER" --json number,headRefName,headRefOid,url)
HEAD_SHA=$(echo "$PR_JSON" | jq -r .headRefOid)
PR_URL=$(echo "$PR_JSON" | jq -r .url)
Ignore failing checks from older SHAs. After every push, refresh HEAD_SHA and
restart the inspection loop.
Fetch both GitHub check runs and legacy commit status contexts:
gh api "repos/{owner}/{repo}/commits/$HEAD_SHA/check-runs?per_page=100"
gh api "repos/{owner}/{repo}/commits/$HEAD_SHA/status"
For a compact PR-level view, this GraphQL payload is useful:
gh api graphql -f query='
query($owner:String!, $repo:String!, $pr:Int!) {
repository(owner:$owner, name:$repo) {
pullRequest(number:$pr) {
headRefOid
url
statusCheckRollup {
contexts(first:100) {
nodes {
__typename
... on CheckRun { name status conclusion detailsUrl workflowName }
... on StatusContext { context state targetUrl description }
}
}
}
}
}
}' -F owner=OWNER -F repo=REPO -F pr="$PR_NUMBER"
After a new push, checks can take a moment to appear. Poll every 15-30 seconds until one of these is true:
Treat these as terminal success states:
SUCCESS, NEUTRAL, SKIPPEDSUCCESSTreat these as pending:
QUEUED, PENDING, WAITING, REQUESTED, IN_PROGRESSPENDINGTreat these as failures:
FAILURE, TIMED_OUT, CANCELLED, ACTION_REQUIRED, STARTUP_FAILURE, STALEFAILURE, ERRORIf no checks appear for the latest SHA, inspect .github/workflows/, workflow
path filters, and branch protection expectations. If the missing check cannot be
caused or fixed from the repo, escalate.
For GitHub Actions failures, inspect runs and failed logs for the current SHA:
gh run list --commit "$HEAD_SHA" --json databaseId,workflowName,status,conclusion,url,headSha
gh run view <RUN_ID> --json databaseId,name,workflowName,status,conclusion,jobs,url,headSha
gh run view <RUN_ID> --log-failed
For each failing check, classify it:
| Failure type | Action |
|---|---|
| Code/test regression | Reproduce locally, fix, and verify |
| Lint/type/build mismatch | Run the matching local command from the workflow and fix it |
| Flake or transient infra issue | Rerun once if evidence supports flakiness |
| External service/status app failure | Escalate with the details URL and owner guess |
| Missing secret/permission/branch protection issue | Escalate immediately |
Only rerun a failed job once without code changes. Do not loop on reruns.
If the failure is actionable from the checked-out code:
Do not stop at a local fix. The loop is only complete when the remote PR checks for the new head SHA are green.
After each fix:
git push
sleep 5
Then refresh the PR metadata, get the new HEAD_SHA, and restart from Step 3.
Exit the loop only when:
If you cannot get the PR green, report:
Good blocker examples:
When the skill completes, report:
check-pr: it is a repair loop for
PR checks.greploop: Greptile can be perfect while CI is still
red.