22
33import logging
44from abc import ABC , abstractmethod
5+ from datetime import datetime
56from typing import Any
67
78from sentry .constants import ObjectStatus
4243)
4344def create_preprod_status_check_task (preprod_artifact_id : int ) -> None :
4445 try :
45- preprod_artifact = PreprodArtifact .objects .get (id = preprod_artifact_id )
46+ preprod_artifact : PreprodArtifact | None = PreprodArtifact .objects .get (
47+ id = preprod_artifact_id
48+ )
4649 except PreprodArtifact .DoesNotExist :
4750 logger .exception (
4851 "preprod.status_checks.create.artifact_not_found" ,
4952 extra = {"artifact_id" : preprod_artifact_id },
5053 )
5154 return
5255
56+ if not preprod_artifact or not isinstance (preprod_artifact , PreprodArtifact ):
57+ logger .error (
58+ "preprod.status_checks.create.artifact_not_found" ,
59+ extra = {"artifact_id" : preprod_artifact_id },
60+ )
61+ return
62+
5363 logger .info (
5464 "preprod.status_checks.create.start" ,
5565 extra = {"artifact_id" : preprod_artifact .id },
@@ -115,6 +125,10 @@ def create_preprod_status_check_task(preprod_artifact_id: int) -> None:
115125
116126 target_url = get_preprod_artifact_url (preprod_artifact )
117127
128+ completed_at : datetime | None = None
129+ if GITHUB_STATUS_CHECK_STATUS_MAPPING [status ] == GitHubCheckStatus .COMPLETED :
130+ completed_at = preprod_artifact .date_updated
131+
118132 check_id = provider .create_status_check (
119133 repo = commit_comparison .head_repo_name ,
120134 sha = commit_comparison .head_sha ,
@@ -125,6 +139,8 @@ def create_preprod_status_check_task(preprod_artifact_id: int) -> None:
125139 summary = summary ,
126140 external_id = str (preprod_artifact .id ),
127141 target_url = target_url ,
142+ started_at = preprod_artifact .date_added ,
143+ completed_at = completed_at ,
128144 )
129145 if check_id is None :
130146 logger .error (
@@ -301,6 +317,8 @@ def create_status_check(
301317 text : str | None ,
302318 summary : str ,
303319 external_id : str ,
320+ started_at : datetime ,
321+ completed_at : datetime | None = None ,
304322 target_url : str | None = None ,
305323 ) -> str | None :
306324 """Create a status check using provider-specific format."""
@@ -318,6 +336,8 @@ def create_status_check(
318336 text : str | None ,
319337 summary : str ,
320338 external_id : str ,
339+ started_at : datetime ,
340+ completed_at : datetime | None = None ,
321341 target_url : str | None = None ,
322342 ) -> str | None :
323343 with self ._create_scm_interaction_event ().capture () as lifecycle :
@@ -373,6 +393,12 @@ def create_status_check(
373393 if mapped_conclusion :
374394 check_data ["conclusion" ] = mapped_conclusion .value
375395
396+ if started_at :
397+ check_data ["started_at" ] = started_at .isoformat ()
398+
399+ if completed_at :
400+ check_data ["completed_at" ] = completed_at .isoformat ()
401+
376402 if target_url :
377403 if target_url .startswith ("http" ):
378404 check_data ["details_url" ] = target_url
0 commit comments