Commit b0e621f3 authored by chase@chromium.org's avatar chase@chromium.org

git-try: Use trychange library for HTTP submits.

Make git-try use trychange for both SVN and HTTP try
server submits.  Simplifies git-try and reduces chance
of differences in behavior between SVN and HTTP try
job submits.

Exit early if the checkout's configured email address
does not pass validation.

Simplify trychange import.

BUG=none
TEST=git-try submits a job to the try server
Review URL: http://codereview.chromium.org/173394

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@24315 0039d316-1c4b-4281-b951-d872f2087c98
parent d59982a1
......@@ -8,6 +8,8 @@ import tempfile
import traceback
import urllib
import sys
import re
import trychange
def Backquote(cmd):
......@@ -93,54 +95,24 @@ def GetMungedDiff(branch):
return munged_diff
def ValidEmail(email):
return re.match(r"^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", email)
def GetEmail():
# TODO: check for errors here?
return Backquote(['git', 'config', 'user.email'])
email = Backquote(['git', 'config', 'user.email'])
runmsg = "Try: git config user.email <EMAIL>"
assert ValidEmail(email), "Email '%s' is not valid. %s" % (email, runmsg)
return email
def TryChange(args):
"""Put a patch on the try server using SVN."""
"""Put a patch on the try server."""
root_dir = Backquote(['git', 'rev-parse', '--show-cdup'])
script_path = os.path.dirname(sys.argv[0])
sys.path.append(script_path)
try:
import trychange
except ImportError, e:
print "Error trying to import trychange from", script_path
print "git-try expects to live at depot_tools/git-try"
raise e
trychange.checkout_root = os.path.abspath(root_dir)
trychange.TryChange(args, None, False)
def WriteTryDiffHTTP(config, patch_name, diff, options):
"""Put a patch on the try server."""
params = {
'user': getpass.getuser(),
'name': patch_name,
'patch': diff
}
if GetRietveldPatchsetNumber():
params['issue'] = GetRietveldIssueNumber()
params['patchset'] = GetRietveldPatchsetNumber()
if options.bot:
params['bot'] = options.bot
if options.clobber:
params['clobber'] = 'true'
url = 'http://%s:%s/send_try_patch' % (config['try_server_http_host'],
config['try_server_http_port'])
connection = urllib.urlopen(url, urllib.urlencode(params))
response = connection.read()
if (response != 'OK'):
print "Error posting to", url
print response
assert False
if __name__ == '__main__':
parser = optparse.OptionParser(
usage='git try [options] [branch]',
......@@ -161,44 +133,53 @@ if __name__ == '__main__':
patch_name = GetPatchName()
diff = GetMungedDiff(branch)
# Send directly to try server if we can parse the config, otherwise
# Write the diff out to a temporary file
diff_file = tempfile.NamedTemporaryFile()
diff_file.write(diff)
diff_file.flush()
email = GetEmail()
user = email.partition('@')[0]
args = [
'-u', user,
'-e', email,
'-n', patch_name,
'--diff', diff_file.name,
]
# Send to try server via HTTP if we can parse the config, otherwise
# upload via SVN.
config = GetTryServerConfig()
if config is not None:
print "Sending %s using HTTP..." % patch_name
WriteTryDiffHTTP(config=config, patch_name=patch_name, diff=diff,
options=options)
sendmsg = "Sending %s using HTTP..." % patch_name
args.extend(['--use_http'])
if config['try_server_http_host'] is not None:
args.extend(['--host', config['try_server_http_host']])
if config['try_server_http_port'] is not None:
args.extend(['--port', config['try_server_http_port']])
else:
print "Could not get server config -- if you're within Google, "
print "do you have have src-internal checked out?"
print "Sending %s using SVN..." % patch_name
# Write the diff out to a temporary file
diff_file = tempfile.NamedTemporaryFile()
diff_file.write(diff)
diff_file.flush()
email = GetEmail()
user = email.partition('@')[0]
args = [
'--use_svn',
'--svn_repo', 'svn://svn.chromium.org/chrome-try/try',
'-u', user,
'-e', email,
'-n', patch_name,
'--diff', diff_file.name,
]
if options.bot:
args.extend(['--bot', options.bot])
if options.clobber:
args.append('--clobber')
if options.revision:
args.extend(['-r', options.revision])
else:
args.extend(['-r', GetRevision()])
if GetRietveldPatchsetNumber():
args.extend([
'--issue', GetRietveldIssueNumber(),
'--patchset', GetRietveldPatchsetNumber(),
])
TryChange(args=args)
sendmsg = "Sending %s using SVN..." % patch_name
args.extend([
'--use_svn', '--svn_repo',
'svn://svn.chromium.org/chrome-try/try',
])
if options.bot:
args.extend(['--bot', options.bot])
if options.clobber:
args.append('--clobber')
if options.revision:
args.extend(['-r', options.revision])
else:
args.extend(['-r', GetRevision()])
if GetRietveldPatchsetNumber():
args.extend([
'--issue', GetRietveldIssueNumber(),
'--patchset', GetRietveldPatchsetNumber(),
])
print sendmsg
TryChange(args=args)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment