diff --git a/packit_service/models.py b/packit_service/models.py index 9cdfcc223..d881ad000 100644 --- a/packit_service/models.py +++ b/packit_service/models.py @@ -1538,6 +1538,9 @@ def __query_merged_runs(cls): func.array_agg(psql_array([PipelineModel.bodhi_update_group_id])).label( "bodhi_update_group_id", ), + func.array_agg(psql_array([PipelineModel.vm_image_build_id])).label( + "vm_image_build_id", + ), ) @classmethod diff --git a/packit_service/service/api/runs.py b/packit_service/service/api/runs.py index 3f44142a7..df5cf5dad 100644 --- a/packit_service/service/api/runs.py +++ b/packit_service/service/api/runs.py @@ -19,6 +19,7 @@ TFTTestRunGroupModel, BodhiUpdateGroupModel, BodhiUpdateTargetModel, + VMImageBuildTargetModel, ) from packit_service.service.api.parsers import indices, pagination_arguments from packit_service.service.api.utils import ( @@ -48,6 +49,19 @@ def _add_sync_release(run: SyncReleaseModel, response_dict: Dict): response_dict["trigger"] = get_project_info_from_build(run) +def _add_vm_image_build(run: VMImageBuildTargetModel, response_dict: Dict): + response_dict["vm_image_build"].append( + { + "packit_id": run.id, + "target": run.target, + "status": run.status, + } + ) + if "trigger" not in response_dict: + response_dict["time_submitted"] = optional_timestamp(run.build_submitted_time) + response_dict["trigger"] = get_project_info_from_build(run) + + def flatten_and_remove_none(ids): return filter(None, map(lambda arr: arr[0], ids)) @@ -75,6 +89,7 @@ def process_runs(runs): "propose_downstream": [], "pull_from_upstream": [], "bodhi_update": [], + "vm_image_build": [], } if srpm_build := SRPMBuildModel.get_by_id(pipeline.srpm_build_id): @@ -126,6 +141,15 @@ def process_runs(runs): response_dict, ) + # handle VM image builds + for vm_image_build_id in set( + flatten_and_remove_none(pipeline.vm_image_build_id) + ): + _add_vm_image_build( + VMImageBuildTargetModel.get_by_id(vm_image_build_id), + response_dict, + ) + result.append(response_dict) return result diff --git a/packit_service/service/api/utils.py b/packit_service/service/api/utils.py index 9f46279bb..8c99b48b3 100644 --- a/packit_service/service/api/utils.py +++ b/packit_service/service/api/utils.py @@ -18,6 +18,7 @@ SyncReleaseTargetModel, optional_timestamp, BodhiUpdateTargetModel, + VMImageBuildTargetModel, ) @@ -39,6 +40,7 @@ def get_project_info_from_build( TFTTestRunGroupModel, SyncReleaseModel, BodhiUpdateTargetModel, + VMImageBuildTargetModel, ] ) -> Dict[str, Any]: if not (project := build.get_project()):