Last active
December 31, 2015 20:59
-
-
Save markllama/8043735 to your computer and use it in GitHub Desktop.
Pull and report some information on a specific PR from the openshift origin-server repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# Protocol defined in: | |
# http://developer.github.com/v3/ | |
# | |
import sys, os | |
import requests | |
github_url_root = "https://api.github.com/" | |
username = '<yourgitusername>' | |
password = '<yourgitpassword>' | |
def print_pr(pr_number): | |
query_url = 'https://api.github.com/repos/openshift/origin-server/pulls/' | |
# get a single PR report | |
r = requests.get(query_url + pr_number, auth=(username, password)) | |
if r.status_code == 200: | |
response = r.json() | |
if len(response) == 0: | |
print "no matching pull requests" | |
else: | |
print "=" * 78 | |
print "- PR number: %s, Username: %s" % (response['number'], response['use | |
r']['login']) | |
body_string = response['body'] | |
if body_string != None: | |
body_array = body_string.split("\n") | |
for line in body_array: | |
try: | |
print unicode("> " + line) | |
except UnicodeEncodeError: | |
print "> LINE MISSING UNICODE" | |
c = requests.get(response['comments_url'], auth=(username,password)) | |
for comment in c.json(): | |
try: | |
print " + %2s) %s: %s" % (comment['id'], comment['user']['login'], com | |
ment['body']) | |
if 'position' in comment: | |
print " + position: %d" % comment['position'] | |
except UnicodeEncodeError: | |
print " + LINE MISSING: UNICODE" | |
#print 'comments_url = %s' % response['comments_url'] | |
print "\n" | |
else: | |
print r | |
print "Status code = %s" % r.status_code | |
print r.headers | |
if __name__ == "__main__": | |
pr_file = sys.argv[1] | |
if os.path.exists(pr_file): | |
for line in file(pr_file): | |
pr_number = line.split()[0] | |
print_pr(pr_number) | |
else: | |
print_pr(pr_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment