-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: Test script to get the ID of a package with a specific tag.
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |