Skip to content

fix(code_review): event_type does not define the webhook type#105548

Merged
armenzg merged 8 commits intomasterfrom
12_30/fix_bug/check_run/armenzg
Dec 31, 2025
Merged

fix(code_review): event_type does not define the webhook type#105548
armenzg merged 8 commits intomasterfrom
12_30/fix_bug/check_run/armenzg

Conversation

@armenzg
Copy link
Copy Markdown
Member

@armenzg armenzg commented Dec 30, 2025

This fixes the check_run re-run case since I regressed it in #105393 when we switched the event_type to ci_check.

Standardizes webhook event type handling by replacing the custom EventType enum with the existing GithubWebhookType from the GitHub integration package.

Changes:

  • Pass github_event from X-GitHub-Event header through webhook chain
  • Remove custom EventType enum and use GithubWebhookType throughout
  • Update webhook processor signatures to accept github_event parameter
  • Simplify event routing logic in process_github_webhook_event task
  • Update all webhook processors and tests to use new signature

This makes the code more consistent with the GitHub integration package and removes duplicate event type definitions.

This fixes the `check_run` re-run case since we were incorrectly checking `ci_check`.

Standardizes webhook event type handling by replacing the custom `EventType`
enum with the existing `GithubWebhookType` from the GitHub integration package.

Changes:
- Pass `github_event` from `X-GitHub-Event` header through webhook chain
- Remove custom `EventType` enum and use `GithubWebhookType` throughout
- Update webhook processor signatures to accept `github_event` parameter
- Simplify event routing logic in `process_github_webhook_event` task
- Update all webhook processors and tests to use new signature

This makes the code more consistent with the GitHub integration package
and removes duplicate event type definitions.
@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
def __call__(
self,
*,
event_type: str,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

All the functions implementing this protocol will be updated to this new signature.

*,
event_type: str,
# This comes from the X-GitHub-Event header
github_event: GithubWebhookType,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Renaming the variable to make it dead obvious. event_type refers to an internal integrations metric.

*,
github_event: GithubWebhookType,
event: Mapping[str, Any],
organization: Organization,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

TODO: The signature here should have always had organization and repo. This is likely because we need a mechanism to enforce the typing. I will follow-up.

# without needing to implement _handle()
def _handle(
self,
github_event: GithubWebhookType,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is now passed here:

Image

continue

def __call__(self, event: Mapping[str, Any], **kwargs: Any) -> None:
github_event = kwargs["github_event"]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We pass this as a kwargs since we don't want to touch the signature of the base class.

@@ -154,6 +162,7 @@
# without needing to implement _handle()
def _handle(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For extra visibility, this belongs to GitHubWebhook:


def _handle(
self,
github_event: GithubWebhookType,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

All children classes will have this value but only the ones for the code_review code will take advantage of it.


try:
handler = self.get_handler(request.META["HTTP_X_GITHUB_EVENT"])
github_event = request.META["HTTP_X_GITHUB_EVENT"]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the real way we can distinguish events.

Yesterday I regressed check_run when I started looking at an event_type of ci_run.

Copy link
Copy Markdown
Contributor

@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.

nice improvement 🚀

assert isinstance(call_kwargs["enqueued_at_str"], str)

@patch("sentry.seer.code_review.webhooks.task.process_github_webhook_event")
@with_feature(CODE_REVIEW_FEATURES)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

technically this test probably wants this decorator omitted (i.e., all features disabled)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will have to fix this test as it should have failed.

TODO: follow-up.

event=event,
organization=organization,
repo=repo,
**kwargs,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Matches the new signature:

Image

"""

CI_CHECK = "ci_check"
CI_CHECK = "ci_check" # e.g. GitHub Check Runs
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Renaming this from check_run to ci_check became the source of the bug.


from ..permissions import has_code_review_enabled
from ..utils import SeerEndpoint, make_seer_request
from .types import EventType
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We're consolidating and using GithubWebhookType instead of this.

def process_check_run_task_event(
*, event_type: str, event_payload: Mapping[str, Any], **kwargs: Any
) -> None:
def process_check_run_task_event(*, event_payload: Mapping[str, Any], **kwargs: Any) -> None:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The event_type or github_event is not passed since the task is already calling the function which handles this event.

Only processes events with event_type='check_run'.
This allows the task to be shared by multiple webhook types without conflicts.
"""
if event_type != EventType.CHECK_RUN:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No need to check anymore.

assert event_type != EventType.CHECK_RUN
assert event_payload is not None
assert github_event != GithubWebhookType.CHECK_RUN
# XXX: Add checking options to prevent sending events to Seer by mistake.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will follow-up in a different PR. We should not call Seer by mistake. We need to map the GitHub events and the options correctly.


EVENT_TYPE_TO_PROCESSOR = {
EventType.CHECK_RUN: process_check_run_task_event,
EventType.ISSUE_COMMENT: _call_seer_request,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The fallback function call is now handled directly in the task:

Image

@armenzg armenzg marked this pull request as ready for review December 31, 2025 14:28
@armenzg armenzg requested a review from a team as a code owner December 31, 2025 14:28
@armenzg armenzg requested a review from a team December 31, 2025 14:28
@armenzg armenzg requested review from a team as code owners December 31, 2025 14:28
@armenzg armenzg merged commit daf853d into master Dec 31, 2025
65 checks passed
@armenzg armenzg deleted the 12_30/fix_bug/check_run/armenzg branch December 31, 2025 14:34
@github-actions github-actions bot locked and limited conversation to collaborators Jan 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants