Skip to content

Comments

fix(webhook): skip deletion events and update tests for None return v…#912

Merged
myakove merged 1 commit intomainfrom
fix/skip-deletion-events
Nov 17, 2025
Merged

fix(webhook): skip deletion events and update tests for None return v…#912
myakove merged 1 commit intomainfrom
fix/skip-deletion-events

Conversation

@myakove
Copy link
Collaborator

@myakove myakove commented Nov 17, 2025

…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%

Summary by CodeRabbit

  • Bug Fixes

    • Improved webhook processing to properly handle branch and tag deletion events, skipping unnecessary repository cloning and processing.
  • Tests

    • Added comprehensive test coverage for webhook push event handling, including validation of deletion detection and normal push workflows.
  • Chores

    • Removed unused library dependency to simplify the codebase.

@coderabbitai
Copy link

coderabbitai bot commented Nov 17, 2025

Walkthrough

Removed 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

Cohort / File(s) Summary
Core webhook logic
webhook_server/libs/github_api.py
Removed requests dependency from ping path; ping now returns None instead of {"status": codes.ok, "message": "pong"}; added early-exit for push events with deletion flag, including logging skip message and token metrics computation before returning None.
Test coverage
webhook_server/tests/test_github_api.py
Updated ping test to expect None; added test suite for push events with two cases: deletion scenario (verifies skip, no cloning, returns None) and normal push scenario (verifies cloning and handler invocation).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Deletion detection logic: Verify early-exit path handles both branch and tag deletions correctly and doesn't interfere with normal push processing.
  • Return value changes: Confirm that returning None from ping endpoint doesn't break downstream consumers or API contracts.
  • Test completeness: Ensure test stubs adequately cover edge cases (e.g., rate limits, logging behavior during deletions).
  • Control flow: Validate that metrics computation and logging occur before early-exit without side effects.

Possibly related issues

Suggested labels

verified, size/L, branch-main, can-be-merged, commented-myakove

Suggested reviewers

  • rnetser
  • dbasunag

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: skipping deletion events in webhook processing and updating tests to expect None return values.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/skip-deletion-events

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 and usage tips.

@myakove-bot
Copy link
Collaborator

Report bugs in Issues

Welcome! 🎉

This pull request will be automatically processed with the following features:

🔄 Automatic Actions

  • Reviewer Assignment: Reviewers are automatically assigned based on the "
    "OWNERS file in the repository root
    "
    "* Size Labeling: PR size labels (XS, S, M, L, XL, XXL) are "
    "automatically applied based on changes
    "
    f"* Issue Creation: A tracking issue is created for this PR and will be closed when the PR is merged or closed
    "
    "* Pre-commit Checks: pre-commit runs "
    "automatically if .pre-commit-config.yaml exists
    "
  • Branch Labeling: Branch-specific labels are applied to track the target branch
  • Auto-verification: Auto-verified users have their PRs automatically marked as verified

📋 Available Commands

PR Status Management

  • /wip - Mark PR as work in progress (adds WIP: prefix to title)
  • /wip cancel - Remove work in progress status
  • /hold - Block PR merging (approvers only)
  • /hold cancel - Unblock PR merging
  • /verified - Mark PR as verified
  • /verified cancel - Remove verification status
  • /reprocess - Trigger complete PR workflow reprocessing (useful if webhook failed or configuration changed)

Review & Approval

  • /lgtm - Approve changes (looks good to me)
  • /approve - Approve PR (approvers only)
  • /automerge - Enable automatic merging when all requirements are met (maintainers and approvers only)
  • /assign-reviewers - Assign reviewers based on OWNERS file
  • /assign-reviewer @username - Assign specific reviewer
  • /check-can-merge - Check if PR meets merge requirements

Testing & Validation

  • /retest tox - Run Python test suite with tox
  • /retest build-container - Rebuild and test container image
  • /retest python-module-install - Test Python package installation
  • /retest pre-commit - Run pre-commit hooks and checks
  • /retest conventional-title - Validate commit message format
  • /retest all - Run all available tests

Container Operations

  • /build-and-push-container - Build and push container image (tagged with PR number)
    • Supports additional build arguments: /build-and-push-container --build-arg KEY=value

Cherry-pick Operations

  • /cherry-pick <branch> - Schedule cherry-pick to target branch when PR is merged
    • Multiple branches: /cherry-pick branch1 branch2 branch3

Label Management

  • /<label-name> - Add a label to the PR
  • /<label-name> cancel - Remove a label from the PR

✅ Merge Requirements

This PR will be automatically approved when the following conditions are met:

  1. Approval: /approve from at least one approver
  2. LGTM Count: Minimum 1 /lgtm from reviewers
  3. Status Checks: All required status checks must pass
  4. No Blockers: No WIP, hold, or conflict labels
  5. Verified: PR must be marked as verified (if verification is enabled)

📊 Review Process

Approvers and Reviewers

Approvers:

  • myakove
  • rnetser

Reviewers:

  • myakove
  • rnetser
Available Labels
  • hold
  • verified
  • wip
  • lgtm
  • approve
  • automerge

💡 Tips

  • WIP Status: Use /wip when your PR is not ready for review
  • Verification: The verified label is automatically removed on each new commit
  • Cherry-picking: Cherry-pick labels are processed when the PR is merged
  • Container Builds: Container images are automatically tagged with the PR number
  • Permission Levels: Some commands require approver permissions
  • Auto-verified Users: Certain users have automatic verification and merge privileges

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%
@myakove myakove merged commit 524ee6e into main Nov 17, 2025
6 of 9 checks passed
@myakove myakove deleted the fix/skip-deletion-events branch November 17, 2025 20:30
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_prop parameter 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_prop parameter 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9d5f0bf and 6415043.

📒 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.py
  • webhook_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.

@myakove-bot
Copy link
Collaborator

New container for ghcr.io/myk-org/github-webhook-server:latest published

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants