|
124 | 124 |
|
125 | 125 |
|
126 | 126 | # --------------------------------------------------------------------------- |
127 | | -# Catalog helpers (shared pattern with verify-release.py) |
| 127 | +# Catalog helpers |
128 | 128 | # --------------------------------------------------------------------------- |
129 | 129 |
|
130 | 130 | def _fetch_pages(api_url: str) -> list: |
@@ -277,7 +277,84 @@ def _find_upstream_remote() -> str: |
277 | 277 | return "" |
278 | 278 |
|
279 | 279 |
|
280 | | -# pylint: disable=too-many-locals,too-many-branches,too-many-statements |
| 280 | +def resolve_commit_sha(tag: str, version: str, |
| 281 | + override: str) -> tuple[str, str]: |
| 282 | + """ |
| 283 | + Return (commit_sha, source_description) for the given version. |
| 284 | +
|
| 285 | + Uses the manually provided *override* SHA when supplied; otherwise |
| 286 | + queries the bundle catalog. Calls sys.exit(1) on any failure. |
| 287 | + """ |
| 288 | + if override: |
| 289 | + return override, "provided manually" |
| 290 | + |
| 291 | + try: |
| 292 | + commit_sha, commit_source = fetch_bundle_info(version) |
| 293 | + except Exception as err: # pylint: disable=broad-except |
| 294 | + print( |
| 295 | + f"\nERROR: fetch_bundle_info failed: {err}", |
| 296 | + file=sys.stderr, |
| 297 | + ) |
| 298 | + sys.exit(1) |
| 299 | + |
| 300 | + if not commit_sha: |
| 301 | + print( |
| 302 | + f"\nERROR: Could not resolve commit SHA for {tag}.", |
| 303 | + file=sys.stderr, |
| 304 | + ) |
| 305 | + print( |
| 306 | + " The bundle image for this version " |
| 307 | + "may not be in the catalog.", |
| 308 | + file=sys.stderr, |
| 309 | + ) |
| 310 | + print( |
| 311 | + " Provide the commit manually: --commit <SHA>", |
| 312 | + file=sys.stderr, |
| 313 | + ) |
| 314 | + sys.exit(1) |
| 315 | + |
| 316 | + return commit_sha, commit_source |
| 317 | + |
| 318 | + |
| 319 | +def resolve_date(tag: str, version: str, override: str) -> tuple[str, str]: |
| 320 | + """ |
| 321 | + Return (published_date, source_description) for the given version. |
| 322 | +
|
| 323 | + Uses the manually provided *override* date when supplied; otherwise |
| 324 | + queries the operator catalog. Calls sys.exit(1) on any failure. |
| 325 | + """ |
| 326 | + if override: |
| 327 | + return override, "provided manually" |
| 328 | + |
| 329 | + try: |
| 330 | + published_date = fetch_operator_push_date(version) |
| 331 | + except Exception as err: # pylint: disable=broad-except |
| 332 | + print( |
| 333 | + f"\nERROR: fetch_operator_push_date failed: {err}", |
| 334 | + file=sys.stderr, |
| 335 | + ) |
| 336 | + sys.exit(1) |
| 337 | + |
| 338 | + if not published_date: |
| 339 | + print( |
| 340 | + f"\nERROR: Could not resolve published date for {tag}.", |
| 341 | + file=sys.stderr, |
| 342 | + ) |
| 343 | + print( |
| 344 | + " The operator image for this version " |
| 345 | + "may not be in the catalog.", |
| 346 | + file=sys.stderr, |
| 347 | + ) |
| 348 | + print( |
| 349 | + " Provide the date manually: --date YYYY-MM-DD", |
| 350 | + file=sys.stderr, |
| 351 | + ) |
| 352 | + sys.exit(1) |
| 353 | + |
| 354 | + return published_date, "operator image push date" |
| 355 | + |
| 356 | + |
| 357 | +# pylint: disable=too-many-locals,too-many-statements |
281 | 358 | def main(): |
282 | 359 | """Parse args, resolve tag details, confirm with user, create the tag.""" |
283 | 360 | parser = argparse.ArgumentParser( |
@@ -308,6 +385,11 @@ def main(): |
308 | 385 | if not re.fullmatch(r"\d+\.\d+\.\d+", args.version): |
309 | 386 | parser.error(f"version must be X.Y.Z, got: {args.version!r}") |
310 | 387 |
|
| 388 | + if args.commit and not _HEX_RE.match(args.commit): |
| 389 | + parser.error( |
| 390 | + f"--commit must be a hex SHA (7-40 characters), got: {args.commit!r}" |
| 391 | + ) |
| 392 | + |
311 | 393 | if args.date: |
312 | 394 | try: |
313 | 395 | date.fromisoformat(args.date) |
@@ -336,62 +418,8 @@ def main(): |
336 | 418 | flush=True, |
337 | 419 | ) |
338 | 420 |
|
339 | | - if args.commit: |
340 | | - commit_sha = args.commit |
341 | | - commit_source = "provided manually" |
342 | | - else: |
343 | | - try: |
344 | | - commit_sha, commit_source = fetch_bundle_info(version) |
345 | | - except Exception as err: # pylint: disable=broad-except |
346 | | - print( |
347 | | - f"\nERROR: fetch_bundle_info failed: {err}", |
348 | | - file=sys.stderr, |
349 | | - ) |
350 | | - sys.exit(1) |
351 | | - if not commit_sha: |
352 | | - print( |
353 | | - f"\nERROR: Could not resolve commit SHA for {tag}.", |
354 | | - file=sys.stderr, |
355 | | - ) |
356 | | - print( |
357 | | - " The bundle image for this version " |
358 | | - "may not be in the catalog.", |
359 | | - file=sys.stderr, |
360 | | - ) |
361 | | - print( |
362 | | - " Provide the commit manually: --commit <SHA>", |
363 | | - file=sys.stderr, |
364 | | - ) |
365 | | - sys.exit(1) |
366 | | - |
367 | | - if args.date: |
368 | | - published_date = args.date |
369 | | - date_source = "provided manually" |
370 | | - else: |
371 | | - try: |
372 | | - published_date = fetch_operator_push_date(version) |
373 | | - except Exception as err: # pylint: disable=broad-except |
374 | | - print( |
375 | | - f"\nERROR: fetch_operator_push_date failed: {err}", |
376 | | - file=sys.stderr, |
377 | | - ) |
378 | | - sys.exit(1) |
379 | | - date_source = "operator image push date" |
380 | | - if not published_date: |
381 | | - print( |
382 | | - f"\nERROR: Could not resolve published date for {tag}.", |
383 | | - file=sys.stderr, |
384 | | - ) |
385 | | - print( |
386 | | - " The operator image for this version " |
387 | | - "may not be in the catalog.", |
388 | | - file=sys.stderr, |
389 | | - ) |
390 | | - print( |
391 | | - " Provide the date manually: --date YYYY-MM-DD", |
392 | | - file=sys.stderr, |
393 | | - ) |
394 | | - sys.exit(1) |
| 421 | + commit_sha, commit_source = resolve_commit_sha(tag, version, args.commit) |
| 422 | + published_date, date_source = resolve_date(tag, version, args.date) |
395 | 423 |
|
396 | 424 | # Expand to full commit SHA and verify it exists locally |
397 | 425 | try: |
|
0 commit comments