Skip to content

Commit 4932371

Browse files
fix(codecov): Add back needed code
1 parent e52c21c commit 4932371

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

  • src/sentry/middleware/integrations/parsers

src/sentry/middleware/integrations/parsers/github.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@
88
from django.http import HttpRequest, HttpResponse
99
from django.http.response import HttpResponseBase
1010

11+
import sentry.options as options
1112
from sentry.hybridcloud.outbox.category import WebhookProviderIdentifier
1213
from sentry.integrations.github.webhook import (
1314
GitHubIntegrationsWebhookEndpoint,
1415
get_github_external_id,
1516
)
1617
from sentry.integrations.github.webhook_types import (
1718
GITHUB_WEBHOOK_TYPE_HEADER,
19+
REGION_PROCESSED_GITHUB_EVENTS,
1820
GithubWebhookType,
1921
)
2022
from sentry.integrations.middleware.hybrid_cloud.parser import BaseRequestParser
2123
from sentry.integrations.models.integration import Integration
2224
from sentry.integrations.services.integration.model import RpcIntegration
2325
from sentry.integrations.types import IntegrationProviderSlug
2426
from sentry.silo.base import control_silo_function
27+
from sentry.utils import metrics
2528

2629
logger = logging.getLogger(__name__)
2730

@@ -115,6 +118,22 @@ def get_response(self) -> HttpResponseBase:
115118
if len(regions) == 0:
116119
return self.get_default_missing_integration_response()
117120

121+
github_event = self.request.META.get(GITHUB_WEBHOOK_TYPE_HEADER)
122+
123+
# Only drop when we have a known unprocessed event type. Missing or empty
124+
# X-GitHub-Event is malformed; let the request be forwarded so the region
125+
# returns 400 and GitHub is notified of the delivery failure.
126+
if (
127+
github_event
128+
and github_event not in REGION_PROCESSED_GITHUB_EVENTS
129+
and options.get("github.webhook.drop-unprocessed-events.enabled")
130+
):
131+
metrics.incr(
132+
"github.webhook.drop_unprocessed_event",
133+
tags={"event_type": github_event or "unknown"},
134+
)
135+
return HttpResponse(status=202)
136+
118137
response = self.get_response_from_webhookpayload(
119138
regions=regions,
120139
identifier=self.get_mailbox_identifier(integration, event),

0 commit comments

Comments
 (0)