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
This commit is contained in:
Tobias Henkel 2018-02-05 10:09:00 +01:00
parent ce1bf1f34f
commit 89a9fca106
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
1 changed files with 20 additions and 2 deletions

View File

@ -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.