Skip to content

feat(utils): add fix-pr command for automated PR/MR remediation#614

Open
cardil wants to merge 5 commits into
openshift-eng:mainfrom
cardil:feature/add-fix-pr-command
Open

feat(utils): add fix-pr command for automated PR/MR remediation#614
cardil wants to merge 5 commits into
openshift-eng:mainfrom
cardil:feature/add-fix-pr-command

Conversation

@cardil

@cardil cardil commented Jul 9, 2026

Copy link
Copy Markdown

Adds /utils:fix-pr command that iteratively resolves merge conflicts, addresses review comments, and fixes CI failures until the PR/MR is mergeable.

Key features:

  • Works with both GitHub PRs and GitLab MRs (auto-detected via review tool)
  • Single review get call per iteration for all state (threads, mergeability, CI)
  • Uses review reply for posting replies to review threads
  • Installs review from cardil/review if missing, detects PATH bin dir
  • --auto-approve=no|ai|human|all controls reply confirmation (default: ai -- bots auto-posted, humans require confirmation)
  • Human reply drafts shown in message, question tool used for yes/no approval
  • --skip-reviews, --skip-rebase, -n N flags

Supersedes #240.

Assisted-by: 🤖 claude-sonnet-4-6

Summary by CodeRabbit

  • Documentation
    • Added a new guide for the /utils:fix-pr command.
    • Documented how to run it, required inputs, and available options for skipping review/rebase steps, controlling iteration count, and setting auto-approval behavior.
    • Expanded usage details with examples, expected outcomes, and notes on stopping conditions and how blockers are reported.

@openshift-ci openshift-ci Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 9, 2026
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a new /utils:fix-pr command reference and command-list entry, updates utils plugin version metadata to 0.0.13, and documents an iterative workflow for resolving merge conflicts, review comments, and CI failures until a PR/MR is mergeable.

Changes

Utils plugin fix-pr documentation and metadata

Layer / File(s) Summary
Metadata and command index
PLUGINS.md, .claude-plugin/marketplace.json, plugins/utils/.claude-plugin/plugin.json, docs/index.html
Adds fix-pr to the utils command listings and bumps the utils plugin version to 0.0.13 across the published metadata.
Command intro and setup
plugins/utils/commands/fix-pr.md
Introduces utils:fix-pr and documents prerequisites, PR/MR number selection, flag parsing, and initial workspace checks.
Iterative remediation loop
plugins/utils/commands/fix-pr.md
Documents the per-iteration flow for conflict resolution, review-thread replies, CI failure inspection, and loop termination conditions.
Verification and usage details
plugins/utils/commands/fix-pr.md
Documents final mergeability checks, output and return semantics, usage examples, CLI arguments, and operational notes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: approved, lgtm

Suggested reviewers: cblecker, bentito

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant FixPr as utils:fix-pr
  participant ReviewGet as review get
  participant ReviewReply as review reply
  participant CI as CI checks
  User->>FixPr: run with PR/MR number and flags
  FixPr->>ReviewGet: fetch PR/MR state for the iteration
  FixPr->>ReviewReply: post replies for unresolved review threads
  FixPr->>CI: inspect failed checks and logs
  FixPr->>User: continue loop until mergeable or blocked
Loading

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (2 errors)

