aboutsummaryrefslogtreecommitdiff
path: root/contrib/devtools/github-merge.py
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/devtools/github-merge.py')
-rwxr-xr-xcontrib/devtools/github-merge.py33
1 files changed, 29 insertions, 4 deletions
diff --git a/contrib/devtools/github-merge.py b/contrib/devtools/github-merge.py
index ab834b7623..41a640b464 100755
--- a/contrib/devtools/github-merge.py
+++ b/contrib/devtools/github-merge.py
@@ -47,13 +47,12 @@ def git_config_get(option, default=None):
except subprocess.CalledProcessError:
return default
-def retrieve_pr_info(repo,pull,ghtoken):
+def retrieve_json(req, ghtoken):
'''
- Retrieve pull request information from github.
- Return None if no title can be found, or an error happens.
+ Retrieve json from github.
+ Return None if an error happens.
'''
try:
- req = Request("https://api.github.com/repos/"+repo+"/pulls/"+pull)
if ghtoken is not None:
req.add_header('Authorization', 'token ' + ghtoken)
result = urlopen(req)
@@ -69,6 +68,18 @@ def retrieve_pr_info(repo,pull,ghtoken):
print('Warning: unable to retrieve pull information from github: %s' % e)
return None
+def retrieve_pr_info(repo,pull,ghtoken):
+ req = Request("https://api.github.com/repos/"+repo+"/pulls/"+pull)
+ return retrieve_json(req,ghtoken)
+
+def retrieve_pr_comments(repo,pull,ghtoken):
+ req = Request("https://api.github.com/repos/"+repo+"/issues/"+pull+"/comments")
+ return retrieve_json(req,ghtoken)
+
+def retrieve_pr_reviews(repo,pull,ghtoken):
+ req = Request("https://api.github.com/repos/"+repo+"/pulls/"+pull+"/reviews")
+ return retrieve_json(req,ghtoken)
+
def ask_prompt(text):
print(text,end=" ",file=stderr)
stderr.flush()
@@ -133,6 +144,16 @@ def tree_sha512sum(commit='HEAD'):
raise IOError('Non-zero return value executing git cat-file')
return overall.hexdigest()
+def get_acks_from_comments(head_commit, comments):
+ assert len(head_commit) == 6
+ ack_str ='\n\nACKs for commit {}:\n'.format(head_commit)
+ for c in comments:
+ review = [l for l in c['body'].split('\r\n') if 'ACK' in l and head_commit in l]
+ if review:
+ ack_str += ' {}:\n'.format(c['user']['login'])
+ ack_str += ' {}\n'.format(review[0])
+ return ack_str
+
def print_merge_details(pull, title, branch, base_branch, head_branch):
print('%s#%s%s %s %sinto %s%s' % (ATTR_RESET+ATTR_PR,pull,ATTR_RESET,title,ATTR_RESET+ATTR_PR,branch,ATTR_RESET))
subprocess.check_call([GIT,'log','--graph','--topo-order','--pretty=format:'+COMMIT_FORMAT,base_branch+'..'+head_branch])
@@ -185,6 +206,9 @@ def main():
info = retrieve_pr_info(repo,pull,ghtoken)
if info is None:
sys.exit(1)
+ comments = retrieve_pr_comments(repo,pull,ghtoken) + retrieve_pr_reviews(repo,pull,ghtoken)
+ if comments is None:
+ sys.exit(1)
title = info['title'].strip()
body = info['body'].strip()
# precedence order for destination branch argument:
@@ -238,6 +262,7 @@ def main():
message = firstline + '\n\n'
message += subprocess.check_output([GIT,'log','--no-merges','--topo-order','--pretty=format:%h %s (%an)',base_branch+'..'+head_branch]).decode('utf-8')
message += '\n\nPull request description:\n\n ' + body.replace('\n', '\n ') + '\n'
+ message += get_acks_from_comments(head_commit=subprocess.check_output([GIT,'log','-1','--pretty=format:%H',head_branch]).decode('utf-8')[:6], comments=comments)
try:
subprocess.check_call([GIT,'merge','-q','--commit','--no-edit','--no-ff','-m',message.encode('utf-8'),head_branch])
except subprocess.CalledProcessError: