@@ -47,13 +47,12 @@ def git_config_get(option, default=None):
47
47
except subprocess .CalledProcessError :
48
48
return default
49
49
50
- def retrieve_pr_info ( repo , pull , ghtoken ):
50
+ def retrieve_json ( req , ghtoken ):
51
51
'''
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.
54
54
'''
55
55
try :
56
- req = Request ("https://api.github.com/repos/" + repo + "/pulls/" + pull )
57
56
if ghtoken is not None :
58
57
req .add_header ('Authorization' , 'token ' + ghtoken )
59
58
result = urlopen (req )
@@ -69,6 +68,18 @@ def retrieve_pr_info(repo,pull,ghtoken):
69
68
print ('Warning: unable to retrieve pull information from github: %s' % e )
70
69
return None
71
70
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
+
72
83
def ask_prompt (text ):
73
84
print (text ,end = " " ,file = stderr )
74
85
stderr .flush ()
@@ -133,6 +144,16 @@ def tree_sha512sum(commit='HEAD'):
133
144
raise IOError ('Non-zero return value executing git cat-file' )
134
145
return overall .hexdigest ()
135
146
147
+ def get_acks_from_comments (head_commit , comments ):
148
+ assert len (head_commit ) == 6
149
+ ack_str = '\n \n ACKs 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
+
136
157
def print_merge_details (pull , title , branch , base_branch , head_branch ):
137
158
print ('%s#%s%s %s %sinto %s%s' % (ATTR_RESET + ATTR_PR ,pull ,ATTR_RESET ,title ,ATTR_RESET + ATTR_PR ,branch ,ATTR_RESET ))
138
159
subprocess .check_call ([GIT ,'log' ,'--graph' ,'--topo-order' ,'--pretty=format:' + COMMIT_FORMAT ,base_branch + '..' + head_branch ])
@@ -185,6 +206,9 @@ def main():
185
206
info = retrieve_pr_info (repo ,pull ,ghtoken )
186
207
if info is None :
187
208
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 )
188
212
title = info ['title' ].strip ()
189
213
body = info ['body' ].strip ()
190
214
# precedence order for destination branch argument:
@@ -238,6 +262,7 @@ def main():
238
262
message = firstline + '\n \n '
239
263
message += subprocess .check_output ([GIT ,'log' ,'--no-merges' ,'--topo-order' ,'--pretty=format:%h %s (%an)' ,base_branch + '..' + head_branch ]).decode ('utf-8' )
240
264
message += '\n \n Pull 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 )
241
266
try :
242
267
subprocess .check_call ([GIT ,'merge' ,'-q' ,'--commit' ,'--no-edit' ,'--no-ff' ,'-m' ,message .encode ('utf-8' ),head_branch ])
243
268
except subprocess .CalledProcessError :
0 commit comments