From 5cc70675c69b3c47a488dff575935c7ac0e09d4f Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 13 Apr 2018 09:09:24 -0700 Subject: [PATCH] webhooks: Suppress errors from very old GitLab versions. Ancient GitLab from several years ago doesn't include the HTTP_X_GITLAB_EVENT header (and seems to have a different format), so we should ignore its requests. Might be good to document the version threshhold, but it's very hard to tell from Googling what it is. --- zerver/webhooks/gitlab/view.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.py index a56a966d06..0cf5c6391b 100644 --- a/zerver/webhooks/gitlab/view.py +++ b/zerver/webhooks/gitlab/view.py @@ -332,7 +332,13 @@ def get_subject_based_on_event(event: str, payload: Dict[str, Any]) -> Text: def get_event(request: HttpRequest, payload: Dict[str, Any], branches: Optional[Text]) -> Optional[str]: # if there is no 'action' attribute, then this is a test payload # and we should ignore it - event = request.META['HTTP_X_GITLAB_EVENT'] + event = request.META.get('HTTP_X_GITLAB_EVENT') + if event is None: + # Suppress events from old versions of GitLab that don't set + # this header. TODO: We probably want a more generic solution + # to this category of issue that throws a 40x error to the + # user, e.g. some sort of InvalidWebhookRequest exception. + return None if event in ['Issue Hook', 'Merge Request Hook', 'Wiki Page Hook']: action = payload['object_attributes'].get('action') if action is None: