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 Aug 22, 2023
1 parent ad317b1 commit e3b8a29
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions clean_ghcr.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,24 @@ 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(), params=params)
result = []
if not response.ok:
if response.status_code != 404:
raise Exception(response.text)
result.extend(response.json())
return result

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 e3b8a29

Please sign in to comment.