Github cli project specific tokens 86/62586/1
authorAric Gardner <agardner@linuxfoundation.org>
Tue, 10 Dec 2019 17:16:10 +0000 (12:16 -0500)
committerAric Gardner <agardner@linuxfoundation.org>
Tue, 10 Dec 2019 17:22:09 +0000 (12:22 -0500)
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 <agardner@linuxfoundation.org>
Change-Id: I23957b43c50b4f6fda3483eec956f04afe9509e8

docs/commands/github.rst
lftools/cli/github_cli.py

index ece4d51..6ff67ba 100644 (file)
@@ -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
 
index 70a0087..0b9e7b7 100644 (file)
@@ -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))