contrib: gh-merge: Include review comments in merge commit
This commit is contained in:
parent
c033c4b5ce
commit
fa1c073154
1 changed files with 29 additions and 4 deletions
|
@ -47,13 +47,12 @@ def git_config_get(option, default=None):
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
return default
|
return default
|
||||||
|
|
||||||
def retrieve_pr_info(repo,pull,ghtoken):
|
def retrieve_json(req, ghtoken):
|
||||||
'''
|
'''
|
||||||
Retrieve pull request information from github.
|
Retrieve json from github.
|
||||||
Return None if no title can be found, or an error happens.
|
Return None if an error happens.
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
req = Request("https://api.github.com/repos/"+repo+"/pulls/"+pull)
|
|
||||||
if ghtoken is not None:
|
if ghtoken is not None:
|
||||||
req.add_header('Authorization', 'token ' + ghtoken)
|
req.add_header('Authorization', 'token ' + ghtoken)
|
||||||
result = urlopen(req)
|
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)
|
print('Warning: unable to retrieve pull information from github: %s' % e)
|
||||||
return None
|
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):
|
def ask_prompt(text):
|
||||||
print(text,end=" ",file=stderr)
|
print(text,end=" ",file=stderr)
|
||||||
stderr.flush()
|
stderr.flush()
|
||||||
|
@ -133,6 +144,16 @@ def tree_sha512sum(commit='HEAD'):
|
||||||
raise IOError('Non-zero return value executing git cat-file')
|
raise IOError('Non-zero return value executing git cat-file')
|
||||||
return overall.hexdigest()
|
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):
|
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))
|
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])
|
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)
|
info = retrieve_pr_info(repo,pull,ghtoken)
|
||||||
if info is None:
|
if info is None:
|
||||||
sys.exit(1)
|
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()
|
title = info['title'].strip()
|
||||||
body = info['body'].strip()
|
body = info['body'].strip()
|
||||||
# precedence order for destination branch argument:
|
# precedence order for destination branch argument:
|
||||||
|
@ -238,6 +262,7 @@ def main():
|
||||||
message = firstline + '\n\n'
|
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 += 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 += '\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:
|
try:
|
||||||
subprocess.check_call([GIT,'merge','-q','--commit','--no-edit','--no-ff','-m',message.encode('utf-8'),head_branch])
|
subprocess.check_call([GIT,'merge','-q','--commit','--no-edit','--no-ff','-m',message.encode('utf-8'),head_branch])
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
|
|
Loading…
Reference in a new issue