@ -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 informati on from github .
Return None if no title can be found , or an error happens .
Retrieve js on 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 \n ACKs 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 %s into %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 ( %a n) ' , base_branch + ' .. ' + head_branch ] ) . decode ( ' utf-8 ' )
message + = ' \n \n Pull 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 :