Skip to content

Commit

Permalink
Refractor: packages.py, delete-package-with-tag.py, test_packages.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielschowe committed Sep 23, 2024
1 parent 6f9d667 commit 77a1143
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pontos/github/api/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ async def package_versions(
if versions:
for version in versions:
yield PackageVersion.from_dict(version)

async def package_version_tags(
self,
organization: str,
Expand Down
10 changes: 8 additions & 2 deletions pontos/github/scripts/delete-package-with-tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from pontos.github.api import GitHubAsyncRESTApi
from pontos.github.models.packages import PackageType


def package_type(value: str) -> PackageType:
if isinstance(value, PackageType):
return value
return PackageType(value.lower())


def add_script_arguments(parser: ArgumentParser) -> None:
parser.add_argument("organization", help="organization name")
parser.add_argument("package", help="package name")
Expand All @@ -23,7 +25,8 @@ def add_script_arguments(parser: ArgumentParser) -> None:
)
parser.add_argument('tag', help='The tag to be deleted.')

async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> None:

async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int:
if not await api.packages.exists(
organization=args.organization,
package_name=args.package,
Expand All @@ -41,4 +44,7 @@ async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> None:
package_type=args.package_type,
tag=args.tag,
)
print(f"Deleted tag {args.tag} from package {args.package} in organization {args.organization}")
print(
f"Deleted tag {args.tag} from package {args.package} in organization {args.organization}"
)
return 0
8 changes: 6 additions & 2 deletions tests/github/api/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ async def test_package_version(self):

async def test_package_version_tags(self):
response = create_response()
response.json.return_value = {"metadata": {"container": {"tags": ["latest", "stable"]}}}
response.json.return_value = {
"metadata": {"container": {"tags": ["latest", "stable"]}}
}

self.client.get.return_value = response

Expand Down Expand Up @@ -248,7 +250,9 @@ async def test_delete_package_with_tag(self):
)

tags_response = create_response()
tags_response.json.return_value = {"metadata": {"container": {"tags": ["latest", "stable"]}}}
tags_response.json.return_value = {
"metadata": {"container": {"tags": ["latest", "stable"]}}
}
self.client.get.return_value = tags_response

await self.api.delete_package_with_tag(
Expand Down

0 comments on commit 77a1143

Please sign in to comment.