Skip to content

Conversation

@armenzg
Copy link
Member

@armenzg armenzg commented Dec 30, 2025

Refactor webhook event handling for Seer code review

Summary:
Consolidates webhook event type handling by replacing the custom EventType enum with the existing GithubWebhookType enum and centralizing configuration.

Changes:

  • Replaced custom EventType enum with GithubWebhookType throughout codebase for consistency with GitHub integration types
  • Created webhooks/config.py to centralize:
    • Event type to option key mappings (EVENT_TYPE_TO_OPTION)
    • Custom webhook handlers (EVENT_TYPE_TO_CUSTOM_HANDLER)
    • Task event processors (EVENT_TYPE_TO_PROCESSOR)
  • Simplified webhook routing logic:
    • Extracted schedule_task() function for default webhook scheduling
    • Added call_seer_if_allowed() to check options before forwarding to Seer
    • Removed duplicate handler functions and mappings
  • Reorganized options in defaults.py (moved webhook options near coding workflows section)
  • Shared configuration between webhook_forwarder.py and webhook handlers via EVENT_TYPE_TO_OPTION

Benefits:

  • Single source of truth for event type definitions
  • Cleaner separation between validation (handlers) and processing (processors)
  • Reduced code duplication
  • Easier to add new webhook types

@armenzg armenzg self-assigned this Dec 30, 2025
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 30, 2025
assert event_payload is not None
option_key = EVENT_TYPE_TO_OPTION.get(event_type)
if option_key and not options.get(option_key):
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Inverted option check blocks Seer calls incorrectly

The condition in call_seer_if_allowed is inverted. According to the comment in defaults.py ("Control forwarding of specific GitHub webhook types to overwatch (True) or seer (False)"), when the option is True the event should go to Overwatch (not Seer), and when False it should go to Seer. However, the current logic if option_key and not options.get(option_key): return returns early when the option is False, which is the opposite of the intended behavior. With default values set to True, all events will incorrectly be forwarded to Seer when they should be blocked.

Fix in Cursor Fix in Web

# Type checks to ensure the functions match WebhookProcessor protocol
_type_checked_handle_other_webhook_event: WebhookProcessor = handle_other_webhook_event
_type_checked_handle_check_run_event: WebhookProcessor = handle_check_run_event
schedule_task(event_type=event_type, event_payload=event)
Copy link
Contributor

Choose a reason for hiding this comment

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

Webhook payload transformation removed, raw events sent to Seer

The old handle_other_webhook_event function called _transform_webhook_to_codegen_request to convert raw GitHub webhook payloads into the CodecovTaskRequest format expected by Seer (with data, external_owner_id, request_type, organization_id fields). The new handle_webhook_event function passes the raw event payload directly to schedule_task without any transformation. For ISSUE_COMMENT, PULL_REQUEST, PULL_REQUEST_REVIEW, and PULL_REQUEST_REVIEW_COMMENT events, Seer will now receive raw GitHub webhook payloads in the wrong format. The transformation function also filtered non-PR-related events (returning None), which is also lost.

Fix in Cursor Fix in Web

@armenzg armenzg changed the title ref(code_review): Block calls to Seer without option set to False ref(code_review): Centralized config, prevent Seer calls and better types Dec 30, 2025
Copy link
Member

@suejung-sentry suejung-sentry left a comment

Choose a reason for hiding this comment

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

these changes make sense to me. guessing this one will get merged first

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

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants