Skip to content

Commit c6ed506

Browse files
committed
Refactor apollo_tree.py to use aiohttp params and simplify API detection
Improves code quality and API ergonomics based on PR feedback. Key changes: - Use aiohttp's params parameter instead of manual query string construction - Remove explicit --api-version flag in favor of auto-detection - API version determined by presence of --major-version parameter - Extract API_BASE_URL as module constant for reusability
1 parent e1a1e50 commit c6ed506

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

apollo/publishing_tools/apollo_tree.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
}
2626

2727
PRODUCT_NAME_TO_SLUG = {v: k for k, v in PRODUCT_SLUG_MAP.items()}
28-
28+
API_BASE_URL = "https://apollo.build.resf.org/api/v3/updateinfo"
2929

3030
def get_product_slug(product_name: str) -> str:
3131
"""
@@ -170,7 +170,6 @@ async def fetch_updateinfo_from_apollo(
170170
repo: dict,
171171
product_name: str,
172172
api_base: str = None,
173-
api_version: int = 1,
174173
major_version: int = None,
175174
minor_version: int = None,
176175
) -> str:
@@ -181,28 +180,27 @@ async def fetch_updateinfo_from_apollo(
181180
repo: Repository dict with 'name' and 'arch' keys
182181
product_name: Product name
183182
api_base: Optional API base URL override
184-
api_version: 2 for new endpoint, 1 for legacy (default)
185183
major_version: Required for api_version=2
186184
minor_version: Optional for api_version=2
187185
"""
188186
if not api_base:
189-
api_base = "https://apollo.build.resf.org/api/v3/updateinfo"
187+
api_base = API_BASE_URL
190188

191-
if api_version == 2:
189+
if major_version:
192190
product_slug = get_product_slug(product_name)
193191
api_url = f"{api_base}/{product_slug}/{major_version}/{quote(repo['name'])}/updateinfo.xml"
194-
api_url += f"?arch={repo['arch']}"
192+
api_params = {'arch': repo['arch']}
195193
if minor_version is not None:
196-
api_url += f"&minor_version={minor_version}"
197-
logger.info("Using v2 endpoint: %s", api_url)
194+
api_params['minor_version'] = minor_version
195+
logger.info("Using v2 endpoint: %s with params %s", api_url, api_params)
198196
else:
199197
pname_arch = product_name.replace("$arch", repo["arch"])
200198
api_url = f"{api_base}/{quote(pname_arch)}/{quote(repo['name'])}/updateinfo.xml"
201-
api_url += f"?req_arch={repo['arch']}"
202-
logger.info("Using legacy endpoint: %s", api_url)
199+
api_params = {'req_arch': repo['arch']}
200+
logger.info("Using legacy endpoint: %s with params %s", api_url, api_params)
203201

204202
async with aiohttp.ClientSession() as session:
205-
async with session.get(api_url) as resp:
203+
async with session.get(api_url, params=api_params) as resp:
206204
if resp.status != 200 and resp.status != 404:
207205
logger.warning(
208206
"Failed to fetch updateinfo from %s, skipping", api_url
@@ -354,7 +352,6 @@ async def run_apollo_tree(
354352
ignore: list[str],
355353
ignore_arch: list[str],
356354
product_name: str,
357-
api_version: int = 1,
358355
major_version: int = None,
359356
minor_version: int = None,
360357
api_base: str = None,
@@ -376,7 +373,6 @@ async def run_apollo_tree(
376373
repo,
377374
product_name,
378375
api_base=api_base,
379-
api_version=api_version,
380376
major_version=major_version,
381377
minor_version=minor_version,
382378
)
@@ -455,13 +451,6 @@ async def run_apollo_tree(
455451
required=True,
456452
help="Product name (e.g., 'Rocky Linux', 'Rocky Linux 8 $arch')",
457453
)
458-
parser.add_argument(
459-
"--api-version",
460-
type=int,
461-
choices=[2, 1],
462-
default=1,
463-
help="Updateinfo endpoint pattern: 1=legacy (default), 2=new major-version based",
464-
)
465454
parser.add_argument(
466455
"--major-version",
467456
type=int,
@@ -481,11 +470,8 @@ async def run_apollo_tree(
481470
if p_args.auto_scan and p_args.manual:
482471
parser.error("Cannot use --auto-scan and --manual together")
483472

484-
if p_args.api_version == 2 and not p_args.major_version:
485-
parser.error("--major-version is required when using --api-version 2")
486-
487-
if p_args.minor_version and p_args.api_version != 2:
488-
parser.error("--minor-version can only be used with --api-version 2")
473+
if p_args.minor_version and not p_args.major_version:
474+
parser.error("--minor-version can only be used with --major-version")
489475

490476
if p_args.manual and not p_args.repos:
491477
parser.error("Must specify repos to publish in manual mode")
@@ -502,7 +488,6 @@ async def run_apollo_tree(
502488
[y for x in p_args.ignore for y in x],
503489
[y for x in p_args.ignore_arch for y in x],
504490
p_args.product_name,
505-
p_args.api_version,
506491
p_args.major_version,
507492
p_args.minor_version,
508493
p_args.api_base,

0 commit comments

Comments
 (0)