Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks: Migrate travis to use @typed_endpoint.
Zixuan James Li7d683018bdef
diff --git a/zerver/webhooks/travis/view.py b/zerver/webhooks/travis/view.pyindex 17cc4b073fd..75ba7c5a85d 100644--- a/zerver/webhooks/travis/view.py+++ b/zerver/webhooks/travis/view.py@@ -1,12 +1,12 @@# Webhooks for external integrations.-from typing import Dictfrom django.http import HttpRequest, HttpResponse+from pydantic import BaseModel, Json+from typing_extensions import Annotatedfrom zerver.decorator import webhook_view-from zerver.lib.request import REQ, has_request_variablesfrom zerver.lib.response import json_success-from zerver.lib.validator import check_bool, check_dict, check_string+from zerver.lib.typed_endpoint import ApiParamConfig, typed_endpointfrom zerver.lib.webhooks.common import check_send_webhook_messagefrom zerver.models import UserProfile@@ -24,26 +24,26 @@ Build status: {} {}Details: [changes]({}), [build log]({})"""+class TravisPayload(BaseModel):+ author_name: str+ status_message: str+ compare_url: str+ build_url: str+ type: str++@webhook_view("Travis", all_event_types=ALL_EVENT_TYPES)-@has_request_variables+@typed_endpointdef api_travis_webhook(request: HttpRequest,user_profile: UserProfile,- ignore_pull_requests: bool = REQ(json_validator=check_bool, default=True),- message: Dict[str, object] = REQ(- "payload",- json_validator=check_dict(- [- ("author_name", check_string),- ("status_message", check_string),- ("compare_url", check_string),- ]- ),- ),+ *,+ message: Annotated[Json[TravisPayload], ApiParamConfig("payload")],+ ignore_pull_requests: Json[bool] = True,) -> HttpResponse:- event = str(message["type"])- message_status = message["status_message"]- if ignore_pull_requests and message["type"] == "pull_request":+ event = message.type+ message_status = message.status_message+ if ignore_pull_requests and message.type == "pull_request":return json_success(request)if message_status in GOOD_STATUSES:@@ -56,11 +56,11 @@ def api_travis_webhook(emoji = f"(No emoji specified for status '{message_status}'.)"body = MESSAGE_TEMPLATE.format(- message["author_name"],+ message.author_name,message_status,emoji,- message["compare_url"],- message["build_url"],+ message.compare_url,+ message.build_url,)topic = "builds"