| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
✅ Deploy Preview for commit-check ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Sorry, something went wrong.
|
Warning Review limit reached@shenxianpeng, you've reached your PR review limit, so we couldn't start this review. Next review available in: 34 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR. To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 4711a9fa-541f-48f0-9f67-ac50ae1e1b5a 📥 CommitsReviewing files that changed from the base of the PR and between 4735bee and be6a2c3. 📒 Files selected for processing (2)
WalkthroughThe _find_target_branch method in MergeBaseValidator is refactored to resolve target branches using git rev-parse --verify against normalized branch names, checking local refs first and then origin/<branch> remote refs, replacing prior git branch -a regex parsing. Corresponding unit tests are added. ChangesTarget branch resolution refactor
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant Validator as MergeBaseValidator
participant Git as subprocess (git rev-parse --verify)
Caller->>Validator: _find_target_branch(pattern)
Validator->>Validator: strip ^/$ anchors
alt branch_name empty
Validator-->>Caller: None
else branch_name present
Validator->>Git: rev-parse --verify branch_name
alt local verify succeeds
Git-->>Validator: success
Validator-->>Caller: branch_name
else local verify fails
Validator->>Git: rev-parse --verify origin/branch_name
alt remote verify succeeds
Git-->>Validator: success
Validator-->>Caller: branch_name
else remote verify fails
Git-->>Validator: failure
Validator-->>Caller: None
end
end
end
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. ❤️ ShareComment @coderabbitai help to get the list of available commands. |
Sorry, something went wrong.
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #451 +/- ##
==========================================
+ Coverage 96.60% 96.89% +0.28%
==========================================
Files 10 10
Lines 1090 1094 +4
==========================================
+ Hits 1053 1060 +7
+ Misses 37 34 -3 ☔ View full report in Codecov by Harness.
|
Sorry, something went wrong.
There was a problem hiding this comment.
commit_check/engine.py (2)🤖 Prompt for all review comments with AI agents463-484: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
Deduplicate ref verification and broaden exception handling.
The local and remote checks are identical except for the ref string, and both only catch subprocess.CalledProcessError, so a missing git executable (FileNotFoundError/OSError) would propagate unhandled instead of falling through to return None like the rest of this method does.
♻️ Proposed refactor to consolidate the duplicated verification logic🤖 Prompt for AI Agents- # Try local branch first - try: - subprocess.run( - ["git", "rev-parse", "--verify", branch_name], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - check=True, - ) - return branch_name - except subprocess.CalledProcessError: - pass - - # Try remote tracking branch under origin/ - try: - subprocess.run( - ["git", "rev-parse", "--verify", f"origin/{branch_name}"], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - check=True, - ) - return branch_name - except subprocess.CalledProcessError: - pass - - return None + def _ref_exists(ref: str) -> bool: + try: + subprocess.run( + ["git", "rev-parse", "--verify", ref], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + check=True, + ) + return True + except (subprocess.CalledProcessError, OSError): + return False + + if _ref_exists(branch_name) or _ref_exists(f"origin/{branch_name}"): + return branch_name + + return NoneVerify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@commit_check/engine.py` around lines 463 - 484, The ref verification in the branch lookup method is duplicated and only handles subprocess.CalledProcessError, so missing git or other OS-level failures can escape instead of falling through cleanly. Refactor the local and origin/ checks in the branch-resolution logic to share a single verification path keyed by the ref string, and broaden the exception handling around subprocess.run in this method to also catch FileNotFoundError/OSError so it still returns None on any verification failure.
455-456: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
Move subprocess/re imports to module top-level.
Local import subprocess / import re inside the method is non-idiomatic; both are cheap, stdlib, and unconditionally needed, so hoist them to the top of the file for consistency with the rest of the module.
🤖 Prompt for AI AgentsVerify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@commit_check/engine.py` around lines 455 - 456, Move the local subprocess and re imports out of the method and into the module-level import block in engine.py; these stdlib imports are used unconditionally, so update the top-of-file imports and remove the in-method import statements from the code path around the affected function.
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Nitpick comments: In `@commit_check/engine.py`: - Around line 463-484: The ref verification in the branch lookup method is duplicated and only handles subprocess.CalledProcessError, so missing git or other OS-level failures can escape instead of falling through cleanly. Refactor the local and origin/ checks in the branch-resolution logic to share a single verification path keyed by the ref string, and broaden the exception handling around subprocess.run in this method to also catch FileNotFoundError/OSError so it still returns None on any verification failure. - Around line 455-456: Move the local subprocess and re imports out of the method and into the module-level import block in engine.py; these stdlib imports are used unconditionally, so update the top-of-file imports and remove the in-method import statements from the code path around the affected function.
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 29e5e2c2-0bbd-47b2-8b8c-439c762ea853
📥 CommitsReviewing files that changed from the base of the PR and between ac1e9a9 and 4735bee.
📒 Files selected for processing (2)
Sorry, something went wrong.
Merging this PR will not alter performance✅ 312 untouched benchmarks Comparing bugfix/find-target-branch-use-rev-parse (be6a2c3) with main (ac1e9a9) Footnotes
|
Sorry, something went wrong.
The old _find_target_branch method scanned all branches via git branch -a and used a loose regex match, which could cause false positives: a pattern like 'main' could match 'main-old', 'main-staging', etc. depending on the order git branch -a outputs branches. The new approach: 1. Strips common regex anchors (^, $) from the pattern to get a clean name 2. Uses git rev-parse --verify <name> for exact local ref resolution 3. Falls back to git rev-parse --verify origin/<name> for remote tracking This makes require_rebase_target safe to recommend to users.
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Problem
MergeBaseValidator._find_target_branch used git branch -a + re.match() to locate the target branch. This approach is fragile because a loose regex like main could match main-old, main-staging, origin/main, etc. — whichever appeared first in git branch -a output (which is non-deterministic). This class of bug makes merge_base validation unreliable in CI.
Solution
Replace the regex-based branch list scan with precise ref resolution using git rev-parse --verify:
Using the full refs/heads/ and refs/remotes/origin/ paths eliminates any possibility of resolving to a tag or other non-branch ref — matching the old behavior which only scanned git branch -a (branches only).
Regression Analysis
All edge cases verified against old behavior:
Test Plan