Skip to content

Commit

Permalink
Handle VM image builds in /api/runs (#2414)
Browse files Browse the repository at this point in the history
Handle VM image builds in /api/runs

Reviewed-by: Laura Barcziová
Reviewed-by: Nikola Forró
  • Loading branch information
softwarefactory-project-zuul[bot] authored Apr 30, 2024
2 parents e988390 + 91544b6 commit 4ca4f69
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packit_service/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions packit_service/service/api/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions packit_service/service/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
SyncReleaseTargetModel,
optional_timestamp,
BodhiUpdateTargetModel,
VMImageBuildTargetModel,
)


Expand All @@ -39,6 +40,7 @@ def get_project_info_from_build(
TFTTestRunGroupModel,
SyncReleaseModel,
BodhiUpdateTargetModel,
VMImageBuildTargetModel,
]
) -> Dict[str, Any]:
if not (project := build.get_project()):
Expand Down

0 comments on commit 4ca4f69

Please sign in to comment.