Skip to content

Commit abe696b

Browse files
committed
ART-8680: fixed art-bot query using catalogs
1 parent ad7f2c0 commit abe696b

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

artbotlib/brew_list.py

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import json
44
import logging
55
import re
6-
import urllib.request
76
from typing import cast, Dict
87
from urllib.parse import quote
98

@@ -12,9 +11,8 @@
1211
import yaml
1312

1413
import artbotlib.exectools
15-
14+
from artbotlib import constants
1615
from . import util
17-
from .constants import RHCOS_BASE_URL
1816
from .rhcos import RHCOSBuildInfo
1917

2018
logger = logging.getLogger(__name__)
@@ -108,7 +106,7 @@ async def get_tag_specs(so, tag_spec, data_type, sem) -> str:
108106
component_release = component_labels.get('release', '?')
109107
component_upstream_commit_url = component_labels.get('io.openshift.build.commit.url', '?')
110108
component_distgit_commit = component_labels.get('vcs-ref', '?')
111-
component_rhcc_url = component_labels.get('url', '?')
109+
logger.info(f"COMPONENT_NAME: {component_name}")
112110

113111
result = f'{release_component_name}='
114112
if data_type.startswith('nvr'):
@@ -120,18 +118,62 @@ async def get_tag_specs(so, tag_spec, data_type, sem) -> str:
120118
distgit_name = component_name.rstrip('container')
121119
distgit_name = distgit_name.rstrip("-")
122120

123-
result += f'https://pkgs.devel.redhat.com/cgit/containers/{distgit_name}/commit/?id={component_distgit_commit}'
121+
result += f'{constants.DISTGIT_URL}/{distgit_name}/commit/?id={component_distgit_commit}'
122+
124123
elif data_type.startswith('commit'):
125124
result += f'{component_upstream_commit_url}'
126125
elif data_type.startswith('catalog'):
127-
result += f'{component_rhcc_url}'
126+
image_type = 'distgit'
127+
suffix = "-container"
128+
catalog_name = ""
129+
if suffix in component_name:
130+
catalog_name = component_name.rstrip('container')
131+
catalog_name = catalog_name.rstrip("-")
132+
version = component_version.strip('v')
133+
version = version[:4]
134+
data_info = catalog_api_query(so, image_type, catalog_name, version)
135+
136+
try:
137+
for item in data_info:
138+
cat_id, cat_name = item
139+
result += f"{constants.CATALOG_URL}/{cat_name}/{cat_id}\n"
140+
except Exception as e:
141+
# Handle any exceptions that might occur within the try block
142+
print("Payload is empty:", e)
143+
128144
elif data_type.startswith('image'):
129145
result += release_component_image
130146

131147
logger.debug('Tag specs for %s: %s', data_type, result)
132148
return result
133149

134150

151+
def catalog_api_query(so, image_type, catalog_name, version):
152+
url = f"{constants.ART_DASH_API_ROUTE}/" \
153+
f"pipeline-image?starting_from={image_type}&name={catalog_name}&version={version}"
154+
logger.info(f"URL: {url}")
155+
response = requests.get(url)
156+
157+
if response.status_code != 200:
158+
logger.error(f"API Server error. Status code: {response.status_code}")
159+
so.say("API server error. Contact ART Team.")
160+
so.monitoring_say("ERROR: API server error.")
161+
return
162+
163+
try:
164+
catalogs_info = response.json()
165+
except Exception as e:
166+
logger.error(f"JSON Error: {e}")
167+
so.say("Error. Contact ART Team")
168+
so.monitoring_say(f"JSON Error: {e}")
169+
return
170+
171+
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"]]
172+
#logger.info(f"CATALOG_DATA: {catalog_data}")
173+
174+
return catalog_data
175+
176+
135177
def list_component_data_for_release_tag(so, data_type, release_tag):
136178
data_type = data_type.lower()
137179
data_types = ('nvr', 'distgit', 'commit', 'catalog', 'image')

artbotlib/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919

2020
BREW_URL = 'https://brewweb.engineering.redhat.com/brew'
2121

22+
CATALOG_URL = 'https://catalog.redhat.com/software/containers'
23+
2224
CGIT_URL = 'https://pkgs.devel.redhat.com/cgit'
2325

2426
COMET_URL = 'https://comet.engineering.redhat.com/containers/repositories'
2527

28+
DISTGIT_URL = 'https://pkgs.devel.redhat.com/cgit/containers'
29+
2630
ERRATA_TOOL_URL = 'https://errata.devel.redhat.com'
2731

2832
GITHUB_API_REPO_URL = "https://api.github.com/repos"

0 commit comments

Comments
 (0)