From cd6af24b4452346429d12864bf1101597e0e10b4 Mon Sep 17 00:00:00 2001 From: David Morris Date: Fri, 20 Oct 2023 20:01:22 +0100 Subject: [PATCH] Adding a team name flag for #122 --- configure.py | 15 +++++++++++++-- thepower.py | 8 ++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/configure.py b/configure.py index 71958504..4fca23ec 100755 --- a/configure.py +++ b/configure.py @@ -115,8 +115,8 @@ def main(args): ### [Team](https://docs.github.com/en/rest/teams) # https://docs.github.com/en/organizations/organizing-members-into-teams/about-teams -team="Justice League" -team_slug="justice-league" +team="${team_name}" +team_slug="${team_slug}" team_id= team_members="${team_members}" team_admin="${team_admin}" @@ -365,6 +365,8 @@ def main(args): assert thepower.token_validator(args.token), "Invalid format: token should have a valid prefix, or should be 40 characters string." + if args.team_name != "": + args.team_slug = thepower.slugify(args.team_name) if args.org != "": logger.info(f"Org = {args.org}") @@ -438,6 +440,8 @@ def main(args): "admin_password": args.admin_password, "mgmt_password": args.mgmt_password, "mgmt_port": args.mgmt_port, + "team_name": args.team_name, + "team_slug": args.team_slug, "team_members": args.team_members, "team_admin": args.team_admin, "org_owner": args.org_owner, @@ -619,6 +623,13 @@ def main(args): default="list-user.sh", help="The name of a primer script which will be executed when configuration is complete", ) + parser.add_argument( + "--team-name", + action="store", + dest="team_name", + default="Justice League", + help="The name of a team to create.", + ) parser.add_argument( "--private-pem-file", action="store", diff --git a/thepower.py b/thepower.py index 047f3445..ab0f20cb 100755 --- a/thepower.py +++ b/thepower.py @@ -21,6 +21,14 @@ import re +def slugify(s): + s = s.lower().strip() + s = re.sub(r'[^\w\s-]', '', s) + s = re.sub(r'[\s_-]+', '-', s) + s = re.sub(r'^-+|-+$', '', s) + return s + + def ghe2json(text): """Converts the text output from gheboot to json""" lexer = shlex.shlex(text)