Skip to content

feat(utils): add fix-pr command for automated PR remediation#240

Open
cardil wants to merge 1 commit intoopenshift-eng:mainfrom
cardil:feature/add-fix-pr-command
Open

feat(utils): add fix-pr command for automated PR remediation#240
cardil wants to merge 1 commit intoopenshift-eng:mainfrom
cardil:feature/add-fix-pr-command

Conversation

@cardil
Copy link

@cardil cardil commented Dec 19, 2025

Summary

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.

Features

Three-Phase Loop

Each iteration performs up to three phases:

  1. Phase 1: Resolve Conflicts - Rebase on base branch, auto-resolve conflicts
  2. Phase 2: Address Review Comments - Fetch, categorize, and fix review feedback
  3. Phase 3: Fix CI Checks - Analyze failures, implement fixes, verify locally

Flags

  • --skip-reviews: Skip Phase 2 (only handle conflicts + CI)
  • --skip-rebase: Skip Phase 1 (only handle reviews + CI)
  • -n N: Configure max iterations (default: 5)

Key Capabilities

  • ✅ Intelligent conflict resolution via rebase
  • ✅ Integrates with existing /utils:address-reviews logic
  • ✅ Automated CI failure analysis and fixes
  • Critical code coverage enforcement - Coverage failures treated as BLOCKING
  • ✅ Local validation (tests/lint/build/coverage) before pushing
  • ✅ Clean git history (amends commits vs. creating new ones)
  • ✅ Idempotent and safe to run multiple times

Use Cases

  1. Get PR ready to merge - One command to handle all remediation
  2. Complex review feedback - Reviews that might break CI are handled in loop
  3. Merge conflicts - Auto-rebase and resolve conflicts
  4. Flaky tests - Multiple iterations handle intermittent failures
  5. Coverage enforcement - Adds targeted unit tests when coverage drops

Examples

# Default: all phases, 5 iterations
/utils:fix-pr

# Custom iterations
/utils:fix-pr -n 10

# Skip reviews, only fix CI
/utils:fix-pr --skip-reviews

# Skip rebase, only reviews + CI
/utils:fix-pr --skip-rebase

# Specific PR with combined flags
/utils:fix-pr 123 -n 3 --skip-rebase

Test Plan

  • Test on PR with failing CI checks
  • Test on PR with merge conflicts
  • Test on PR with review comments
  • Test with --skip-reviews flag
  • Test with --skip-rebase flag
  • Test with -n custom iterations
  • Test code coverage failure handling
  • Verify command appears in /plugin reload
  • Verify documentation updated correctly

Assisted-By: 🤖 Claude Sonnet 4.5 noreply@anthropic.com

Summary by CodeRabbit

  • New Features

    • Added /utils:fix-pr command to automatically resolve PR conflicts, address review comments, and fix CI failures iteratively with optional skips for reviews or rebasing.
  • Documentation

    • Added comprehensive documentation and usage examples for the new fix-pr command.

✏️ Tip: You can customize this high-level summary in your review settings.

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>
@openshift-ci
Copy link

openshift-ci bot commented Dec 19, 2025

[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 theobarberbany 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
Copy link
Contributor

coderabbitai bot commented Dec 19, 2025

Walkthrough

Adds documentation for a new /utils:fix-pr command to the Utils plugin that iteratively fixes PR checks and addresses review comments until the PR is mergeable. The command accepts a PR number with optional flags for iteration count, skipping reviews, and skipping rebase operations.

Changes

Cohort / File(s) Summary
Command documentation
PLUGINS.md, docs/data.json
Updated plugin registry and manifest to include new /utils:fix-pr command with signature [PR number] [-n N] [--skip-reviews] [--skip-rebase] and description.
Command specification
plugins/utils/commands/fix-pr.md
Added comprehensive recipe documentation detailing the fix-pr workflow, including argument parsing, three-phase remediation loop (merge conflicts, review comments, CI checks), termination conditions, verification steps, and usage examples.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

  • All changes are documentation-only with no implementation code
  • Changes are repetitive across files (consistent command metadata)
  • Primary review focus: verify command signature consistency and documentation clarity across the three updated locations

Pre-merge checks and finishing touches

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 The new fix-pr.md documentation contains multiple hardcoded git remote references (origin) without first discovering actual remote names through git remote discovery commands. Update fix-pr.md to discover the primary remote using git remote -v, store it in a variable, and replace all hardcoded origin references with this variable throughout.
Git Push Safety Rules ❌ Error The fix-pr command specification violates Git Push Safety Rules by performing autonomous git push --force-with-lease operations without explicit user permission across all remediation phases. Remove all git push --force-with-lease operations and replace with standard git push, or require explicit user confirmation before any push operation.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding a new fix-pr command to the utils plugin for automated PR remediation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
No Real People Names In Style References ✅ Passed Pull request documentation contains no real people's names used as style references. Only AI tool/model names (Claude Code, Claude Sonnet 4.5) found.
No Untrusted Mcp Servers ✅ Passed No MCP server installations, references, or package dependencies introduced in PR. Documentation-only changes with no code or dependency modifications.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 47cd45c and eabb6bb.

📒 Files selected for processing (3)
  • PLUGINS.md (1 hunks)
  • docs/data.json (1 hunks)
  • plugins/utils/commands/fix-pr.md (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
plugins/utils/commands/fix-pr.md

31-31: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)

🔇 Additional comments (14)
PLUGINS.md (1)

295-295: LGTM! Clear and consistent command documentation.

The command entry is well-formatted and provides a clear description of the command's purpose. The signature matches the expected format.

docs/data.json (1)

450-455: LGTM! Consistent command metadata.

The JSON entry matches the documentation in PLUGINS.md and follows the established structure for command metadata in this file.

plugins/utils/commands/fix-pr.md (12)

1-13: LGTM! Consistent command signature.

The frontmatter and synopsis section are well-structured and match the signatures defined in PLUGINS.md and docs/data.json.


14-22: LGTM! Clear and comprehensive description.

The description effectively communicates the command's purpose and provides practical use cases that align with the PR objectives.


25-46: LGTM! Well-structured argument parsing.

The argument parsing logic is clear and handles all the necessary cases. The default of 5 iterations is reasonable, and the verification of a clean working tree is good practice.


53-121: LGTM! Robust conflict resolution workflow.

The conflict resolution phase is well-designed with appropriate handling of edge cases, intelligent auto-resolution with user fallback, and safe force-pushing using --force-with-lease. The inclusion of a wait period for GitHub to recognize the rebase is a thoughtful detail.


122-157: LGTM! Well-integrated review addressing workflow.

The review comment addressing phase appropriately reuses logic from the existing /utils:address-reviews command and handles different comment types with proper prioritization. The AI-assisted response footer provides good transparency.


158-224: LGTM! Comprehensive CI failure handling with strong coverage enforcement.

The CI check fixing phase is well-designed with appropriate waiting logic, failure analysis, and local validation. The emphasis on treating code coverage failures as CRITICAL/blocking issues (lines 202-206) aligns well with the PR objectives and ensures quality standards are maintained.


225-255: LGTM! Well-defined termination conditions.

The loop termination logic covers all necessary cases, including detecting when external blockers prevent progress. User prompts at max iterations provide good control over the workflow.


256-308: LGTM! Thorough verification and reporting.

The final verification and summary sections provide comprehensive feedback on the PR status and what actions were taken during the remediation process. The detailed breakdown by phase is particularly helpful for understanding what the command accomplished.


315-424: LGTM! Comprehensive and realistic examples.

The examples section provides excellent coverage of different usage patterns with realistic output. Example 1 is particularly valuable as it shows the complete multi-iteration workflow with all phases in action.


425-430: LGTM! Clear argument documentation.

The arguments section provides a concise reference that is consistent with the command signature documented throughout the file.


431-445: LGTM! Comprehensive implementation guidelines.

The guidelines section provides excellent guidance covering UX considerations, technical best practices, and critical requirements. The emphasis on code coverage as a blocking issue (line 444) reinforces the implementation details and ensures proper handling.


446-460: LGTM! Valuable design context and rationale.

The notes section effectively explains the design rationale behind the three-phase loop approach and sets appropriate expectations for handling complex scenarios. The emphasis on idempotency and graceful handling is important for a command of this complexity.


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

@openshift-ci openshift-ci bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Dec 19, 2025
@openshift-ci
Copy link

openshift-ci bot commented Dec 19, 2025

Hi @cardil. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

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

Labels

needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant