Skip to content

Commit ad8b5cc

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

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

clean_ghcr.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,22 @@ 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())
61+
if not response.ok:
62+
if response.status_code != 404:
63+
raise Exception(response.text)
64+
return [response.json()]
65+
5766
all_org_pkg = get_req(
5867
f"/{owner_type}s/{owner}/packages?package_type=container")
5968
if repo_name:
6069
all_org_pkg = [
6170
pkg for pkg in all_org_pkg if pkg.get("repository")
6271
and pkg["repository"]["name"].lower() == repo_name
6372
]
64-
if package_name:
65-
all_org_pkg = [
66-
pkg for pkg in all_org_pkg if pkg["name"] == package_name
67-
]
6873
return all_org_pkg
6974

7075

0 commit comments

Comments
 (0)