Skip to content

Commit

Permalink
Add: Test script to get the ID of a package with a specific tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
y0urself committed May 17, 2024
1 parent f513774 commit c80e1d7
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions pontos/github/scripts/find-package-tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# SPDX-FileCopyrightText: 2022-2023 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

"""
This script checks wether a package has a specific tag
"""

from argparse import ArgumentParser, Namespace

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")
parser.add_argument("tag", help="tag to check")
parser.add_argument(
"--package-type",
type=package_type,
help="package type",
default=PackageType.CONTAINER,
)


async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int:
if not await api.packages.exists(
organization=args.organization,
package_name=args.package,
package_type=args.package_type,
):
print(
f"Package {args.package} does not exist in organization {args.organization}"
)
return 1

async for package in api.packages.package_versions(
organization=args.organization,
package_name=args.package,
package_type=args.package_type,
):
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}"
)
return 0

print(f"Package {args.package} does not have tag {args.tag}")
return 0

0 comments on commit c80e1d7

Please sign in to comment.