From 914ad805709bc409348784bbbbc5060131dfefe3 Mon Sep 17 00:00:00 2001 From: Aric Gardner Date: Tue, 10 Dec 2019 12:16:10 -0500 Subject: [PATCH] Github cli project specific tokens Github cli commands should first search for a [github.organization] section. Then fall back to a [github] section ISSUE-ID: RELENG-2574 Signed-off-by: Aric Gardner Change-Id: I23957b43c50b4f6fda3483eec956f04afe9509e8 --- docs/commands/github.rst | 2 +- lftools/cli/github_cli.py | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/docs/commands/github.rst b/docs/commands/github.rst index ece4d517..6ff67bae 100644 --- a/docs/commands/github.rst +++ b/docs/commands/github.rst @@ -53,6 +53,6 @@ API requires a [github] or [github.OrgName] section in ~/.config/lftools/lftools .. code-block:: bash - [github] or [github.org] + [github] or [github.orgName] token = REDACTED diff --git a/lftools/cli/github_cli.py b/lftools/cli/github_cli.py index 70a00874..0b9e7b7f 100644 --- a/lftools/cli/github_cli.py +++ b/lftools/cli/github_cli.py @@ -37,7 +37,11 @@ def github_cli(ctx): @click.pass_context def submit_pr(ctx, organization, repo, pr): """Submit a pr if mergeable.""" - token = config.get_setting("github", "token") + if config.get_setting("github." + organization, "token"): + token = config.get_setting("github." + organization, "token") + else: + token = config.get_setting("github", "token") + g = Github(token) orgName = organization try: @@ -104,7 +108,11 @@ def createrepo(ctx, organization, repository, description, has_issues, has_proje By default has_issues has_wiki and has_projects is set to false. See --help to create a repo with these enabled. """ - token = config.get_setting("github", "token") + if config.get_setting("github." + organization, "token"): + token = config.get_setting("github." + organization, "token") + else: + token = config.get_setting("github", "token") + g = Github(token) orgName = organization has_issues = has_issues or False @@ -155,7 +163,10 @@ def updaterepo(ctx, organization, repository, has_issues, has_projects, has_wiki By default has_issues has_wiki and has_projects is set to false. See --help to use this command to enable these options. """ - token = config.get_setting("github", "token") + if config.get_setting("github." + organization, "token"): + token = config.get_setting("github." + organization, "token") + else: + token = config.get_setting("github", "token") g = Github(token) orgName = organization @@ -212,7 +223,11 @@ def createteam(ctx, organization, name, repo, privacy): Privacy should be set to closed This allows us to control group membership. """ - token = config.get_setting("github", "token") + if config.get_setting("github." + organization, "token"): + token = config.get_setting("github." + organization, "token") + else: + token = config.get_setting("github", "token") + g = Github(token) orgName = organization print("Creating team {} for repo {} under organization {} ".format(name, repo, orgName)) -- 2.16.6