def get(self, forge): """List of projects of given forge (e.g. github.com, gitlab.com)""" result = [] first, last = indices() for project in GitProjectModel.get_forge(first, last, forge): project_info = { "namespace": project.namespace, "repo_name": project.repo_name, "project_url": project.project_url, "prs_handled": len(project.pull_requests), "branches_handled": len(project.branches), "releases_handled": len(project.releases), "issues_handled": len(project.issues), } result.append(project_info) if not result: return response_maker([]) resp = response_maker( result, status=HTTPStatus.PARTIAL_CONTENT.value, ) resp.headers["Content-Range"] = f"git-projects {first + 1}-{last}/*" return resp
def get(self): """List all GitProjects""" result = [] first, last = indices() projects_list = GitProjectModel.get_projects(first, last) if not projects_list: return response_maker([]) for project in projects_list: project_info = { "namespace": project.namespace, "repo_name": project.repo_name, "project_url": project.project_url, "prs_handled": len(project.pull_requests), "branches_handled": len(project.branches), "releases_handled": len(project.releases), "issues_handled": len(project.issues), } result.append(project_info) resp = response_maker( result, status=HTTPStatus.PARTIAL_CONTENT.value, ) resp.headers["Content-Range"] = f"git-projects {first + 1}-{last}/*" return resp
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, forge, namespace, repo_name): """Project branches""" branches = GitProjectModel.get_project_branches( forge, namespace, repo_name) if not branches: return response_maker([]) result = [] for branch in branches: branch_info = { "branch": branch.name, "builds": [], "tests": [], } for build in branch.get_copr_builds(): build_info = { "build_id": build.build_id, "chroot": build.target, "status": build.status, "web_url": build.web_url, } branch_info["builds"].append(build_info) result.append(branch_info) for test_run in branch.get_test_runs(): test_info = { "pipeline_id": test_run.pipeline_id, "chroot": test_run.target, "status": test_run.status, "web_url": test_run.web_url, } branch_info["tests"].append(test_info) return response_maker(result)
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, forge, namespace, repo_name): """Project branches""" branches = GitProjectModel.get_project_branches( forge, namespace, repo_name) if not branches: return response_maker([]) result = [] for branch in branches: branch_info = { "branch": branch.name, "builds": [], "koji_builds": [], "srpm_builds": [], "tests": [], } for build in branch.get_copr_builds(): build_info = { "build_id": build.build_id, "chroot": build.target, "status": build.status, "web_url": build.web_url, } branch_info["builds"].append(build_info) for build in branch.get_koji_builds(): build_info = { "build_id": build.build_id, "chroot": build.target, "status": build.status, "web_url": build.web_url, } branch_info["koji_builds"].append(build_info) for build in branch.get_srpm_builds(): build_info = { "srpm_build_id": build.id, "success": build.success, "log_url": url_for("builds.get_srpm_build_logs_by_id", id_=build.id, _external=True), } branch_info["srpm_builds"].append(build_info) for test_run in branch.get_test_runs(): test_info = { "pipeline_id": test_run.pipeline_id, "chroot": test_run.target, "status": test_run.status, "web_url": test_run.web_url, } branch_info["tests"].append(test_info) result.append(branch_info) return response_maker(result)
def get(self, forge, namespace, repo_name): """Project issues""" issues_list = GitProjectModel.get_project_issues(forge, namespace, repo_name) if not issues_list: return response_maker([]) result = [] for issue in issues_list: result.append(issue.issue_id) return response_maker(result)
def get(self, forge, namespace, repo_name): """Project releases""" releases_list = GitProjectModel.get_project_releases( forge, namespace, repo_name) if not releases_list: return response_maker([]) result = [] for release in releases_list: release_info = { "tag_name": release.tag_name, "commit_hash": release.commit_hash, } result.append(release_info) return response_maker(result)
def get(self): """List all SRPM builds.""" result = [] first, last = indices() for build in SRPMBuildModel.get(first, last): build_dict = { "srpm_build_id": build.id, "success": build.success, "log_url": get_srpm_build_info_url(build.id), "build_submitted_time": optional_timestamp(build.build_submitted_time), } project = build.get_project() # Its possible that jobtrigger isnt stored in db if project: build_dict["repo_namespace"] = project.namespace build_dict["repo_name"] = project.repo_name build_dict["project_url"] = project.project_url build_dict["pr_id"] = build.get_pr_id() build_dict["branch_name"] = build.get_branch_name() result.append(build_dict) resp = response_maker( result, status=HTTPStatus.PARTIAL_CONTENT.value, ) resp.headers["Content-Range"] = f"srpm-builds {first + 1}-{last}/*" return resp
def get(self): """ List all Koji builds. """ first, last = indices() result = [] for build in KojiBuildModel.get_range(first, last): build_dict = { "build_id": build.build_id, "status": build.status, "build_submitted_time": optional_time(build.build_submitted_time), "chroot": build.target, "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, "pr_id": build.get_pr_id(), "branch_name": build.get_branch_name(), "release": build.get_release_tag(), } project = build.get_project() if project: build_dict["project_url"] = project.project_url build_dict["repo_namespace"] = project.namespace build_dict["repo_name"] = project.repo_name result.append(build_dict) resp = response_maker( result, status=HTTPStatus.PARTIAL_CONTENT.value, ) resp.headers["Content-Range"] = f"koji-builds {first + 1}-{last}/*" return resp
def get(self): """ List all Copr builds. """ # Return relevant info thats concise # Usecases like the packit-dashboard copr-builds table result = [] first, last = indices() for build in CoprBuildModel.get_merged_chroots(first, last): build_info = CoprBuildModel.get_by_build_id(build.build_id, None) project_info = build_info.get_project() build_dict = { "project": build_info.project_name, "build_id": build.build_id, "status_per_chroot": {}, "build_submitted_time": optional_time(build_info.build_submitted_time), "web_url": build_info.web_url, "ref": build_info.commit_sha, "pr_id": build_info.get_pr_id(), "branch_name": build_info.get_branch_name(), "repo_namespace": project_info.namespace, "repo_name": project_info.repo_name, } for count, chroot in enumerate(build.target): # [0] because sqlalchemy returns a single element sub-list build_dict["status_per_chroot"][chroot[0]] = build.status[count][0] result.append(build_dict) resp = response_maker(result, status=HTTPStatus.PARTIAL_CONTENT,) resp.headers["Content-Range"] = f"copr-builds {first + 1}-{last}/*" return resp
def get(self): """ List all Testing Farm results. """ result = [] first, last = indices() # results have nothing other than ref in common, so it doesnt make sense to # merge them like copr builds for tf_result in TFTTestRunModel.get_range(first, last): result_dict = { "pipeline_id": tf_result.pipeline_id, "ref": tf_result.commit_sha, "status": tf_result.status, "target": tf_result.target, "web_url": tf_result.web_url, "pr_id": tf_result.get_pr_id(), } project = tf_result.get_project() result_dict["repo_namespace"] = project.namespace result_dict["repo_name"] = project.repo_name result_dict["project_url"] = project.project_url result.append(result_dict) resp = response_maker( result, status=HTTPStatus.PARTIAL_CONTENT.value, ) resp.headers["Content-Range"] = f"test-results {first + 1}-{last}/*" return resp
def get(self, forge, namespace, repo_name): """List PRs""" result = [] first, last = indices() pr_list = GitProjectModel.get_project_prs(first, last, forge, namespace, repo_name) if not pr_list: return response_maker([]) for pr in pr_list: pr_info = { "pr_id": pr.pr_id, "builds": [], "tests": [], } copr_builds = [] test_runs = [] for build in pr.get_copr_builds(): build_info = { "build_id": build.build_id, "chroot": build.target, "status": build.status, "web_url": build.web_url, } copr_builds.append(build_info) pr_info["builds"] = copr_builds for test_run in pr.get_test_runs(): test_info = { "pipeline_id": test_run.pipeline_id, "chroot": test_run.target, "status": str(test_run.status), "web_url": test_run.web_url, } test_runs.append(test_info) pr_info["tests"] = test_runs result.append(pr_info) resp = response_maker( result, status=HTTPStatus.PARTIAL_CONTENT, ) resp.headers["Content-Range"] = f"git-project-prs {first + 1}-{last}/*" return resp
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, forge, namespace): """List of projects of given forge and namespace""" result = [] projects = GitProjectModel.get_namespace(forge, namespace) if not projects: return response_maker([]) for project in projects: project_info = { "namespace": project.namespace, "repo_name": project.repo_name, "project_url": project.project_url, "prs_handled": len(project.pull_requests), "branches_handled": len(project.branches), "releases_handled": len(project.releases), "issues_handled": len(project.issues), } result.append(project_info) return response_maker(result)
def get(self, forge, namespace, repo_name): """Project Details""" project = GitProjectModel.get_project(forge, namespace, repo_name) if not project: return response_maker( {"error": "No info about project stored in DB"}, status=HTTPStatus.NOT_FOUND, ) project_info = { "namespace": project.namespace, "repo_name": project.repo_name, "project_url": project.project_url, "prs_handled": len(project.pull_requests), "branches_handled": len(project.branches), "releases_handled": len(project.releases), "issues_handled": len(project.issues), } return response_maker(project_info)
def get(self, id): """A specific copr build details. From copr_build hash, filled by worker.""" builds_list = CoprBuildModel.get_all_by_build_id(str(id)) if not bool(builds_list.first()): return response_maker( {"error": "No info about build stored in DB"}, status=HTTPStatus.NOT_FOUND.value, ) build = builds_list[0] build_dict = { "project": build.project_name, "owner": build.owner, "build_id": build.build_id, "status": build.status, # Legacy, remove later. "status_per_chroot": {}, "chroots": [], "build_submitted_time": optional_time(build.build_submitted_time), "build_start_time": optional_time(build.build_start_time), "build_finished_time": optional_time(build.build_finished_time), "commit_sha": build.commit_sha, "web_url": build.web_url, "srpm_logs": build.srpm_build.logs if build.srpm_build else None, # For backwards compatability with the old redis based API "ref": build.commit_sha, } project = build.get_project() if project: build_dict["repo_namespace"] = project.namespace build_dict["repo_name"] = project.repo_name build_dict["git_repo"] = project.project_url build_dict["pr_id"] = build.get_pr_id() build_dict["branch_name"] = build.get_branch_name() # merge chroots into one for sbid_build in builds_list: build_dict["chroots"].append(sbid_build.target) # Get status per chroot as well build_dict["status_per_chroot"][ sbid_build.target] = sbid_build.status return response_maker(build_dict)
class MergedRun(Resource): @ns.response(HTTPStatus.OK.value, "OK, merged run details follow") @ns.response(HTTPStatus.NOT_FOUND.value, "Run ID not found in DB") def get(self, id): """Return details for merged run.""" if result := process_runs([RunModel.get_merged_run(id)]): return response_maker(result[0]) return response_maker({"error": "No run has been found in DB"}, status=HTTPStatus.NOT_FOUND.value)
def get(self): """List all runs.""" first, last = indices() result = process_runs(RunModel.get_merged_chroots(first, last)) resp = response_maker( result, status=HTTPStatus.PARTIAL_CONTENT.value, ) resp.headers["Content-Range"] = f"runs {first + 1}-{last}/*" return resp
def get(self, id): """A specific koji build details. From koji_build hash, filled by worker.""" builds_list = KojiBuildModel.get_all_by_build_id(str(id)) if not builds_list.first(): return response_maker( {"error": "No info about build stored in DB"}, status=HTTPStatus.NOT_FOUND.value, ) build = builds_list[0] build_dict = { "build_id": build.build_id, "status": build.status, "build_start_time": optional_time(build.build_start_time), "build_finished_time": optional_time(build.build_finished_time), "build_submitted_time": optional_time(build.build_submitted_time), "chroot": build.target, "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, "pr_id": build.get_pr_id(), "branch_name": build.get_branch_name(), "ref": build.commit_sha, "release": build.get_release_tag(), } project = build.get_project() if project: build_dict["project_url"] = project.project_url build_dict["repo_namespace"] = project.namespace build_dict["repo_name"] = project.repo_name build_dict[ "srpm_logs"] = build.srpm_build.logs if build.srpm_build else None return response_maker(build_dict)
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)
def get(self): """Health check""" return response_maker({"status": "We are healthy!"}, )
def get(self, id): """Return details for merged run.""" if result := process_runs([RunModel.get_merged_run(id)]): return response_maker(result[0])