From f739d95a964ad9ef4b6020f0ff2fac0ade43134d Mon Sep 17 00:00:00 2001 From: Michael Biarnes Kiefer Date: Tue, 20 Feb 2024 12:44:51 +0100 Subject: [PATCH] ART-8680: fixed art-bot query using catalogs Update artbotlib/brew_list.py Co-authored-by: Daniele Paolella --- artbotlib/brew_list.py | 53 ++++++++++++++++++++++++++++++++++++++---- artbotlib/constants.py | 4 ++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/artbotlib/brew_list.py b/artbotlib/brew_list.py index 7100dfb..0d8d5c3 100644 --- a/artbotlib/brew_list.py +++ b/artbotlib/brew_list.py @@ -14,7 +14,7 @@ import artbotlib.exectools from . import util -from .constants import NIGHTLY_REGISTRY, QUAY_REGISTRY +from .constants import NIGHTLY_REGISTRY, QUAY_REGISTRY, CATALOG_URL, DISTGIT_URL, ART_DASH_API_ROUTE from .rhcos import RHCOSBuildInfo logger = logging.getLogger(__name__) @@ -108,7 +108,7 @@ async def get_tag_specs(so, tag_spec, data_type, sem) -> str: component_release = component_labels.get('release', '?') component_upstream_commit_url = component_labels.get('io.openshift.build.commit.url', '?') component_distgit_commit = component_labels.get('vcs-ref', '?') - component_rhcc_url = component_labels.get('url', '?') + logger.info(f"COMPONENT_NAME: {component_name}") result = f'{release_component_name}=' if data_type.startswith('nvr'): @@ -120,11 +120,30 @@ async def get_tag_specs(so, tag_spec, data_type, sem) -> str: distgit_name = component_name.rstrip('container') distgit_name = distgit_name.rstrip("-") - result += f'https://pkgs.devel.redhat.com/cgit/containers/{distgit_name}/commit/?id={component_distgit_commit}' + result += f'{DISTGIT_URL}/{distgit_name}/commit/?id={component_distgit_commit}' + elif data_type.startswith('commit'): result += f'{component_upstream_commit_url}' elif data_type.startswith('catalog'): - result += f'{component_rhcc_url}' + image_type = 'distgit' + suffix = "-container" + catalog_name = "" + if suffix in component_name: + catalog_name = component_name.rstrip('container') + catalog_name = catalog_name.rstrip("-") + # component_version comes in format i.e. v4.14.18 - needed version in four digits format (i.e. 4.14) + version = component_version.strip('v') + version = version[:4] + data_info = catalog_api_query(so, image_type, catalog_name, version) + + try: + for item in data_info: + cat_id, cat_name = item + result += f"{CATALOG_URL}/{cat_name}/{cat_id}\n" + except TypeError as e: + # Handle TypeError exceptions that might occur within the try block + logger.warning("Payload is empty:", e) + elif data_type.startswith('image'): result += release_component_image @@ -132,6 +151,32 @@ async def get_tag_specs(so, tag_spec, data_type, sem) -> str: return result +def catalog_api_query(so, image_type, catalog_name, version): + url = f"{ART_DASH_API_ROUTE}/" \ + f"pipeline-image?starting_from={image_type}&name={catalog_name}&version={version}" + logger.info(f"URL: {url} \n\n") + response = requests.get(url) + + if response.status_code != 200: + logger.error(f"API Server error. Status code: {response.status_code}") + so.say("API server error. Contact ART Team.") + so.monitoring_say("ERROR: API server error.") + return + + try: + catalogs_info = response.json() + except Exception as e: + logger.error(f"JSON Error: {e}") + so.say("Error. Contact ART Team") + so.monitoring_say(f"JSON Error: {e}") + return + + catalog_data = [(repo['delivery']['delivery_repo_id'], repo['delivery']['delivery_repo_name']) for dg in catalogs_info["payload"]["distgit"] for repo in dg["brew"]["cdn"]] + #logger.info(f"CATALOG_DATA: {catalog_data}") + + return catalog_data + + def list_component_data_for_release_tag(so, data_type, release_tag): data_type = data_type.lower() data_types = ('nvr', 'distgit', 'commit', 'catalog', 'image') diff --git a/artbotlib/constants.py b/artbotlib/constants.py index 44fe3b0..a54dd6d 100644 --- a/artbotlib/constants.py +++ b/artbotlib/constants.py @@ -19,10 +19,14 @@ BREW_URL = 'https://brewweb.engineering.redhat.com/brew' +CATALOG_URL = 'https://catalog.redhat.com/software/containers' + CGIT_URL = 'https://pkgs.devel.redhat.com/cgit' COMET_URL = 'https://comet.engineering.redhat.com/containers/repositories' +DISTGIT_URL = 'https://pkgs.devel.redhat.com/cgit/containers' + ERRATA_TOOL_URL = 'https://errata.devel.redhat.com' GITHUB_API_REPO_URL = "https://api.github.com/repos"