def process_runs(runs): """ Process `RunModel`s and construct a JSON that is returned from the endpoints that return merged chroots. Args: runs: Iterator over merged `RunModel`s. Returns: List of JSON objects where each represents pipelines run on single SRPM. """ result = [] for pipeline in runs: response_dict = { "merged_run_id": pipeline.merged_id, "srpm": None, "copr": [], "koji": [], "test_run": [], } srpm_build = SRPMBuildModel.get_by_id(pipeline.srpm_build_id) if srpm_build: response_dict["srpm"] = { "packit_id": srpm_build.id, "status": srpm_build.status, } response_dict["time_submitted"] = optional_timestamp( srpm_build.build_submitted_time) response_dict["trigger"] = get_project_info_from_build(srpm_build) for model_type, Model, packit_ids in ( ("copr", CoprBuildModel, pipeline.copr_build_id), ("koji", KojiBuildModel, pipeline.koji_build_id), ("test_run", TFTTestRunModel, pipeline.test_run_id), ): for packit_id in set( filter(None, map(lambda ids: ids[0], packit_ids))): row = Model.get_by_id(packit_id) if row.status == "waiting_for_srpm": continue response_dict[model_type].append({ "packit_id": packit_id, "target": row.target, "status": row.status, }) if "trigger" not in response_dict: submitted_time = (row.submitted_time if isinstance( row, TFTTestRunModel) else row.build_submitted_time) response_dict["time_submitted"] = optional_timestamp( submitted_time) response_dict["trigger"] = get_project_info_from_build(row) result.append(response_dict) return result
def get(self, id): """A specific copr build details for one chroot.""" build = CoprBuildModel.get_by_id(int(id)) if not build: return response_maker( {"error": "No info about build stored in DB"}, status=HTTPStatus.NOT_FOUND.value, ) build_dict = { "build_id": build.build_id, "status": build.status, "chroot": build.target, "build_submitted_time": optional_timestamp(build.build_submitted_time), "build_start_time": optional_timestamp(build.build_start_time), "build_finished_time": optional_timestamp(build.build_finished_time), "commit_sha": build.commit_sha, "web_url": build.web_url, "build_logs_url": build.build_logs_url, "copr_project": build.project_name, "copr_owner": build.owner, "srpm_build_id": build.get_srpm_build().id, "run_ids": sorted(run.id for run in build.runs), "built_packages": build.built_packages, } build_dict.update(get_project_info_from_build(build)) return response_maker(build_dict)
def get(self, id): """A specific SRPM build details.""" build = SRPMBuildModel.get_by_id(int(id)) if not build: return response_maker( {"error": "No info about build stored in DB"}, status=HTTPStatus.NOT_FOUND.value, ) build_dict = { "status": build.status, "build_submitted_time": optional_timestamp(build.build_submitted_time), "build_start_time": optional_timestamp(build.build_start_time), "build_finished_time": optional_timestamp(build.build_finished_time), "url": build.url, "logs": build.logs, "logs_url": build.logs_url, "copr_build_id": build.copr_build_id, "copr_web_url": build.copr_web_url, "run_ids": sorted(run.id for run in build.runs), } build_dict.update(get_project_info_from_build(build)) return response_maker(build_dict)
def get(self, id): """A specific koji build details.""" build = KojiBuildModel.get_by_id(int(id)) if not build: return response_maker( {"error": "No info about build stored in DB"}, status=HTTPStatus.NOT_FOUND.value, ) build_dict = { "build_id": build.build_id, "status": build.status, "chroot": build.target, "build_start_time": optional_timestamp(build.build_start_time), "build_finished_time": optional_timestamp(build.build_finished_time), "build_submitted_time": optional_timestamp(build.build_submitted_time), "commit_sha": build.commit_sha, "web_url": build.web_url, # from old data, sometimes build_logs_url is same and sometimes different to web_url "build_logs_url": build.build_logs_url, "srpm_build_id": build.get_srpm_build().id, "run_ids": sorted(run.id for run in build.runs), } build_dict.update(get_project_info_from_build(build)) return response_maker(build_dict)
def get(self, id): """Return details for given run.""" run = RunModel.get_run(id_=id) if not run: return response_maker( {"error": "No run has been found in DB"}, status=HTTPStatus.NOT_FOUND.value, ) result = { "run_id": run.id, "trigger": get_project_info_from_build(run.srpm_build), "srpm_build_id": run.srpm_build_id, "copr_build_id": run.copr_build_id, "koji_build_id": run.koji_build_id, "test_run_id": run.test_run_id, } return response_maker(result)
def get(self, id): """A specific test run details.""" test_run_model = TFTTestRunModel.get_by_id(int(id)) if not test_run_model: return response_maker( {"error": "No info about build stored in DB"}, status=HTTPStatus.NOT_FOUND.value, ) test_result_dict = { "pipeline_id": test_run_model.pipeline_id, "status": test_run_model.status, "chroot": test_run_model.target, "commit_sha": test_run_model.commit_sha, "web_url": test_run_model.web_url, "copr_build_id": test_run_model.runs[0].copr_build_id, "run_ids": sorted(run.id for run in test_run_model.runs), "submitted_time": optional_timestamp(test_run_model.submitted_time), } test_result_dict.update(get_project_info_from_build(test_run_model)) return response_maker(test_result_dict)