fix(webhook): skip deletion events and update tests for None return v…#912
fix(webhook): skip deletion events and update tests for None return v…#912
Conversation
WalkthroughRemoved requests library dependency from ping response, changed ping responses to return None instead of a dict, and introduced an early-exit path for push events when branch or tag deletion is detected, along with corresponding test updates. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related issues
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 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 |
|
Report bugs in Issues Welcome! 🎉This pull request will be automatically processed with the following features: 🔄 Automatic Actions
📋 Available CommandsPR Status Management
Review & Approval
Testing & Validation
Container Operations
Cherry-pick Operations
Label Management
✅ Merge RequirementsThis PR will be automatically approved when the following conditions are met:
📊 Review ProcessApprovers and ReviewersApprovers:
Reviewers:
Available Labels
💡 Tips
For more information, please refer to the project documentation or contact the maintainers. |
…alues Skip processing for branch/tag deletion events (deleted=true) to avoid unnecessary git operations and repository cloning. Changes: - Skip processing when hook_data['deleted'] is True - Return None consistently from process() method (ping, deletion events) - Remove unused 'requests' import from github_api.py - Update test assertions to expect None instead of dict return values - Add comprehensive tests for deletion event handling Tests: - test_process_ping_event: Assert None instead of dict - test_process_push_event_deletion: Verify deletion events are skipped - test_process_push_event_normal_push_not_deletion: Verify normal pushes work All tests passing (893 tests), coverage maintained at 90.16%
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
webhook_server/tests/test_github_api.py (2)
1423-1501: Remove unused mock parameter.The
mock_auto_verified_propparameter is defined but never used in the test body. Consider removing it to clean up the test signature.Apply this diff:
@patch("webhook_server.libs.github_api.GithubWebhook.add_api_users_to_auto_verified_and_merged_users") async def test_process_push_event_deletion( self, - mock_auto_verified_prop: Mock, mock_repo_local_data: Mock, mock_get_apis: Mock, mock_api_rate_limit: Mock,Based on static analysis.
1502-1564: Remove unused mock parameter.The
mock_auto_verified_propparameter is defined but never used in the test body. Consider removing it to clean up the test signature.Apply this diff:
@patch("webhook_server.libs.github_api.GithubWebhook.add_api_users_to_auto_verified_and_merged_users") async def test_process_push_event_normal_push_not_deletion( self, - mock_auto_verified_prop: Mock, mock_repo_local_data: Mock, mock_get_apis: Mock, mock_process_push: Mock,Based on static analysis.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
webhook_server/libs/github_api.py(2 hunks)webhook_server/tests/test_github_api.py(2 hunks)
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2024-10-29T08:09:57.157Z
Learnt from: myakove
Repo: myk-org/github-webhook-server PR: 612
File: webhook_server_container/libs/github_api.py:2089-2100
Timestamp: 2024-10-29T08:09:57.157Z
Learning: In `webhook_server_container/libs/github_api.py`, when the function `_keep_approved_by_approvers_after_rebase` is called, existing approval labels have already been cleared after pushing new changes, so there's no need to check for existing approvals within this function.
Applied to files:
webhook_server/libs/github_api.pywebhook_server/tests/test_github_api.py
📚 Learning: 2025-10-30T00:18:06.176Z
Learnt from: myakove
Repo: myk-org/github-webhook-server PR: 878
File: webhook_server/libs/github_api.py:111-118
Timestamp: 2025-10-30T00:18:06.176Z
Learning: In webhook_server/libs/github_api.py, when creating temporary directories or performing operations that need repository names, prefer using self.repository_name (from webhook payload, always available) over dereferencing self.repository.name or self.repository_by_github_app.name, which may be None. This avoids AttributeError and keeps the code simple and reliable.
Applied to files:
webhook_server/libs/github_api.py
📚 Learning: 2024-10-08T09:19:56.185Z
Learnt from: myakove
Repo: myk-org/github-webhook-server PR: 586
File: webhook_server_container/libs/github_api.py:1947-1956
Timestamp: 2024-10-08T09:19:56.185Z
Learning: In `webhook_server_container/libs/github_api.py`, the indentation style used in the `set_pull_request_automerge` method is acceptable as per the project's coding standards.
Applied to files:
webhook_server/libs/github_api.py
📚 Learning: 2024-10-14T14:12:28.924Z
Learnt from: myakove
Repo: myk-org/github-webhook-server PR: 588
File: webhook_server_container/libs/github_api.py:1638-1639
Timestamp: 2024-10-14T14:12:28.924Z
Learning: In `webhook_server_container/libs/github_api.py`, it is acceptable for `self.repository.owner.email` to be `None` since internal commands can handle this case.
Applied to files:
webhook_server/libs/github_api.py
📚 Learning: 2024-10-14T14:13:21.316Z
Learnt from: myakove
Repo: myk-org/github-webhook-server PR: 588
File: webhook_server_container/libs/github_api.py:1632-1637
Timestamp: 2024-10-14T14:13:21.316Z
Learning: In the `ProcessGithubWehook` class in `webhook_server_container/libs/github_api.py`, avoid using environment variables to pass tokens because multiple commands with multiple tokens can run at the same time.
Applied to files:
webhook_server/libs/github_api.py
🧬 Code graph analysis (2)
webhook_server/libs/github_api.py (1)
webhook_server/utils/helpers.py (1)
format_task_fields(117-136)
webhook_server/tests/test_github_api.py (1)
webhook_server/libs/github_api.py (2)
GithubWebhook(50-729)process(308-518)
🪛 Ruff (0.14.5)
webhook_server/tests/test_github_api.py
1432-1432: Unused method argument: mock_auto_verified_prop
(ARG002)
1512-1512: Unused method argument: mock_auto_verified_prop
(ARG002)
🔇 Additional comments (3)
webhook_server/libs/github_api.py (2)
326-326: LGTM: Consistent return value across event handlers.The change from returning a dict to None makes the ping handler consistent with all other event handlers in the codebase.
335-346: LGTM: Efficient early-exit for deletion events.The deletion check correctly skips unnecessary git operations while maintaining proper logging and metrics collection. Using
.get("deleted")safely handles cases where the key is absent.webhook_server/tests/test_github_api.py (1)
231-231: LGTM: Test correctly updated for new return value.The assertion properly verifies that ping events now return None instead of a dict.
|
New container for ghcr.io/myk-org/github-webhook-server:latest published |
…alues
Skip processing for branch/tag deletion events (deleted=true) to avoid unnecessary git operations and repository cloning.
Changes:
Tests:
All tests passing (893 tests), coverage maintained at 90.16%
Summary by CodeRabbit
Bug Fixes
Tests
Chores