From 9c631f2259d29aec3a80933ae302c46f53752dca Mon Sep 17 00:00:00 2001 From: Joshua Ferge Date: Fri, 24 Jan 2025 11:58:20 -0500 Subject: [PATCH] use TypedDict --- src/sentry/integrations/vercel/webhook.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/sentry/integrations/vercel/webhook.py b/src/sentry/integrations/vercel/webhook.py index bd8136cd16eb39..f2ff40ce465499 100644 --- a/src/sentry/integrations/vercel/webhook.py +++ b/src/sentry/integrations/vercel/webhook.py @@ -4,7 +4,7 @@ import hmac import logging from collections.abc import Mapping -from typing import Any +from typing import Any, TypedDict from django.http.request import HttpRequest from django.http.response import HttpResponseBase @@ -42,6 +42,12 @@ class MissingRepositoryError(IntegrationError): pass +class _ReleasePayload(TypedDict): + version: str + projects: list[str] + refs: list[dict[str, str]] + + def verify_signature(request): signature = request.META.get("HTTP_X_VERCEL_SIGNATURE") secret = options.get("vercel.client-secret") @@ -95,7 +101,7 @@ def get_repository(meta: Mapping[str, str]) -> str: def get_payload_and_token( payload: Mapping[str, Any], organization_id: int, sentry_project_id: int -) -> tuple[dict[str, Any], str]: +) -> tuple[_ReleasePayload, str]: meta = payload["deployment"]["meta"] # look up the project so we can get the slug @@ -121,7 +127,7 @@ def get_payload_and_token( commit_sha = get_commit_sha(meta) repository = get_repository(meta) - release_payload = { + release_payload: _ReleasePayload = { "version": commit_sha, "projects": [project.slug], "refs": [{"repository": repository, "commit": commit_sha}], @@ -371,9 +377,10 @@ def _deployment_created(self, external_id, request): } json_error = None - # create the basic release payload without refs - no_ref_payload = release_payload.copy() - del no_ref_payload["refs"] + no_ref_payload = { + "version": release_payload["version"], + "projects": release_payload["projects"], + } with http.build_session() as session: try: