From 33a0673ce378bad4510cbb248c1f089e1c713957 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Sep 22 2022 08:49:04 +0000 Subject: copr_bug: migrate to APIv3 --- diff --git a/src/FedoraReview/copr_bug.py b/src/FedoraReview/copr_bug.py index b647c87..4bdad1b 100644 --- a/src/FedoraReview/copr_bug.py +++ b/src/FedoraReview/copr_bug.py @@ -33,7 +33,9 @@ from .review_error import ReviewError from .settings import Settings from .url_bug import UrlBug -COPR_API_URL_TEMPLATE = "https://copr.fedoraproject.org/api/coprs/build/{}/" +COPR_HOST = "http://copr.fedorainfracloud.org" +COPR_API_URL_TEMPLATE = COPR_HOST + "/api_3/build/{}" +COPR_BUILD_URL_TEMPLATE = "/coprs/build/{}" def get_build_data(build_id): @@ -138,24 +140,18 @@ class CoprBug(UrlBug): def get_location(self, build_id): """Get COPR build URI""" build_data = get_build_data(build_id) - - if build_data["status"] != "succeeded": - self.log.error("Build did not succeeded in all its chroots.Exiting.") + state = build_data.get("state", "unknown") + if state != "succeeded": + self.log.error("Copr build did not succeed, state=%s", state) sys.exit(1) required_chroot = "fedora-rawhide-" + platform.machine() + chroots = build_data.get("chroots", []) + if required_chroot not in chroots: + self.log.error("%s chroot not found. Exiting.", required_chroot) + sys.exit(1) - fedora_chroots = filter( - lambda pair: pair[0].startswith("fedora"), - build_data["results_by_chroot"].items(), - ) - - for chroot, uri in fedora_chroots: - if chroot == required_chroot: - return uri - - self.log.error("%s chroot not found. Exiting.", required_chroot) - sys.exit(1) + return COPR_BUILD_URL_TEMPLATE.format(build_id) def check_options(self): # pylint: disable=R0201 """Raise error if Settings combination is invalid."""