Skip to content

Commit 848ec56

Browse files
committed
Merge #15643: contrib: gh-merge: Include ACKs in merge commit
fa1c073 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
2 parents 2084060 + fa1c073 commit 848ec56

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

contrib/devtools/github-merge.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ def git_config_get(option, default=None):
4747
except subprocess.CalledProcessError:
4848
return default
4949

50-
def retrieve_pr_info(repo,pull,ghtoken):
50+
def retrieve_json(req, ghtoken):
5151
'''
52-
Retrieve pull request information from github.
53-
Return None if no title can be found, or an error happens.
52+
Retrieve json from github.
53+
Return None if an error happens.
5454
'''
5555
try:
56-
req = Request("https://api.github.com/repos/"+repo+"/pulls/"+pull)
5756
if ghtoken is not None:
5857
req.add_header('Authorization', 'token ' + ghtoken)
5958
result = urlopen(req)
@@ -69,6 +68,18 @@ def retrieve_pr_info(repo,pull,ghtoken):
6968
print('Warning: unable to retrieve pull information from github: %s' % e)
7069
return None
7170

71+
def retrieve_pr_info(repo,pull,ghtoken):
72+
req = Request("https://api.github.com/repos/"+repo+"/pulls/"+pull)
73+
return retrieve_json(req,ghtoken)
74+
75+
def retrieve_pr_comments(repo,pull,ghtoken):
76+
req = Request("https://api.github.com/repos/"+repo+"/issues/"+pull+"/comments")
77+
return retrieve_json(req,ghtoken)
78+
79+
def retrieve_pr_reviews(repo,pull,ghtoken):
80+
req = Request("https://api.github.com/repos/"+repo+"/pulls/"+pull+"/reviews")
81+
return retrieve_json(req,ghtoken)
82+
7283
def ask_prompt(text):
7384
print(text,end=" ",file=stderr)
7485
stderr.flush()
@@ -133,6 +144,16 @@ def tree_sha512sum(commit='HEAD'):
133144
raise IOError('Non-zero return value executing git cat-file')
134145
return overall.hexdigest()
135146

147+
def get_acks_from_comments(head_commit, comments):
148+
assert len(head_commit) == 6
149+
ack_str ='\n\nACKs for commit {}:\n'.format(head_commit)
150+
for c in comments:
151+
review = [l for l in c['body'].split('\r\n') if 'ACK' in l and head_commit in l]
152+
if review:
153+
ack_str += ' {}:\n'.format(c['user']['login'])
154+
ack_str += ' {}\n'.format(review[0])
155+
return ack_str
156+
136157
def print_merge_details(pull, title, branch, base_branch, head_branch):
137158
print('%s#%s%s %s %sinto %s%s' % (ATTR_RESET+ATTR_PR,pull,ATTR_RESET,title,ATTR_RESET+ATTR_PR,branch,ATTR_RESET))
138159
subprocess.check_call([GIT,'log','--graph','--topo-order','--pretty=format:'+COMMIT_FORMAT,base_branch+'..'+head_branch])
@@ -185,6 +206,9 @@ def main():
185206
info = retrieve_pr_info(repo,pull,ghtoken)
186207
if info is None:
187208
sys.exit(1)
209+
comments = retrieve_pr_comments(repo,pull,ghtoken) + retrieve_pr_reviews(repo,pull,ghtoken)
210+
if comments is None:
211+
sys.exit(1)
188212
title = info['title'].strip()
189213
body = info['body'].strip()
190214
# precedence order for destination branch argument:
@@ -238,6 +262,7 @@ def main():
238262
message = firstline + '\n\n'
239263
message += subprocess.check_output([GIT,'log','--no-merges','--topo-order','--pretty=format:%h %s (%an)',base_branch+'..'+head_branch]).decode('utf-8')
240264
message += '\n\nPull request description:\n\n ' + body.replace('\n', '\n ') + '\n'
265+
message += get_acks_from_comments(head_commit=subprocess.check_output([GIT,'log','-1','--pretty=format:%H',head_branch]).decode('utf-8')[:6], comments=comments)
241266
try:
242267
subprocess.check_call([GIT,'merge','-q','--commit','--no-edit','--no-ff','-m',message.encode('utf-8'),head_branch])
243268
except subprocess.CalledProcessError:

0 commit comments

Comments
 (0)