Skip to content

Commit 1d064ad

Browse files
mbiarneslocriandev
andcommitted
ART-8680: fixed art-bot query using catalogs
Update artbotlib/brew_list.py Co-authored-by: Daniele Paolella <[email protected]>
1 parent 06cec01 commit 1d064ad

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

artbotlib/brew_list.py

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
import artbotlib.exectools
1515

1616
from . import util
17-
from .constants import NIGHTLY_REGISTRY, QUAY_REGISTRY
17+
from .constants import NIGHTLY_REGISTRY, QUAY_REGISTRY, CATALOG_URL, DISTGIT_URL, ART_DASH_API_ROUTE
1818
from .rhcos import RHCOSBuildInfo
1919

2020
logger = logging.getLogger(__name__)
2121

2222

23-
@util.cached
23+
@artbotlib.util.cached
2424
def brew_list_components(nvr):
2525
koji_api = util.koji_client_session()
2626
logger.info('Getting info for build %s', nvr)
@@ -108,7 +108,7 @@ async def get_tag_specs(so, tag_spec, data_type, sem) -> str:
108108
component_release = component_labels.get('release', '?')
109109
component_upstream_commit_url = component_labels.get('io.openshift.build.commit.url', '?')
110110
component_distgit_commit = component_labels.get('vcs-ref', '?')
111-
component_rhcc_url = component_labels.get('url', '?')
111+
logger.info(f"COMPONENT_NAME: {component_name}")
112112

113113
result = f'{release_component_name}='
114114
if data_type.startswith('nvr'):
@@ -120,18 +120,62 @@ async def get_tag_specs(so, tag_spec, data_type, sem) -> str:
120120
distgit_name = component_name.rstrip('container')
121121
distgit_name = distgit_name.rstrip("-")
122122

123-
result += f'https://pkgs.devel.redhat.com/cgit/containers/{distgit_name}/commit/?id={component_distgit_commit}'
123+
result += f'{DISTGIT_URL}/{distgit_name}/commit/?id={component_distgit_commit}'
124+
124125
elif data_type.startswith('commit'):
125126
result += f'{component_upstream_commit_url}'
126127
elif data_type.startswith('catalog'):
127-
result += f'{component_rhcc_url}'
128+
image_type = 'distgit'
129+
suffix = "-container"
130+
catalog_name = ""
131+
if suffix in component_name:
132+
catalog_name = component_name.rstrip('container')
133+
catalog_name = catalog_name.rstrip("-")
134+
# component_version comes in format i.e. v4.14.18 - needed version in four digits format (i.e. 4.14)
135+
version = component_version.strip('v')
136+
version = version[:4]
137+
data_info = catalog_api_query(so, image_type, catalog_name, version)
138+
139+
try:
140+
for item in data_info:
141+
cat_id, cat_name = item
142+
result += f"{CATALOG_URL}/{cat_name}/{cat_id}\n"
143+
except TypeError as e:
144+
# Handle TypeError exceptions that might occur within the try block
145+
logger.warning(f"Payload is empty for {catalog_name}:", e)
146+
128147
elif data_type.startswith('image'):
129148
result += release_component_image
130149

131150
logger.debug('Tag specs for %s: %s', data_type, result)
132151
return result
133152

134153

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