def parse_koji_event(event) -> Optional[KojiBuildEvent]: if event.get("topic") != "org.fedoraproject.prod.buildsys.task.state.change": return None build_id = event.get("id") logger.info(f"Koji event: build_id={build_id}") state = nested_get(event, "info", "state") if not state: logger.debug("Cannot find build state.") return None state_enum = KojiBuildState(event.get("new")) if "new" in event else None old_state = KojiBuildState(event.get("old")) if "old" in event else None start_time = nested_get(event, "info", "start_time") completion_time = nested_get(event, "info", "completion_time") rpm_build_task_id = None for children in nested_get(event, "info", "children", default=[]): if children.get("method") == "buildArch": rpm_build_task_id = children.get("id") break return KojiBuildEvent( build_id=build_id, state=state_enum, old_state=old_state, start_time=start_time, completion_time=completion_time, rpm_build_task_id=rpm_build_task_id, )
def parse_koji_build_event(event) -> Optional[KojiBuildEvent]: if event.get("topic" ) != "org.fedoraproject.prod.buildsys.build.state.change": return None # Some older messages had a different structure content = event.get("body") or event.get("msg") if not content: return None build_id = content.get("build_id") task_id = content.get("task_id") logger.info(f"Koji event: build_id={build_id} task_id={task_id}") new_state = (KojiBuildState.from_number(raw_new) if (raw_new := content.get("new")) is not None else None) old_state = (KojiBuildState.from_number(raw_old) if (raw_old := content.get("old")) is not None else None) version = content.get("version") epoch = content.get("epoch") # "release": "1.fc36" release, _ = content.get("release").split(".") # "request": [ # "git+https://src.fedoraproject.org/rpms/packit.git#0eb3e12005cb18f15d3054020f7ac934c01eae08", # "rawhide", # {} # ], raw_git_ref, fedora_target, _ = content.get("request") project_url = (raw_git_ref.split("#")[0].removeprefix( "git+").removesuffix(".git")) package_name, commit_hash = raw_git_ref.split("/")[-1].split(".git#") branch_name = fedora_target.removesuffix("-candidate") return KojiBuildEvent( build_id=build_id, state=new_state, package_name=package_name, branch_name=branch_name, commit_sha=commit_hash, namespace="rmps", repo_name=package_name, project_url=project_url, epoch=epoch, version=version, release=release, rpm_build_task_id=task_id, web_url=KojiBuildEvent.get_koji_rpm_build_web_url( rpm_build_task_id=task_id, koji_web_url=ServiceConfig.get_service_config().koji_web_url, ), old_state=old_state, )
def from_event_dict(cls, event: dict): return KojiBuildEvent( build_id=event.get("build_id"), state=KojiBuildState(event.get("state")) if event.get("state") else None, old_state=(KojiBuildState(event.get("old_state")) if event.get("old_state") else None), rpm_build_task_id=event.get("rpm_build_task_id"), start_time=event.get("start_time"), completion_time=event.get("completion_time"), )
def from_event_dict(cls, event: dict): return KojiBuildEvent( build_id=event.get("build_id"), state=KojiBuildState(raw_new) if (raw_new := event.get("state")) else None, old_state=(KojiBuildState(raw_old) if (raw_old := event.get("old_state")) else None), rpm_build_task_id=event.get("rpm_build_task_id"), package_name=event.get("package_name"), project_url=event.get("project_url"), web_url=event.get("web_url"), branch_name=event.get("branch_name"), repo_name=event.get("repo_name"), namespace=event.get("namespace"), commit_sha=event.get("commit_sha"), epoch=event.get("epoch"), version=event.get("version"), release=event.get("release"), )