Skip to content

Commit

Permalink
Avoid listing org packages where repo token doesn't have access
Browse files Browse the repository at this point in the history
  • Loading branch information
mering committed Oct 31, 2023
1 parent ad317b1 commit ad8b5cc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions clean_ghcr.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,22 @@ def get_req(path, params=None):


def get_list_packages(owner, repo_name, owner_type, package_name):
if package_name:
url = get_url(
f"/{owner_type}s/{owner}/packages/container/{package_name}")
response = requests.get(url, headers=get_base_headers())
if not response.ok:
if response.status_code != 404:
raise Exception(response.text)
return [response.json()]

all_org_pkg = get_req(
f"/{owner_type}s/{owner}/packages?package_type=container")
if repo_name:
all_org_pkg = [
pkg for pkg in all_org_pkg if pkg.get("repository")
and pkg["repository"]["name"].lower() == repo_name
]
if package_name:
all_org_pkg = [
pkg for pkg in all_org_pkg if pkg["name"] == package_name
]
return all_org_pkg


Expand Down

0 comments on commit ad8b5cc

Please sign in to comment.