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 bool(builds_list.first()): 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"] = f"https://github.com/{project.namespace}/{project.repo_name}" build_dict[ "https_url"] = f"https://github.com/{project.namespace}/{project.repo_name}.git" build_dict["pr_id"] = build.get_pr_id() # 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 build = make_response(dumps(build_dict)) build.headers["Content-Type"] = "application/json" build.headers["Access-Control-Allow-Origin"] = "*" return build if build else ("", HTTPStatus.NO_CONTENT) else: return "", HTTPStatus.NO_CONTENT
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 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": url_for( "builds.get_srpm_build_logs_by_id", id_=build.id, _external=True ), "build_submitted_time": optional_time(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, 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)
def get(self): """ List all Copr builds. """ # Return relevant info thats concise # Usecases like the packit-dashboard copr-builds table result = [] checklist = [] first, last = indices() for build in islice(CoprBuildModel.get_all(), first, last): if int(build.build_id) not in checklist: 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), "web_url": build.web_url, } project = build.get_project() if project: build_dict["repo_namespace"] = project.namespace build_dict["repo_name"] = project.repo_name # same_buildid_builds are copr builds created due to the same trigger # multiple identical builds are created which differ only in target # so we merge them into one same_buildid_builds = CoprBuildModel.get_all_by_build_id( str(build.build_id)) for sbid_build in same_buildid_builds: build_dict["chroots"].append(sbid_build.target) # Get status per chroot as well build_dict["status_per_chroot"][ sbid_build.target] = sbid_build.status checklist.append(int(build.build_id)) result.append(build_dict) resp = make_response(dumps(result), HTTPStatus.PARTIAL_CONTENT) resp.headers[ "Content-Range"] = f"copr-builds {first + 1}-{last}/{len(result)}" resp.headers["Content-Type"] = "application/json" 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_build_info(build: Union[KojiBuildModel, CoprBuildModel], build_description: str): project = build.get_project() trigger = build.job_trigger.get_trigger_object() if isinstance(trigger, PullRequestModel): title_identifier = f"PR #{trigger.pr_id}" elif isinstance(trigger, GitBranchModel): title_identifier = f"branch {trigger.name}" elif isinstance(trigger, ProjectReleaseModel): title_identifier = f"release {trigger.tag_name}" else: title_identifier = "" return render_template( "build_info.html", project=project, title_identifier=title_identifier, build_description=build_description, build=build, build_submitted_time=models.optional_time(build.build_submitted_time, fmt="%Y-%m-%d %H:%M:%S UTC"), )
def test_optional_time(input_object, expected_type): # optional_time returns a string if its passed a datetime object # None if passed a NoneType object assert isinstance(optional_time(input_object), expected_type)