-
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.
- Loading branch information
1 parent
5d1b1d4
commit 27c8a23
Showing
3 changed files
with
54 additions
and
6 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
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,44 @@ | ||
""" | ||
This script delete a package from a repository, if it contains the specified 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( | ||
"--package-type", | ||
type=package_type, | ||
help="package type", | ||
default=PackageType.CONTAINER, | ||
) | ||
parser.add_argument('tag', help='The tag to be deleted.') | ||
|
||
async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> None: | ||
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 | ||
print(f"Found package {args.package} in organization {args.organization}") | ||
|
||
await api.packages.delete_package_with_tag( | ||
organization=args.organization, | ||
package_name=args.package, | ||
package_type=args.package_type, | ||
tag=args.tag, | ||
) | ||
print(f"Deleted tag {args.tag} from package {args.package} in organization {args.organization}") |
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