diff options
author | Tobias Henkel <tobias.henkel@bmw.de> | 2017-12-21 15:36:19 +0100 |
---|---|---|
committer | Tobias Henkel <tobias.henkel@bmw.de> | 2017-12-22 20:04:44 +0100 |
commit | ac1763d9bdf08a7131a6c523c68fb6991ce1d40c (patch) | |
tree | b32d1ef75e61cf582d0937926a82f34bef55f9f6 | |
parent | 8e78ba6124402d6d865064be7daa5d3645eeaa15 (diff) | |
download | zuul-ac1763d9bdf08a7131a6c523c68fb6991ce1d40c.tar.gz |
Enable direct use of github driver in debug tool
The github debugging tool proved to be quite useful for prototyping
new stuff using the github api. In the process I ended up copying half
of the GithubConnection into it. However for trying out new stuff it
would be great to implement and try out the features/fixes directly in
the Github driver.
And here it is! The script now starts up a standalone version of the
Github driver which can be used to query and debug isolated stuff
against Github.
Change-Id: Ifdad1e69dae009011847869d51ff24000c44adb8
-rwxr-xr-x[-rw-r--r--] | tools/github-debugging.py | 92 |
1 files changed, 54 insertions, 38 deletions
diff --git a/tools/github-debugging.py b/tools/github-debugging.py index 171627ab9..101fd1118 100644..100755 --- a/tools/github-debugging.py +++ b/tools/github-debugging.py @@ -1,55 +1,71 @@ -import github3 +#!/usr/bin/env python3 + import logging -import time + +from zuul.driver.github.githubconnection import GithubConnection +from zuul.driver.github import GithubDriver +from zuul.model import Change, Project # This is a template with boilerplate code for debugging github issues # TODO: for real use override the following variables -url = 'https://example.com' +server = 'github.com' api_token = 'xxxx' -org = 'org' -project = 'project' -pull_nr = 3 +org = 'example' +repo = 'sandbox' +pull_nr = 8 + + +def configure_logging(context): + stream_handler = logging.StreamHandler() + logger = logging.getLogger(context) + logger.addHandler(stream_handler) + logger.setLevel(logging.DEBUG) + + +# uncomment for more logging +# configure_logging('urllib3') +# configure_logging('github3') +# configure_logging('cachecontrol') + + +# This is all that's needed for getting a usable github connection +def create_connection(server, api_token): + driver = GithubDriver() + connection_config = { + 'server': server, + 'api_token': api_token, + } + conn = GithubConnection(driver, 'github', connection_config) + conn._authenticateGithubAPI() + return conn -# Send the logs to stderr as well -stream_handler = logging.StreamHandler() +def get_change(connection: GithubConnection, + org: str, + repo: str, + pull: int) -> Change: + p = Project("%s/%s" % (org, repo), connection.source) + github = connection.getGithubClient(p) + pr = github.pull_request(org, repo, pull) + sha = pr.head.sha + return conn._getChange(p, pull, sha, True) -logger_urllib3 = logging.getLogger('requests.packages.logger_urllib3') -# logger_urllib3.addHandler(stream_handler) -logger_urllib3.setLevel(logging.DEBUG) -logger = logging.getLogger('github3') -# logger.addHandler(stream_handler) -logger.setLevel(logging.DEBUG) +# create github connection +conn = create_connection(server, api_token) -github = github3.GitHubEnterprise(url) +# Now we can do anything we want with the connection, e.g. check canMerge for +# a pull request. +change = get_change(conn, org, repo, pull_nr) +print(conn.canMerge(change, {'cc/gate2'})) -# This is the currently broken cache adapter, enable or replace it to debug -# caching -# import cachecontrol -# from cachecontrol.cache import DictCache -# cache_adapter = cachecontrol.CacheControlAdapter( -# DictCache(), -# cache_etags=True) +# Or just use the github object. +# github = conn.getGithubClient() # -# github.session.mount('http://', cache_adapter) -# github.session.mount('https://', cache_adapter) - - -github.login(token=api_token) - -i = 0 -while True: - pr = github.pull_request(org, project, pull_nr) - prdict = pr.as_dict() - issue = pr.issue() - labels = list(issue.labels()) - print(labels) - i += 1 - print(i) - time.sleep(1) +# repository = github.repository(org, repo) +# print(repository.as_dict()) |