Skip to content

Commit

Permalink
Avoid listing org packages where job token doesn't have access (#23)
Browse files Browse the repository at this point in the history
* Avoid listing org packages where repo token doesn't have access

* Update docs to use job token where possible

It's possible if you set permissions packages:write
and specify the image name explicitly
  • Loading branch information
mering authored Aug 21, 2023
1 parent 1e4bcb5 commit 22d89ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ delete all / untagged ghcr containers in a repository
- name: Delete all containers from package without tags
uses: Chizkiyahu/delete-untagged-ghcr-action@v2
with:
token: ${{ secrets.PAT_TOKEN }}
token: ${{ github.token }}
repository_owner: ${{ github.repository_owner }}
repository: ${{ github.repository }}
package_name: the-package-name
Expand All @@ -145,12 +145,12 @@ delete all / untagged ghcr containers in a repository
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PAT_TOKEN }}
username: ${{ github.repository_owner }}
password: ${{ github.token }}
- name: Delete all containers from package without tags
uses: Chizkiyahu/delete-untagged-ghcr-action@v2
with:
token: ${{ secrets.PAT_TOKEN }}
token: ${{ github.token }}
repository_owner: ${{ github.repository_owner }}
repository: ${{ github.repository }}
package_name: the-package-name
Expand All @@ -164,7 +164,7 @@ delete all / untagged ghcr containers in a repository
- name: Delete all containers from package
uses: Chizkiyahu/delete-untagged-ghcr-action@v2
with:
token: ${{ secrets.PAT_TOKEN }}
token: ${{ github.token }}
repository_owner: ${{ github.repository_owner }}
repository: ${{ github.repository }}
package_name: the-package-name
Expand Down
10 changes: 6 additions & 4 deletions clean_ghcr.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,19 @@ def get_req(path, params=None):


def get_list_packages(owner, repo_name, owner_type, package_name):
if package_name:
return [{
"name": package_name,
"url": f"/{owner_type}s/{owner}/packages/container/{package_name}",
}]

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 22d89ca

Please sign in to comment.