Skip to content

Commit

Permalink
Test package_version_delete and package_version_tags
Browse files Browse the repository at this point in the history
  • Loading branch information
y0urself authored and gabrielschowe committed Sep 24, 2024
1 parent 526a6d2 commit 88b2a21
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pontos/github/api/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions pontos/github/scripts/find-package-tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit 88b2a21

Please sign in to comment.