From 10743bf874d8f99d5d81ea1b5ee54803f5d30941 Mon Sep 17 00:00:00 2001 From: Aric Gardner Date: Thu, 9 Jan 2020 15:37:32 -0500 Subject: [PATCH] lftools github create-team no longer requires repo repo is now optional ISSUE-ID: RELENG-2646 Signed-off-by: Aric Gardner Change-Id: I3cb31d17bb2fbe9e0ec7c419c99ad5cc2397d0f6 --- lftools/cli/github_cli.py | 60 +++++++++++++--------- .../notes/github-create-team-52614d75e690f80d.yaml | 5 ++ 2 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 releasenotes/notes/github-create-team-52614d75e690f80d.yaml diff --git a/lftools/cli/github_cli.py b/lftools/cli/github_cli.py index 0b9e7b7f..f8dbb2c4 100644 --- a/lftools/cli/github_cli.py +++ b/lftools/cli/github_cli.py @@ -214,8 +214,9 @@ def updaterepo(ctx, organization, repository, has_issues, has_projects, has_wiki @click.command(name='create-team') @click.argument('organization') @click.argument('name') -@click.argument('repo') @click.argument('privacy') +@click.option('--repo', type=str, required=False, + help='Assign team to repo') @click.pass_context def createteam(ctx, organization, name, repo, privacy): """Create a Github team within an Organization. @@ -236,39 +237,50 @@ def createteam(ctx, organization, name, repo, privacy): except GithubException as ghe: print(ghe) - try: - repos = org.get_repos - except GithubException as ghe: - print(ghe) + if repo: + try: + repos = org.get_repos + except GithubException as ghe: + print(ghe) + + my_repos = [repo] + repos = [repo for repo in repos() if repo.name in my_repos] + for repo in repos: + print(repo) + if repos: + print("repo found") + else: + print("repo not found") + sys.exit(1) try: teams = org.get_teams except GithubException as ghe: print(ghe) - my_repos = [repo] - repos = [repo for repo in repos() if repo.name in my_repos] - for repo in repos: - print(repo) - - if repos: - print("repo found") - else: - print("repo not found") - sys.exit(1) - for team in teams(): if team.name == name: print("team {} already exists".format(team)) sys.exit(1) - try: - org.create_team( - name=name, - repo_names=repos, - privacy=privacy - ) - except GithubException as ghe: - print(ghe) + + if repo: + try: + org.create_team( + name=name, + repo_names=repos, + privacy=privacy + ) + except GithubException as ghe: + print(ghe) + + if not repo: + try: + org.create_team( + name=name, + privacy=privacy + ) + except GithubException as ghe: + print(ghe) @click.command(name='user') diff --git a/releasenotes/notes/github-create-team-52614d75e690f80d.yaml b/releasenotes/notes/github-create-team-52614d75e690f80d.yaml new file mode 100644 index 00000000..2abb1512 --- /dev/null +++ b/releasenotes/notes/github-create-team-52614d75e690f80d.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + lftools github create-team no longer requires repo + it is now an option -- 2.16.6