Merge #15643: contrib: gh-merge: Include ACKs in merge commit

fa1c073154 contrib: gh-merge: Include review comments in merge commit (MarcoFalke)

Pull request description:

  This includes all up-to-date ACKs in the merge commit for reference

Tree-SHA512: 32c9352d884f9ecf94940f50f2921fc9fc026083c120f54d0651a41814872e852aee8d0c4ad5bcd03292329f05d76fcb7bac11741e1dd3bf417211a186005afb
This commit is contained in:
Wladimir J. van der Laan 2019-03-27 11:54:54 +01:00
commit 848ec5603f
No known key found for this signature in database
GPG key ID: 1E4AED62986CD25D

View file

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