diff --git a/bin/try.py b/bin/try.py index ccf9c2f096..889b58c675 100755 --- a/bin/try.py +++ b/bin/try.py @@ -16,6 +16,7 @@ import re import subprocess import sys import tempfile +import urllib2 BUCKET_SKIA_PRIMARY = 'skia/skia.primary' @@ -75,6 +76,31 @@ def main(): help='Job name or regular expression to match job names.') args = parser.parse_args() + # First, find the Gerrit issue number. If the change was uploaded using Depot + # Tools, this configuration will be present in the git config. + branch = subprocess.check_output(['git', 'branch', '--show-current']).rstrip() + if not branch: + print 'Not on any branch; cannot trigger try jobs.' + sys.exit(1) + branch_issue_config = 'branch.%s.gerritissue' % branch + try: + issue = subprocess.check_output([ + 'git', 'config', '--local', branch_issue_config]) + except subprocess.CalledProcessError: + # Not using Depot Tools. Find the Change-Id line in the most recent commit + # and obtain the issue number using that. + print '"git cl issue" not set; searching for Change-Id footer.' + msg = subprocess.check_output(['git', 'log', '-n1', branch]) + m = re.search('Change-Id: (I[a-f0-9]+)', msg) + if not m: + print ('No gerrit issue found in `git config --local %s` and no Change-Id' + ' found in most recent commit message.') + sys.exit(1) + url = 'https://skia-review.googlesource.com/changes/%s' % m.groups()[0] + resp = urllib2.urlopen(url).read() + issue = str(json.loads('\n'.join(resp.splitlines()[1:]))['_number']) + print 'Setting "git cl issue %s"' % issue + subprocess.check_call(['git', 'cl', 'issue', issue]) # Load and filter the list of jobs. jobs = [] tasks_json = os.path.join(find_repo_root(), TASKS_JSON)