Check name Status Explanation Resolution
No Assumed Git Remote Names ❌ Error New utils:fix-pr docs hardcode git fetch origin, git rebase origin/..., and git rebase origin/main without remote discovery first. Replace fixed remote names with a discovered remote variable (e.g. via git remote -v/git branch -vv) and use that throughout the workflow.
Git Push Safety Rules ❌ Error The new /utils:fix-pr docs repeatedly prescribe git push --force-with-lease, a forbidden force-push variant, and do not require explicit user permission before pushing. Remove all force-push steps and require explicit user approval before any push; use ordinary pushes only on approved feature branches, never main/master.
✅ Passed checks (8 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding the utils fix-pr command for automated PR/MR remediation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
No Real People Names In Style References ✅ Passed No real-person names appear as style references or examples; the only named examples are assistant/tool names like Roo, Zoo, and Opencode.
No Untrusted Mcp Servers ✅ Passed Touched files only add utils:fix-pr docs/version bumps; no new mcpServers, npx @..., or MCP server installs were added. The only install is cardil/review, not MCP.
Ai-Helpers Overlap Detection ✅ Passed No open PR with overlapping ai-helpers paths/titles; closest docs (address-review-pr, gh-attention, check-pr-ci-status) are related but below 60%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@openshift-ci
openshift-ci Bot requested review from brandisher and celebdor July 9, 2026 10:09
@openshift-ci

openshift-ci Bot commented Jul 9, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: cardil
Once this PR has been reviewed and has the lgtm label, please assign stbenjam for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/data.json`:
- Around line 450-455: The generated docs artifacts are out of sync with the
current fix-pr metadata. Regenerate the docs from the source command definition
in fix-pr.md so the updated argument_hint, description, and synopsis are
reflected consistently in both docs/data.json and PLUGINS.md.

In `@PLUGINS.md`:
- Line 295: The `/utils:fix-pr` command hint in the generated docs is out of
sync with the command’s frontmatter. Regenerate the entry sourced from
docs/data.json so the bullet matches the actual argument_hint for fix-pr.md,
including the PR/MR reference and the --auto-approve option. Locate the
generated command text for /utils:fix-pr and update it from the underlying
metadata rather than editing the displayed string manually.

In `@plugins/utils/commands/fix-pr.md`:
- Around line 10-12: The fenced example in fix-pr.md is unlabeled and triggers
markdownlint MD040; update the markdown fences in this document to use an
appropriate language tag such as bash, text, or diff so the example is properly
labeled. Keep the existing command example intact and ensure any other fenced
blocks in the file follow the same pattern.
- Around line 120-137: The rebase workflow in the command guide still instructs
`git push --force-with-lease`, which must be removed from this `fix-pr` flow.
Update the rebase handling section to use a non-destructive push path or require
an explicit user confirmation gate before any push, and make sure the steps
around rebase resolution in this document no longer mention any force-push
variant. Keep the guidance aligned with the existing `Handle rebase outcome` and
`git rebase --continue` flow while replacing the final push instruction with a
safe alternative.
- Around line 79-89: Clarify the polling contract around review get so it does
not read like a one-time fetch for all phases. Update the documentation around
review get <PR_NUMBER> to state that the full PR/MR snapshot should be fetched
at the start of each iteration, and re-run after rebases and while waiting for
CI. Keep the existing snapshot/phase explanation, but make the repeated-use
behavior explicit in the same section.
- Around line 241-244: The failed CI log collection step in the PR fix guide is
GitHub-only and needs a GitLab fallback. Update the instructions around the
“Fetch failure details” step to either add a `glab ci view`/`glab ci trace` path
for GitLab or clearly label the existing `gh run view` flow as GitHub-specific;
keep the wording aligned with the surrounding `review get` guidance in the
fix-pr workflow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 89f47fc5-7636-4d6c-b4e4-1e0656341b5b

📥 Commits

Reviewing files that changed from the base of the PR and between c3f880e and a0325a2.

📒 Files selected for processing (3)
  • PLUGINS.md
  • docs/data.json
  • plugins/utils/commands/fix-pr.md

Comment thread docs/data.json Outdated
Comment thread PLUGINS.md Outdated
Comment thread plugins/utils/commands/fix-pr.md Outdated
Comment thread plugins/utils/commands/fix-pr.md Outdated
Comment thread plugins/utils/commands/fix-pr.md
Comment thread plugins/utils/commands/fix-pr.md Outdated
cardil added 4 commits July 9, 2026 12:14
Add new /utils:fix-pr command that automates the complete PR
remediation workflow by iteratively resolving merge conflicts,
addressing review comments, and fixing failing CI checks.

Key features:
- Three-phase loop: conflicts → reviews → CI checks
- Intelligent conflict resolution via rebase
- Integrates with existing /utils:address-reviews logic
- Automated CI failure analysis and fixes
- --skip-reviews flag for CI-only workflow
- Configurable max iterations (default: 5)

This command helps developers get PRs ready to merge with minimal
manual intervention, handling complex scenarios where review fixes
might break CI or create new conflicts.

Assisted-By: 🤖 Claude Sonnet 4.5 <noreply@anthropic.com>
- Single 'review get' call per iteration for threads, mergeability, CI status
- Use 'review reply' for all review thread replies
- Install review from cardil/review if missing, detect PATH bin dir
- Document GitLab MR support alongside GitHub PRs

Assisted-by: 🤖 claude-sonnet-4-6
- Add --auto-approve=no|ai|human|all flag (default: ai)
- Human reviewer replies require confirmation by default
- Bot replies auto-posted by default
- Draft shown in normal message, question tool used only for yes/no
- Examples: ask_followup_question (Roo/Zoo), question (Opencode)
- Remove AI footer from replies

Assisted-by: 🤖 claude-sonnet-4-6
Assisted-by: 🤖 claude-sonnet-4-6
@cardil
cardil force-pushed the feature/add-fix-pr-command branch from a0325a2 to 5d037d0 Compare July 9, 2026 10:14
@openshift-ci openshift-ci Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 9, 2026
Comment thread plugins/utils/commands/fix-pr.md Outdated
- Add language tags to all fenced code blocks (MD040)
- Clarify review get polling contract (re-run after rebase and while waiting for CI)
- Add GitLab fallback for failed CI log fetching (glab ci view / glab ci trace)
- Replace 'gracefully' with specific error handling description
- Bump utils plugin version to 0.0.13
- Regenerate docs/index.html and marketplace.json

Assisted-by: 🤖 claude-sonnet-4-6

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
plugins/utils/commands/fix-pr.md (1)

355-356: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use the resolved base branch here instead of hardcoding main.

These instructions should mirror the earlier BASE_BRANCH lookup. Hardcoding origin/main / main makes the guide wrong for repos whose target branch is not main, including GitLab MRs.

♻️ Proposed fix
-   Resolve conflicts with: git rebase origin/main
+   Resolve conflicts with: git rebase origin/${BASE_BRANCH}
...
-   🔄 Rebasing on main...
+   🔄 Rebasing on ${BASE_BRANCH}...

Also applies to: 417-418

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/utils/commands/fix-pr.md` around lines 355 - 356, The
conflict-resolution instruction is hardcoded to use origin/main, which breaks
repos whose base branch is not main. Update the rebase guidance in the fix-pr
markdown to use the resolved base branch value, matching the earlier BASE_BRANCH
lookup logic, and make the same replacement in the other referenced location so
both instructions stay consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@plugins/utils/commands/fix-pr.md`:
- Around line 355-356: The conflict-resolution instruction is hardcoded to use
origin/main, which breaks repos whose base branch is not main. Update the rebase
guidance in the fix-pr markdown to use the resolved base branch value, matching
the earlier BASE_BRANCH lookup logic, and make the same replacement in the other
referenced location so both instructions stay consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3622c5e7-1081-4b91-97ae-9cf1e210d2ec

📥 Commits

Reviewing files that changed from the base of the PR and between 5d037d0 and 74956dc.

📒 Files selected for processing (4)
  • .claude-plugin/marketplace.json
  • docs/index.html
  • plugins/utils/.claude-plugin/plugin.json
  • plugins/utils/commands/fix-pr.md
✅ Files skipped from review due to trivial changes (1)
  • plugins/utils/.claude-plugin/plugin.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant