Skip to content

fix(hooks): check the PR the merge command actually targets - #3868

Merged
zackees merged 1 commit into
masterfrom
fix/pr-merge-hook-repo-aware
Aug 7, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/pr-merge-hook-repo-aware

Conversation

@zackees

@zackees zackees commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Problem

The gh pr merge review guard (ci/hooks/check_pr_merge_reviews.py) ran coderabbit_addressor.py --check with no arguments, which resolves "the PR for the current branch of the current checkout". It ignored both the PR number and the --repo in the command it was inspecting.

Two consequences:

  1. Wrong repository. Merging a sibling project's PR (gh pr merge N --repo OWNER/NAME) was judged against this checkout instead of OWNER/NAME.
  2. False-positive block. When the current branch had no PR of its own, the addressor exited 2 — no PR found for current branch — and the hook treated that as a block. A fully reviewed merge was refused because of unrelated local state.

Hit in practice while merging FastLED/fbuild#1268 with this checkout sitting on master: the guard refused, even though that PR had 0 actionable CodeRabbit comments and 5/5 pre-merge checks passed. Neither documented override (FL_HOOK_SKIP=1, FL_HOOK_SOFT=1) reaches the hook's shell, so there was no way through short of reshaping the command to evade the guard — which is exactly what a guard shouldn't force.

Fix

  • The hook parses the target PR number and repo out of the merge command and forwards them: bare number, --repo/-R in either order, --repo=VALUE, and PR URLs. URLs carry their own owner/repo, so they no longer silently fall back to the current checkout — that was a bug in my first cut of this change, caught by the table test below.
  • coderabbit_addressor.py gains --repo OWNER/NAME, overriding the slug used for the API calls. It requires an explicit PR number, since "the PR for the current branch" is meaningless across repositories.
  • Exit 2 no longer blocks. From the addressor it means "could not identify a PR", not "this PR has unresolved reviews". It now allows with a warning; only a real unresolved-comment verdict (exit 1) blocks. The guard exists to protect review state — where there is no identifiable PR, there is none to protect.

This is strictly a targeting fix. A merge with genuinely unresolved CodeRabbit threads still blocks exactly as before.

Validation

Live case, which previously failed:

$ uv run python ci/tools/coderabbit_addressor.py 1268 --check --repo FastLED/fbuild
exit=0        # correctly reports no unresolved comments on the fbuild PR

Guard rail still holds:

$ uv run python ci/tools/coderabbit_addressor.py --check --repo FastLED/fbuild
[address-reviews] --repo requires an explicit PR number

New tests cover all six command shapes plus non-merge commands (gh pr view, gh pr create must not engage the guard).

  • pytest ci/tests/test_check_pr_merge_reviews.py → 7 passed
  • bash lint → clean

Found while working #3867 / FastLED/fbuild#1267.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved pull request merge checks to correctly identify targets from pull request URLs, numbers, branches, and repository options.
    • Cross-repository pull request merges now receive the appropriate review validation.
    • Merge checks no longer block eligible merges when the target pull request cannot be identified, while genuine review failures remain blocking.
  • Tests
    • Added coverage for repository targeting, same-repository merges, branch-based merges, and unrelated CLI commands.

The `gh pr merge` review guard always ran
`coderabbit_addressor.py --check` with no arguments, which resolves "the
PR for the current branch of the current checkout". It ignored both the
PR number and the `--repo` in the command it was inspecting.

Two consequences:

1. Merging a sibling project's PR (`gh pr merge N --repo OWNER/NAME`)
   was judged against the wrong repository entirely.
2. When the current branch had no PR of its own, the addressor exited 2
   ("no PR found for current branch") and the hook treated that as a
   block — so a perfectly reviewed merge was refused because of unrelated
   local state. Hit in practice merging FastLED/fbuild#1268 while this
   checkout sat on master.

Fixes both:

- The hook now parses the target PR number and repo out of the merge
  command — bare number, `--repo`/`-R` in either order, `--repo=VALUE`,
  and PR URLs (which carry their own owner/repo, so they no longer fall
  back to the current checkout) — and forwards them.
- `coderabbit_addressor.py` gains `--repo OWNER/NAME`, which overrides
  the slug used for the GitHub API calls. It requires an explicit PR
  number, since "the PR for the current branch" is meaningless across
  repositories.
- Exit 2 from the addressor means "could not identify a PR", not "this
  PR has unresolved reviews". That now allows the merge with a warning
  instead of blocking; only a real unresolved-comment verdict (exit 1)
  blocks. The guard exists to protect review state, and where there is
  no identifiable PR there is no review state to protect.

Verified against the live case: `coderabbit_addressor.py 1268 --check
--repo FastLED/fbuild` now correctly reports no unresolved comments.

New tests cover all six command shapes plus non-merge commands.
`pytest ci/tests/test_check_pr_merge_reviews.py`: 7 passed. `bash lint`
clean.

Co-Authored-By: Claude <[email protected]>
@zackees
zackees merged commit 02e4535 into master Aug 7, 2026
11 of 17 checks passed
@zackees
zackees deleted the fix/pr-merge-hook-repo-aware branch August 7, 2026 03:07
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7da2dc8c-2ff8-496e-ac2d-2f6c6147dfea

📥 Commits

Reviewing files that changed from the base of the PR and between ccbdc9d and 01110be.

📒 Files selected for processing (3)
  • ci/hooks/check_pr_merge_reviews.py
  • ci/tests/test_check_pr_merge_reviews.py
  • ci/tools/coderabbit_addressor.py

📝 Walkthrough

Walkthrough

The merge hook now identifies pull request and repository targets from gh pr merge commands. The addressor supports explicit repository selection. Non-blocking addressor failures now allow the merge with diagnostics.

Changes

Merge review targeting

Layer / File(s) Summary
Addressor repository override
ci/tools/coderabbit_addressor.py
The addressor accepts --repo with an explicit pull request number and uses the selected repository instead of the current checkout.
Merge hook target resolution
ci/hooks/check_pr_merge_reviews.py, ci/tests/test_check_pr_merge_reviews.py
The hook extracts pull request and repository targets from merge commands, passes them to the addressor, blocks only on exit code 1, and tests supported command forms.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GitHubCLI
  participant check_pr_merge_reviews
  participant coderabbit_addressor
  GitHubCLI->>check_pr_merge_reviews: Run gh pr merge
  check_pr_merge_reviews->>check_pr_merge_reviews: Extract PR and repository
  check_pr_merge_reviews->>coderabbit_addressor: Run --check with target
  coderabbit_addressor-->>check_pr_merge_reviews: Return exit status
Loading
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pr-merge-hook-repo-aware

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant