Skip to content

Commit a20fe3e

Browse files
committed
Removed get_package_in_repo() and replaced with paginate_results() from packages list_.py.
1 parent a67f4de commit a20fe3e

1 file changed

Lines changed: 33 additions & 55 deletions

File tree

cloudsmith_cli/cli/commands/vulnerabilities.py

Lines changed: 33 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -13,62 +13,11 @@
1313
_print_vulnerabilities_summary_table,
1414
get_package_scan_result,
1515
)
16+
from ...core.pagination import paginate_results
1617
from .. import decorators, utils, validators
1718
from .main import main
1819

1920

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-
7221
def _has_scan_results(data):
7322
"""Check whether scan data contains actual scan results."""
7423
scans = getattr(data, "scans", None)
@@ -336,9 +285,8 @@ def _collect_repo_scan_data(opts, owner, repo, slugs, severity_filter, fixable):
336285
"severity_filter",
337286
help="Filter by severities (e.g., 'CRITICAL', 'HIGH', 'MEDIUM', 'LOW').",
338287
)
339-
@click.pass_context
340288
def vulnerabilities(
341-
ctx, opts, owner_repo_package, show_assessment, fixable, severity_filter
289+
opts, owner_repo_package, show_assessment, fixable, severity_filter
342290
):
343291
"""
344292
Retrieve vulnerability scan results for a package.
@@ -394,7 +342,37 @@ def vulnerabilities(
394342

395343
# Repo summary mode: collect with progress bar, then output once
396344
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+
]
398376

399377
repo_summary_rows = _collect_repo_scan_data(
400378
opts, owner, repo, slugs, severity_filter, fixable

0 commit comments

Comments
 (0)