Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(604)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/net/rietveld.py

Issue 2069863002: Add a webkit-patch command which gets a list of relevant try jobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/common/net/rietveld_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 """Utility functions to communicate with Rietveld."""
6
7 import collections
8 import json
9 import logging
10 import urllib2
11
12
13 _log = logging.getLogger(__name__)
14
15 BASE_CODEREVIEW_URL = 'https://codereview.chromium.org/api'
16
17 TryJob = collections.namedtuple('TryJob', ('builder_name', 'master_name', 'build _number'))
18
19
20 def latest_try_jobs(issue_number, builder_names, web, patchset_number=None):
21 """Returns a list of TryJob objects for jobs on the latest patchset.
22
23 Args:
24 issue_number: A Rietveld issue number.
25 builder_names: Builders that we're interested in; try jobs for only
26 these builders will be listed.
27 web: webkitpy.common.net.web.Web object (which can be mocked out).
28 patchset_number: Use a specific patchset instead of the latest one.
29
30 Returns:
31 A list of TryJob objects; empty list if none were found.
32 """
33 try:
34 if patchset_number:
35 url = _patchset_url(issue_number, patchset_number)
36 else:
37 url = _latest_patchset_url(issue_number, web)
38 patchset_data = _get_json(url, web)
39 except (urllib2.URLError, ValueError):
40 return []
41 jobs = []
42 for job in patchset_data['try_job_results']:
43 if job['builder'] not in builder_names:
44 continue
45 jobs.append(TryJob(
46 builder_name=job['builder'],
47 master_name=job['master'],
48 build_number=job['buildnumber']))
49 return jobs
50
51
52 def _latest_patchset_url(issue_number, web):
53 issue_data = _get_json(_issue_url(issue_number), web)
54 latest_patchset_number = issue_data["patchsets"][-1]
55 return _patchset_url(issue_number, latest_patchset_number)
56
57
58 def _get_json(url, web):
59 """Fetches JSON from a URL, and logs errors if the request was unsuccessful.
60
61 Raises:
62 urllib2.URLError: Something went wrong with the request.
63 ValueError: The response wasn't valid JSON.
64 """
65 try:
66 contents = web.get_binary(url)
67 except urllib2.URLError:
68 _log.error('Request failed to URL: %s' % url)
69 raise
70 try:
71 return json.loads(contents)
72 except ValueError:
73 _log.error('Invalid JSON: %s' % contents)
74 raise
75
76
77 def _issue_url(issue_number):
78 return '%s/%s' % (BASE_CODEREVIEW_URL, issue_number)
79
80
81 def _patchset_url(issue_number, patchset_number):
82 return '%s/%s' % (_issue_url(issue_number), patchset_number)
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/common/net/rietveld_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698