Expose push safety validation#9
Conversation
📝 WalkthroughWalkthroughThis PR adds push-safety validation to the MCP server through a new ChangesPush Safety Validation Feature
Dependabot Configuration Update
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9 +/- ##
==========================================
+ Coverage 62.94% 66.02% +3.08%
==========================================
Files 2 2
Lines 197 209 +12
==========================================
+ Hits 124 138 +14
+ Misses 73 71 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@src/commit_check_mcp/server.py`:
- Around line 406-409: The current normalization sets normalized_push_refs =
push_refs.strip() which turns whitespace-only strings into "" and causes
_validate_push to treat them as explicit refs; change the normalization so that
after stripping any string that becomes empty is coerced to None (e.g., use
push_refs.strip() or None) so normalized_push_refs is None for
empty/whitespace-only input before calling _validate_push; update the assignment
that creates normalized_push_refs (and keep using _normalize_repo_path and the
_validate_push call) so downstream logic uses upstream fallback correctly.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 348d62d1-e17a-4137-9fd4-1940d2325108
⛔ Files ignored due to path filters (1)
uv.lockis excluded by!**/*.lock
📒 Files selected for processing (4)
.github/dependabot.ymlREADME.mdsrc/commit_check_mcp/server.pytests/test_server.py
| normalized_push_refs = push_refs.strip() if isinstance(push_refs, str) else None | ||
| normalized_repo_path = _normalize_repo_path(repo_path) | ||
| return _validate_push( | ||
| normalized_push_refs, |
There was a problem hiding this comment.
Reject whitespace-only push_refs input to avoid fallback misrouting.
On Line 406, whitespace-only input is normalized to "" and forwarded. That makes _validate_push treat it as explicit refs (push_upstream_fallback=False) instead of upstream fallback. Please reject empty strings (or coerce them to None) after normalization.
Suggested fix
def validate_push_safety(
@@
) -> dict[str, Any]:
"""Validate that a push is not a force push."""
normalized_push_refs = push_refs.strip() if isinstance(push_refs, str) else None
+ if isinstance(push_refs, str) and not normalized_push_refs:
+ raise ValueError("push_refs cannot be empty when provided")
normalized_repo_path = _normalize_repo_path(repo_path)
return _validate_push(📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| normalized_push_refs = push_refs.strip() if isinstance(push_refs, str) else None | |
| normalized_repo_path = _normalize_repo_path(repo_path) | |
| return _validate_push( | |
| normalized_push_refs, | |
| normalized_push_refs = push_refs.strip() if isinstance(push_refs, str) else None | |
| if isinstance(push_refs, str) and not normalized_push_refs: | |
| raise ValueError("push_refs cannot be empty when provided") | |
| normalized_repo_path = _normalize_repo_path(repo_path) | |
| return _validate_push( | |
| normalized_push_refs, |
🤖 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 `@src/commit_check_mcp/server.py` around lines 406 - 409, The current
normalization sets normalized_push_refs = push_refs.strip() which turns
whitespace-only strings into "" and causes _validate_push to treat them as
explicit refs; change the normalization so that after stripping any string that
becomes empty is coerced to None (e.g., use push_refs.strip() or None) so
normalized_push_refs is None for empty/whitespace-only input before calling
_validate_push; update the assignment that creates normalized_push_refs (and
keep using _normalize_repo_path and the _validate_push call) so downstream logic
uses upstream fallback correctly.
Summary
closes #8
Validation
Summary by CodeRabbit
Release Notes
New Features
Documentation