Skip to content

Commit

Permalink
Change: New try
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielschowe committed Sep 18, 2024
1 parent 252b8ef commit 97b9832
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions pontos/github/api/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,28 +115,28 @@ async def package(

async def package_versions(
self, organization: str, package_type: PackageType, package_name: str
)SyncIterator[PackageVersion]:
) -> AsyncIterator[PackageVersion]:
"""
Get information about package versions
https://docs.github.com/en/rest/reference/packages#list-package-versions-for-an-organization
Args:
organization: GitHub organization to use
package_type: Type of the package to get
package_name: Name of the package to get
Raises:
`httpx.HTTPStatusError`: If there was an error in the request
Returns:
An async iterator yielding package versions
Example:
.. code-block:: python
from pontos.github.api import GitHubAsyncRESTApi
async with GitHubAsyncRESTApi(token) as api:
async for package in api.packages.package_versions(
organization="foo",
Expand All @@ -148,9 +148,11 @@ async def package_versions(
api = f"/orgs/{organization}/packages/{package_type}/{package_name}/versions"
async for response in self._client.get_all(api):
response.raise_for_status()

for version in response.json():
yield PackageVersion.from_dict(version)

versions = response.json()
if versions:
for version in versions:
yield PackageVersion.from_dict(version)

async def package_version(
self,
Expand Down Expand Up @@ -347,8 +349,12 @@ async def delete_package_with_tag(
tag="latest",
)
"""
for package_version in self.package_versions(organization, package_type, package_name):
print(package_version)
async for package_version in self.package_versions(organization, package_type, package_name):
if tag in package_version.tags:
api = f"/orgs/{organization}/packages/{package_type}/{package_name}/versions/{package_version.id}"
response = await self._client.delete(api)
if not response.is_success:
raise GitHubApiError(response)
api = f"/orgs/{organization}/packages/{package_type}/{package_name}/versions/tags/{tag}"
response = await self._client.delete(api)
if not response.is_success:
Expand Down

0 comments on commit 97b9832

Please sign in to comment.