Skip to content

Commit

Permalink
Avoid listing org packages where job 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 233c7d6 commit 3202d05
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions clean_ghcr.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,23 @@ 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:
return []
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 3202d05

Please sign in to comment.