From 88b2a21d6902ca5f97091af15cca9106f69d377c Mon Sep 17 00:00:00 2001 From: Jaspar Stach Date: Fri, 20 Sep 2024 09:57:30 +0200 Subject: [PATCH] Test package_version_delete and package_version_tags --- pontos/github/api/packages.py | 7 +++++-- pontos/github/scripts/find-package-tag.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pontos/github/api/packages.py b/pontos/github/api/packages.py index 4a00da862..5f0be6608 100644 --- a/pontos/github/api/packages.py +++ b/pontos/github/api/packages.py @@ -211,6 +211,9 @@ async def package_version_tags( """ Get information about package version tags + Uses https://docs.github.com/en/rest/reference/packages#get-a-package-version-for-an-organization + and only returns the tags + Args: organization: GitHub organization to use package_type: Type of the package to get @@ -238,12 +241,12 @@ async def package_version_tags( print(tags) """ - api = f"/orgs/{organization}/packages/{package_type}/{package_name}/versions/{version}/tags" + api = f"/orgs/{organization}/packages/{package_type}/{package_name}/versions/{version}" response = await self._client.get(api) if not response.is_success: raise GitHubApiError(response) resp = response.json() - return resp["tags"] + return resp["metadata"][package_type]["tags"] async def delete_package( self, organization: str, package_type: PackageType, package_name: str diff --git a/pontos/github/scripts/find-package-tag.py b/pontos/github/scripts/find-package-tag.py index a0eda8f23..104b5c2e0 100644 --- a/pontos/github/scripts/find-package-tag.py +++ b/pontos/github/scripts/find-package-tag.py @@ -41,17 +41,33 @@ async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int: f"Package {args.package} does not exist in organization {args.organization}" ) return 1 + print(f"Found package {args.package} in organization {args.organization}") async for package in api.packages.package_versions( organization=args.organization, package_name=args.package, package_type=args.package_type, ): + print(f"Checking package {args.package} with id {package.id}") if package.metadata.container.tags: if args.tag in package.metadata.container.tags: print( f"Package {args.package} with id {package.id} has tag {args.tag}" ) + tags = await api.packages.package_version_tags( + args.organization, + args.package_type, + args.package, + package.id, + ) + print(f"Tags: {tags}") + + await api.packages.delete_package_version( + args.organization, + args.package_type, + args.package, + package.id, + ) return 0 print(f"Package {args.package} does not have tag {args.tag}")