From a33607d8ad860afa5517cdde56b8edd0b2367358 Mon Sep 17 00:00:00 2001 From: Zixuan James Li Date: Mon, 14 Aug 2023 17:50:15 -0400 Subject: [PATCH] webhooks: Convert gitlab to use @typed_endpoint. The GitLab webhook has a mix of different types of parameters each requring a unique set of configurations. --- zerver/webhooks/gitlab/view.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.py index 2c867c641d..cde6ac75a0 100644 --- a/zerver/webhooks/gitlab/view.py +++ b/zerver/webhooks/gitlab/view.py @@ -3,13 +3,15 @@ from functools import partial from typing import Dict, List, Optional, Protocol, Union from django.http import HttpRequest, HttpResponse +from pydantic import Json from zerver.decorator import webhook_view from zerver.lib.exceptions import UnsupportedWebhookEventTypeError -from zerver.lib.request import REQ, has_request_variables from zerver.lib.response import json_success -from zerver.lib.validator import WildValue, check_bool, check_int, check_string, to_wild_value +from zerver.lib.typed_endpoint import WebhookPayload, typed_endpoint +from zerver.lib.validator import WildValue, check_int, check_string from zerver.lib.webhooks.common import ( + OptionalUserSpecifiedTopicStr, check_send_webhook_message, validate_extract_webhook_http_header, ) @@ -416,14 +418,15 @@ ALL_EVENT_TYPES = list(EVENT_FUNCTION_MAPPER.keys()) @webhook_view("GitLab", all_event_types=ALL_EVENT_TYPES) -@has_request_variables +@typed_endpoint def api_gitlab_webhook( request: HttpRequest, user_profile: UserProfile, - payload: WildValue = REQ(argument_type="body", converter=to_wild_value), - branches: Optional[str] = REQ(default=None), - use_merge_request_title: bool = REQ(default=True, json_validator=check_bool), - user_specified_topic: Optional[str] = REQ("topic", default=None), + *, + payload: WebhookPayload[WildValue], + branches: Optional[str] = None, + use_merge_request_title: Json[bool] = True, + user_specified_topic: OptionalUserSpecifiedTopicStr = None, ) -> HttpResponse: event = get_event(request, payload, branches) if event is not None: