From 89a9fca1069583eadba27daeff78c877164f5481 Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Mon, 5 Feb 2018 10:09:00 +0100 Subject: [PATCH] Enhance github debugging script for apps One might want to use the github debugging script with GitHub apps. Add that as a possibility. This also piggybacks a small fix where we called getGithubClient with the wrong data type. Change-Id: I8db77eb5d4d86aa4d6cc3acf3b4e70ef46f9e11d --- tools/github-debugging.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/github-debugging.py b/tools/github-debugging.py index 101fd11180..da6fd0c664 100755 --- a/tools/github-debugging.py +++ b/tools/github-debugging.py @@ -11,6 +11,8 @@ from zuul.model import Change, Project # TODO: for real use override the following variables server = 'github.com' api_token = 'xxxx' +appid = 2 +appkey = '/opt/project/appkey' org = 'example' repo = 'sandbox' @@ -42,20 +44,36 @@ def create_connection(server, api_token): return conn +def create_connection_app(server, appid, appkey): + driver = GithubDriver() + connection_config = { + 'server': server, + 'app_id': appid, + 'app_key': appkey, + } + conn = GithubConnection(driver, 'github', connection_config) + conn._authenticateGithubAPI() + conn._prime_installation_map() + return conn + + def get_change(connection: GithubConnection, org: str, repo: str, pull: int) -> Change: p = Project("%s/%s" % (org, repo), connection.source) - github = connection.getGithubClient(p) + github = connection.getGithubClient(p.name) pr = github.pull_request(org, repo, pull) sha = pr.head.sha return conn._getChange(p, pull, sha, True) -# create github connection +# create github connection with api token conn = create_connection(server, api_token) +# create github connection with app key +# conn = create_connection_app(server, appid, appkey) + # Now we can do anything we want with the connection, e.g. check canMerge for # a pull request.