Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Utility functions to communicate with Rietveld.""" | 5 """Utility functions to communicate with Rietveld.""" |
| 6 | 6 |
| 7 import collections | 7 import collections |
| 8 import json | 8 import json |
| 9 import logging | 9 import logging |
| 10 import urllib2 | 10 import urllib2 |
| 11 | 11 import subprocess |
| 12 | 12 |
| 13 _log = logging.getLogger(__name__) | 13 _log = logging.getLogger(__name__) |
| 14 | 14 |
| 15 BASE_CODEREVIEW_URL = 'https://codereview.chromium.org/api' | 15 BASE_CODEREVIEW_URL = 'https://codereview.chromium.org/api' |
| 16 | 16 |
| 17 TryJob = collections.namedtuple('TryJob', ('builder_name', 'build_number')) | 17 TryJob = collections.namedtuple('TryJob', ('builder_name', 'build_number')) |
| 18 | 18 |
| 19 def latest_try_jobs(issue_number, builder_names, web, patchset_number=None): | 19 def latest_try_jobs(issue_number, builder_names, web, patchset_number=None): |
| 20 """Returns a list of TryJob objects for jobs on the latest patchset. | 20 """Returns a list of TryJob objects for jobs on the latest patchset. |
| 21 | 21 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 _log.error('Request failed to URL: %s' % url) | 66 _log.error('Request failed to URL: %s' % url) |
| 67 raise | 67 raise |
| 68 try: | 68 try: |
| 69 return json.loads(contents) | 69 return json.loads(contents) |
| 70 except ValueError: | 70 except ValueError: |
| 71 _log.error('Invalid JSON: %s' % contents) | 71 _log.error('Invalid JSON: %s' % contents) |
| 72 raise | 72 raise |
| 73 | 73 |
| 74 | 74 |
| 75 def _issue_url(issue_number): | 75 def _issue_url(issue_number): |
| 76 return '%s/%s' % (BASE_CODEREVIEW_URL, issue_number) | 76 if issue_number == 'None': |
| 77 | 77 raise Exception('No issue number associated with this branch') |
| 78 else: | |
|
Dirk Pranke
2016/07/06 21:22:37
I would enforce that the issue_number is legit as
| |
| 79 return '%s/%s' % (BASE_CODEREVIEW_URL, issue_number) | |
| 78 | 80 |
| 79 def _patchset_url(issue_number, patchset_number): | 81 def _patchset_url(issue_number, patchset_number): |
| 80 return '%s/%s' % (_issue_url(issue_number), patchset_number) | 82 return '%s/%s' % (_issue_url(issue_number), patchset_number) |
| 81 | 83 |
| 82 | 84 |
| 83 def get_latest_try_job_results(issue_number, web): | 85 def get_latest_try_job_results(issue_number, web): |
| 84 url = _latest_patchset_url(issue_number, web) | 86 url = _latest_patchset_url(issue_number, web) |
| 85 patchset_data = _get_json(url, web) | 87 patchset_data = _get_json(url, web) |
| 86 results = {} | 88 results = {} |
| 87 for job in patchset_data['try_job_results']: | 89 for job in patchset_data['try_job_results']: |
| 88 results[job['builder']] = job['result'] | 90 results[job['builder']] = job['result'] |
| 89 return results | 91 return results |
| 92 | |
| 93 | |
| 94 def get_cl_issue_number(): | |
|
Dirk Pranke
2016/07/06 21:22:37
This method doesn't belong on this object, since y
qyearsley
2016/07/06 21:38:56
1. In other places in webkitpy, an Executive objec
dcampb
2016/07/06 22:13:06
per dpranke@ comment, I moved the function to the
Dirk Pranke
2016/07/06 22:33:29
Actually mocking all of that stuff up in scm_unitt
| |
| 95 issue_number = subprocess.check_output('git cl issue | cut -d" " -f3', shell =True) | |
|
qyearsley
2016/07/06 21:38:56
As I think you mentioned, this command using `cut`
| |
| 96 issue_number = issue_number[:-1] | |
| 97 return issue_number | |
| OLD | NEW |