|
13 | 13 | _print_vulnerabilities_summary_table, |
14 | 14 | get_package_scan_result, |
15 | 15 | ) |
| 16 | +from ...core.pagination import paginate_results |
16 | 17 | from .. import decorators, utils, validators |
17 | 18 | from .main import main |
18 | 19 |
|
19 | 20 |
|
20 | | -def get_packages_in_repo(opts, owner, repo): |
21 | | - """Get all packages in a repository, paginating through all pages.""" |
22 | | - all_packages = [] |
23 | | - page = 1 |
24 | | - page_size = 100 # fetch in larger batches for efficiency |
25 | | - |
26 | | - try: |
27 | | - while True: |
28 | | - packages, page_info = list_packages( |
29 | | - opts=opts, |
30 | | - owner=owner, |
31 | | - repo=repo, |
32 | | - query=None, |
33 | | - sort=None, |
34 | | - page=page, |
35 | | - page_size=page_size, |
36 | | - ) |
37 | | - |
38 | | - if packages: |
39 | | - all_packages.extend(packages) |
40 | | - |
41 | | - # No page info means single page or no results |
42 | | - if not page_info: |
43 | | - break |
44 | | - |
45 | | - current_page = getattr(page_info, "page", page) |
46 | | - total_pages = getattr(page_info, "page_total", 1) |
47 | | - |
48 | | - if current_page >= total_pages: |
49 | | - break |
50 | | - |
51 | | - page += 1 |
52 | | - |
53 | | - except Exception as exc: |
54 | | - raise click.ClickException( |
55 | | - f"Failed to list packages for '{owner}/{repo}'. " |
56 | | - f"Please check the owner and repository names are correct. " |
57 | | - f"Detail: {exc}" |
58 | | - ) from exc |
59 | | - |
60 | | - if not all_packages: |
61 | | - raise click.ClickException( |
62 | | - f"No packages found in '{owner}/{repo}'. " |
63 | | - f"The repository may be empty, or the owner/repo names may be incorrect." |
64 | | - ) |
65 | | - |
66 | | - return [ |
67 | | - (pkg["slug_perm"], pkg.get("name", pkg["slug_perm"]), pkg.get("version", "")) |
68 | | - for pkg in all_packages |
69 | | - ] |
70 | | - |
71 | | - |
72 | 21 | def _has_scan_results(data): |
73 | 22 | """Check whether scan data contains actual scan results.""" |
74 | 23 | scans = getattr(data, "scans", None) |
@@ -336,9 +285,8 @@ def _collect_repo_scan_data(opts, owner, repo, slugs, severity_filter, fixable): |
336 | 285 | "severity_filter", |
337 | 286 | help="Filter by severities (e.g., 'CRITICAL', 'HIGH', 'MEDIUM', 'LOW').", |
338 | 287 | ) |
339 | | -@click.pass_context |
340 | 288 | def vulnerabilities( |
341 | | - ctx, opts, owner_repo_package, show_assessment, fixable, severity_filter |
| 289 | + opts, owner_repo_package, show_assessment, fixable, severity_filter |
342 | 290 | ): |
343 | 291 | """ |
344 | 292 | Retrieve vulnerability scan results for a package. |
@@ -394,7 +342,37 @@ def vulnerabilities( |
394 | 342 |
|
395 | 343 | # Repo summary mode: collect with progress bar, then output once |
396 | 344 | if repo_summary: |
397 | | - slugs = get_packages_in_repo(opts, owner, repo) |
| 345 | + try: |
| 346 | + all_packages, _ = paginate_results( |
| 347 | + list_packages, |
| 348 | + page_all=True, |
| 349 | + page=1, |
| 350 | + owner=owner, |
| 351 | + repo=repo, |
| 352 | + query=None, |
| 353 | + sort=None, |
| 354 | + ) |
| 355 | + except Exception as exc: |
| 356 | + raise click.ClickException( |
| 357 | + f"Failed to list packages for '{owner}/{repo}'. " |
| 358 | + f"Please check the owner and repository names are correct. " |
| 359 | + f"Detail: {exc}" |
| 360 | + ) from exc |
| 361 | + |
| 362 | + if not all_packages: |
| 363 | + raise click.ClickException( |
| 364 | + f"No packages found in '{owner}/{repo}'. " |
| 365 | + f"The repository may be empty, or the owner/repo names may be incorrect." |
| 366 | + ) |
| 367 | + |
| 368 | + slugs = [ |
| 369 | + ( |
| 370 | + pkg["slug_perm"], |
| 371 | + pkg.get("name", pkg["slug_perm"]), |
| 372 | + pkg.get("version", ""), |
| 373 | + ) |
| 374 | + for pkg in all_packages |
| 375 | + ] |
398 | 376 |
|
399 | 377 | repo_summary_rows = _collect_repo_scan_data( |
400 | 378 | opts, owner, repo, slugs, severity_filter, fixable |
|
0 commit comments