Skip to content

Commit

Permalink
Merge 2d4f70c into merged_master (Bitcoin PR #15838)
Browse files Browse the repository at this point in the history
  • Loading branch information
apoelstra committed Oct 28, 2020
2 parents e901c26 + 2d4f70c commit 1b0aded
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions contrib/devtools/github-merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,36 @@ def git_config_get(option, default=None):
except subprocess.CalledProcessError:
return default

def retrieve_json(req, ghtoken):
def get_response(req_url, ghtoken):
req = Request(req_url)
if ghtoken is not None:
req.add_header('Authorization', 'token ' + ghtoken)
return urlopen(req)

def retrieve_json(req_url, ghtoken, use_pagination=False):
'''
Retrieve json from github.
Return None if an error happens.
'''
try:
if ghtoken is not None:
req.add_header('Authorization', 'token ' + ghtoken)
result = urlopen(req)
reader = codecs.getreader('utf-8')
obj = json.load(reader(result))
if not use_pagination:
return json.load(reader(get_response(req_url, ghtoken)))

obj = []
page_num = 1
while True:
req_url_page = '{}?page={}'.format(req_url, page_num)
result = get_response(req_url_page, ghtoken)
obj.extend(json.load(reader(result)))

link = result.headers.get('link', None)
if link is not None:
link_next = [l for l in link.split(',') if 'rel="next"' in l]
if len(link_next) > 0:
page_num = int(link_next[0][link_next[0].find("page=")+5:link_next[0].find(">")])
continue
break
return obj
except HTTPError as e:
error_message = e.read()
Expand All @@ -69,16 +88,16 @@ def retrieve_json(req, ghtoken):
return None

def retrieve_pr_info(repo,pull,ghtoken):
req = Request("https://api.github.com/repos/"+repo+"/pulls/"+pull)
return retrieve_json(req,ghtoken)
req_url = "https://api.github.com/repos/"+repo+"/pulls/"+pull
return retrieve_json(req_url,ghtoken)

def retrieve_pr_comments(repo,pull,ghtoken):
req = Request("https://api.github.com/repos/"+repo+"/issues/"+pull+"/comments")
return retrieve_json(req,ghtoken)
req_url = "https://api.github.com/repos/"+repo+"/issues/"+pull+"/comments"
return retrieve_json(req_url,ghtoken,use_pagination=True)

def retrieve_pr_reviews(repo,pull,ghtoken):
req = Request("https://api.github.com/repos/"+repo+"/pulls/"+pull+"/reviews")
return retrieve_json(req,ghtoken)
req_url = "https://api.github.com/repos/"+repo+"/pulls/"+pull+"/reviews"
return retrieve_json(req_url,ghtoken,use_pagination=True)

def ask_prompt(text):
print(text,end=" ",file=stderr)
Expand Down

0 comments on commit 1b0aded

Please sign in to comment.