def get_builds(self, number_of_builds: int = 3) -> None: """ Get specific number of latest builds from koji :param number_of_builds: int :return: None """ logger.info("\nLatest builds:") # https://github.com/fedora-infra/bodhi/issues/3058 from bodhi.client.bindings import BodhiClient b = BodhiClient() builds_d = b.latest_builds(self.dg.package_name) branches = self.dg.local_project.git_project.get_branches() branches.remove("master") # there is no master tag in koji for branch in branches: koji_tag = f"{branch}-updates-candidate" try: koji_builds = [builds_d[koji_tag]] # take last three builds koji_builds = (koji_builds[:number_of_builds] if len(koji_builds) > number_of_builds else koji_builds) koji_builds_str = "\n".join(f" - {b}" for b in koji_builds) logger.info(f"{branch}:\n{koji_builds_str}") except KeyError: logger.info(f"{branch}: No builds.")
def create_bodhi_update( self, dist_git_branch: str, update_type: str, update_notes: str, koji_builds: Sequence[str] = None, ): logger.debug( f"About to create a Bodhi update of type {update_type} from {dist_git_branch}" ) # https://github.com/fedora-infra/bodhi/issues/3058 from bodhi.client.bindings import BodhiClient, BodhiClientException if not self.package_name: raise PackitException("Package name is not set.") # bodhi will likely prompt for username and password if kerb ticket is not up b = BodhiClient() if not koji_builds: # alternatively we can call something like `koji latest-build rawhide sen` builds_d = b.latest_builds(self.package_name) builds_str = "\n".join(f" - {b}" for b in builds_d) logger.debug( f"Koji builds for package {self.package_name}: \n{builds_str}") koji_tag = f"{dist_git_branch}-updates-candidate" try: koji_builds = [builds_d[koji_tag]] koji_builds_str = "\n".join(f" - {b}" for b in koji_builds) logger.info( f"Koji builds for package {self.package_name} and koji tag {koji_tag}:" f"\n{koji_builds_str}") except KeyError: raise PackitException( f"There is no build for {self.package_name} in koji tag {koji_tag}" ) # I was thinking of verifying that the build is valid for a new bodhi update # but in the end it's likely a waste of resources since bodhi will tell us rendered_note = update_notes.format( version=self.specfile.get_version()) try: result = b.save(builds=koji_builds, notes=rendered_note, type=update_type) logger.debug(f"Bodhi response:\n{result}") logger.info(f"Bodhi update {result['alias']}:\n" f"- {result['url']}\n" f"- stable_karma: {result['stable_karma']}\n" f"- unstable_karma: {result['unstable_karma']}\n" f"- notes:\n{result['notes']}\n") if "caveats" in result: for cav in result["caveats"]: logger.info(f"- {cav['name']}: {cav['description']}\n") except BodhiClientException as ex: logger.error(ex) raise PackitException( f"There is a problem with creating the bodhi update:\n{ex}") return result["alias"]
def get_builds(self, number_of_builds: int = 3) -> Dict: """ Get specific number of latest builds from koji :param number_of_builds: int :return: None """ # https://github.com/fedora-infra/bodhi/issues/3058 from bodhi.client.bindings import BodhiClient b = BodhiClient() builds_d = b.latest_builds(self.dg.package_name) branches = self.dg.local_project.git_project.get_branches() branches.remove("master") # there is no master tag in koji builds: Dict = {} for branch in branches: koji_tag = f"{branch}-updates-candidate" try: # take last three builds builds[branch] = builds_d[koji_tag][:number_of_builds] except KeyError: logger.info(f"There are no builds for branch {branch}") return builds
def get_builds(self, ) -> Dict: """ Get latest koji builds """ # https://github.com/fedora-infra/bodhi/issues/3058 from bodhi.client.bindings import BodhiClient b = BodhiClient() # { koji-target: "latest-build-nvr"} builds_d = b.latest_builds( self.dg.package_config.downstream_package_name) branches = self.dg.local_project.git_project.get_branches() logger.debug("Latest koji builds fetched.") builds: Dict = {} for branch in branches: # there is no master tag in koji if branch == "master": continue koji_tag = f"{branch}-updates-candidate" try: builds[branch] = builds_d[koji_tag] except KeyError: logger.info(f"There are no builds for branch {branch}") return builds
def create_bodhi_update( self, dist_git_branch: str, update_type: str, update_notes: str, koji_builds: Sequence[str] = None, bugzilla_ids: Optional[List[int]] = None, ): logger.debug( f"About to create a Bodhi update of type {update_type!r} from {dist_git_branch!r}" ) # bodhi will likely prompt for username and password if kerb ticket is not up b = BodhiClient() if not koji_builds: # alternatively we can call something like `koji latest-build rawhide sen` builds_d = b.latest_builds(self.package_config.downstream_package_name) builds_str = "\n".join(f" - {b}" for b in builds_d) logger.debug( "Koji builds for package " f"{self.package_config.downstream_package_name!r}: \n{builds_str}" ) # EPEL uses "testing-candidate" instead of "updates-candidate" prefix = "testing" if dist_git_branch.startswith("epel") else "updates" koji_tag = f"{dist_git_branch}-{prefix}-candidate" try: koji_builds = [builds_d[koji_tag]] koji_builds_str = "\n".join(f" - {b}" for b in koji_builds) logger.info( "Koji builds for package " f"{self.package_config.downstream_package_name!r} and koji tag {koji_tag}:" f"\n{koji_builds_str}" ) except KeyError: raise PackitException( f"There is no build for {self.package_config.downstream_package_name!r} " f"in koji tag {koji_tag}" ) # I was thinking of verifying that the build is valid for a new bodhi update # but in the end it's likely a waste of resources since bodhi will tell us rendered_note = update_notes.format(version=self.specfile.get_version()) try: save_kwargs = { "builds": koji_builds, "notes": rendered_note, "type": update_type, } if bugzilla_ids: save_kwargs["bugs"] = list(map(str, bugzilla_ids)) result = b.save(**save_kwargs) logger.debug(f"Bodhi response:\n{result}") logger.info( f"Bodhi update {result['alias']}:\n" f"- {result['url']}\n" f"- stable_karma: {result['stable_karma']}\n" f"- unstable_karma: {result['unstable_karma']}\n" f"- notes:\n{result['notes']}\n" ) if "caveats" in result: for cav in result["caveats"]: logger.info(f"- {cav['name']}: {cav['description']}\n") except BodhiClientException as ex: logger.error(ex) raise PackitException( f"There is a problem with creating the bodhi update:\n{ex}" ) return result["alias"]