fix(code_review): event_type does not define the webhook type#105548
fix(code_review): event_type does not define the webhook type#105548
Conversation
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.
| def __call__( | ||
| self, | ||
| *, | ||
| event_type: str, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
| continue | ||
|
|
||
| def __call__(self, event: Mapping[str, Any], **kwargs: Any) -> None: | ||
| github_event = kwargs["github_event"] |
There was a problem hiding this comment.
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( | |||
There was a problem hiding this comment.
For extra visibility, this belongs to GitHubWebhook:
|
|
||
| def _handle( | ||
| self, | ||
| github_event: GithubWebhookType, |
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
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.
suejung-sentry
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
technically this test probably wants this decorator omitted (i.e., all features disabled)
There was a problem hiding this comment.
I will have to fix this test as it should have failed.
TODO: follow-up.
| event=event, | ||
| organization=organization, | ||
| repo=repo, | ||
| **kwargs, |
| """ | ||
|
|
||
| CI_CHECK = "ci_check" | ||
| CI_CHECK = "ci_check" # e.g. GitHub Check Runs |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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, |



This fixes the
check_runre-run case since I regressed it in #105393 when we switched theevent_typetoci_check.Standardizes webhook event type handling by replacing the custom
EventTypeenum with the existingGithubWebhookTypefrom the GitHub integration package.Changes:
github_eventfromX-GitHub-Eventheader through webhook chainEventTypeenum and useGithubWebhookTypethroughoutgithub_eventparameterprocess_github_webhook_eventtaskThis makes the code more consistent with the GitHub integration package and removes duplicate event type definitions.