From: Aric Gardner Date: Tue, 10 Dec 2019 17:16:10 +0000 (-0500) Subject: Github cli project specific tokens X-Git-Tag: v0.29.1~3 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F86%2F62586%2F1;p=releng%2Flftools.git 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 --- 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))