Skip to content

Commit e3b8a29

Browse files
committed
Avoid listing org packages where repo token doesn't have access
1 parent ad317b1 commit e3b8a29

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

clean_ghcr.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,24 @@ def get_req(path, params=None):
5454

5555

5656
def get_list_packages(owner, repo_name, owner_type, package_name):
57+
if package_name:
58+
url = get_url(
59+
f"/{owner_type}s/{owner}/packages/container/{package_name}")
60+
response = requests.get(url, headers=get_base_headers(), params=params)
61+
result = []
62+
if not response.ok:
63+
if response.status_code != 404:
64+
raise Exception(response.text)
65+
result.extend(response.json())
66+
return result
67+
5768
all_org_pkg = get_req(
5869
f"/{owner_type}s/{owner}/packages?package_type=container")
5970
if repo_name:
6071
all_org_pkg = [
6172
pkg for pkg in all_org_pkg if pkg.get("repository")
6273
and pkg["repository"]["name"].lower() == repo_name
6374
]
64-
if package_name:
65-
all_org_pkg = [
66-
pkg for pkg in all_org_pkg if pkg["name"] == package_name
67-
]
6875
return all_org_pkg
6976

7077

0 commit comments

Comments
 (0)