Merge #7781: devtools: Auto-set branch to merge to in github-merge
10d3ae1
devtools: Auto-set branch to merge to in github-merge (Wladimir J. van der Laan)
This commit is contained in:
commit
55db5f07b1
1 changed files with 22 additions and 12 deletions
|
@ -47,9 +47,9 @@ def git_config_get(option, default=None):
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
return default
|
return default
|
||||||
|
|
||||||
def retrieve_pr_title(repo,pull):
|
def retrieve_pr_info(repo,pull):
|
||||||
'''
|
'''
|
||||||
Retrieve pull request title from github.
|
Retrieve pull request information from github.
|
||||||
Return None if no title can be found, or an error happens.
|
Return None if no title can be found, or an error happens.
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
|
@ -57,9 +57,9 @@ def retrieve_pr_title(repo,pull):
|
||||||
result = urlopen(req)
|
result = urlopen(req)
|
||||||
reader = codecs.getreader('utf-8')
|
reader = codecs.getreader('utf-8')
|
||||||
obj = json.load(reader(result))
|
obj = json.load(reader(result))
|
||||||
return obj['title']
|
return obj
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Warning: unable to retrieve pull title from github: %s' % e)
|
print('Warning: unable to retrieve pull information from github: %s' % e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def ask_prompt(text):
|
def ask_prompt(text):
|
||||||
|
@ -69,13 +69,13 @@ def ask_prompt(text):
|
||||||
print("",file=stderr)
|
print("",file=stderr)
|
||||||
return reply
|
return reply
|
||||||
|
|
||||||
def parse_arguments(branch):
|
def parse_arguments():
|
||||||
epilog = '''
|
epilog = '''
|
||||||
In addition, you can set the following git configuration variables:
|
In addition, you can set the following git configuration variables:
|
||||||
githubmerge.repository (mandatory),
|
githubmerge.repository (mandatory),
|
||||||
user.signingkey (mandatory),
|
user.signingkey (mandatory),
|
||||||
githubmerge.host (default: git@github.com),
|
githubmerge.host (default: git@github.com),
|
||||||
githubmerge.branch (default: master),
|
githubmerge.branch (no default),
|
||||||
githubmerge.testcmd (default: none).
|
githubmerge.testcmd (default: none).
|
||||||
'''
|
'''
|
||||||
parser = argparse.ArgumentParser(description='Utility to merge, sign and push github pull requests',
|
parser = argparse.ArgumentParser(description='Utility to merge, sign and push github pull requests',
|
||||||
|
@ -83,14 +83,14 @@ def parse_arguments(branch):
|
||||||
parser.add_argument('pull', metavar='PULL', type=int, nargs=1,
|
parser.add_argument('pull', metavar='PULL', type=int, nargs=1,
|
||||||
help='Pull request ID to merge')
|
help='Pull request ID to merge')
|
||||||
parser.add_argument('branch', metavar='BRANCH', type=str, nargs='?',
|
parser.add_argument('branch', metavar='BRANCH', type=str, nargs='?',
|
||||||
default=branch, help='Branch to merge against (default: '+branch+')')
|
default=None, help='Branch to merge against (default: githubmerge.branch setting, or base branch for pull, or \'master\')')
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Extract settings from git repo
|
# Extract settings from git repo
|
||||||
repo = git_config_get('githubmerge.repository')
|
repo = git_config_get('githubmerge.repository')
|
||||||
host = git_config_get('githubmerge.host','git@github.com')
|
host = git_config_get('githubmerge.host','git@github.com')
|
||||||
branch = git_config_get('githubmerge.branch','master')
|
opt_branch = git_config_get('githubmerge.branch',None)
|
||||||
testcmd = git_config_get('githubmerge.testcmd')
|
testcmd = git_config_get('githubmerge.testcmd')
|
||||||
signingkey = git_config_get('user.signingkey')
|
signingkey = git_config_get('user.signingkey')
|
||||||
if repo is None:
|
if repo is None:
|
||||||
|
@ -105,9 +105,20 @@ def main():
|
||||||
host_repo = host+":"+repo # shortcut for push/pull target
|
host_repo = host+":"+repo # shortcut for push/pull target
|
||||||
|
|
||||||
# Extract settings from command line
|
# Extract settings from command line
|
||||||
args = parse_arguments(branch)
|
args = parse_arguments()
|
||||||
pull = str(args.pull[0])
|
pull = str(args.pull[0])
|
||||||
branch = args.branch
|
|
||||||
|
# Receive pull information from github
|
||||||
|
info = retrieve_pr_info(repo,pull)
|
||||||
|
if info is None:
|
||||||
|
exit(1)
|
||||||
|
title = info['title']
|
||||||
|
# precedence order for destination branch argument:
|
||||||
|
# - command line argument
|
||||||
|
# - githubmerge.branch setting
|
||||||
|
# - base branch for pull (as retrieved from github)
|
||||||
|
# - 'master'
|
||||||
|
branch = args.branch or opt_branch or info['base']['ref'] or 'master'
|
||||||
|
|
||||||
# Initialize source branches
|
# Initialize source branches
|
||||||
head_branch = 'pull/'+pull+'/head'
|
head_branch = 'pull/'+pull+'/head'
|
||||||
|
@ -147,7 +158,6 @@ def main():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Create unsigned merge commit.
|
# Create unsigned merge commit.
|
||||||
title = retrieve_pr_title(repo,pull)
|
|
||||||
if title:
|
if title:
|
||||||
firstline = 'Merge #%s: %s' % (pull,title)
|
firstline = 'Merge #%s: %s' % (pull,title)
|
||||||
else:
|
else:
|
||||||
|
@ -165,7 +175,7 @@ def main():
|
||||||
print("ERROR: Creating merge failed (already merged?).",file=stderr)
|
print("ERROR: Creating merge failed (already merged?).",file=stderr)
|
||||||
exit(4)
|
exit(4)
|
||||||
|
|
||||||
print('%s#%s%s %s' % (ATTR_RESET+ATTR_PR,pull,ATTR_RESET,title))
|
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])
|
||||||
print()
|
print()
|
||||||
# Run test command if configured.
|
# Run test command if configured.
|
||||||
|
|
Loading…
Reference in a new issue