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

Side by Side Diff: rietveld.py

Issue 11348122: Add presubmit check to verify issue is not closed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: changed CheckOwners to be backwards compitable. More changes to rietveld.py Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 """Defines class Rietveld to easily access a rietveld instance. 5 """Defines class Rietveld to easily access a rietveld instance.
6 6
7 Security implications: 7 Security implications:
8 8
9 The following hypothesis are made: 9 The following hypothesis are made:
10 - Rietveld enforces: 10 - Rietveld enforces:
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 def get_pending_issues(self): 71 def get_pending_issues(self):
72 """Returns an array of dict of all the pending issues on the server.""" 72 """Returns an array of dict of all the pending issues on the server."""
73 # TODO: Convert this to use Rietveld::search(), defined below. 73 # TODO: Convert this to use Rietveld::search(), defined below.
74 return json.loads( 74 return json.loads(
75 self.get('/search?format=json&commit=2&closed=3&' 75 self.get('/search?format=json&commit=2&closed=3&'
76 'keys_only=True&limit=1000&order=__key__'))['results'] 76 'keys_only=True&limit=1000&order=__key__'))['results']
77 77
78 def close_issue(self, issue): 78 def close_issue(self, issue):
79 """Closes the Rietveld issue for this changelist.""" 79 """Closes the Rietveld issue for this changelist."""
80 logging.info('closing issue %d' % issue) 80 logging.info('closing issue %s' % issue)
M-A Ruel 2012/11/28 02:43:49 Please don't change these and revert everything in
Isaac (away) 2012/11/28 22:28:17 OK... I thought you asked for that earlier when y
81 self.post("/%d/close" % issue, [('xsrf_token', self.xsrf_token())]) 81 self.post("/%s/close" % issue, [('xsrf_token', self.xsrf_token())])
82 82
83 def get_description(self, issue): 83 def get_description(self, issue):
84 """Returns the issue's description.""" 84 """Returns the issue's description."""
85 return self.get('/%d/description' % issue) 85 return self.get('/%s/description' % issue)
86 86
87 def get_issue_properties(self, issue, messages): 87 def get_issue_properties(self, issue, messages):
88 """Returns all the issue's metadata as a dictionary.""" 88 """Returns all the issue's metadata as a dictionary."""
89 url = '/api/%d' % issue 89 url = '/api/%s' % issue
90 if messages: 90 if messages:
91 url += '?messages=true' 91 url += '?messages=true'
92 return json.loads(self.get(url)) 92 return json.loads(self.get(url))
93 93
94 def get_patchset_properties(self, issue, patchset): 94 def get_patchset_properties(self, issue, patchset):
95 """Returns the patchset properties.""" 95 """Returns the patchset properties."""
96 url = '/api/%d/%d' % (issue, patchset) 96 url = '/api/%s/%s' % (issue, patchset)
97 return json.loads(self.get(url)) 97 return json.loads(self.get(url))
98 98
99 def get_file_content(self, issue, patchset, item): 99 def get_file_content(self, issue, patchset, item):
100 """Returns the content of a new file. 100 """Returns the content of a new file.
101 101
102 Throws HTTP 302 exception if the file doesn't exist or is not a binary file. 102 Throws HTTP 302 exception if the file doesn't exist or is not a binary file.
103 """ 103 """
104 # content = 0 is the old file, 1 is the new file. 104 # content = 0 is the old file, 1 is the new file.
105 content = 1 105 content = 1
106 url = '/%d/binary/%d/%d/%d' % (issue, patchset, item, content) 106 url = '/%s/binary/%s/%d/%d' % (issue, patchset, item, content)
107 return self.get(url) 107 return self.get(url)
108 108
109 def get_file_diff(self, issue, patchset, item): 109 def get_file_diff(self, issue, patchset, item):
110 """Returns the diff of the file. 110 """Returns the diff of the file.
111 111
112 Returns a useless diff for binary files. 112 Returns a useless diff for binary files.
113 """ 113 """
114 url = '/download/issue%d_%d_%d.diff' % (issue, patchset, item) 114 url = '/download/issue%s_%s_%d.diff' % (issue, patchset, item)
115 return self.get(url) 115 return self.get(url)
116 116
117 def get_patch(self, issue, patchset): 117 def get_patch(self, issue, patchset):
118 """Returns a PatchSet object containing the details to apply this patch.""" 118 """Returns a PatchSet object containing the details to apply this patch."""
119 props = self.get_patchset_properties(issue, patchset) or {} 119 props = self.get_patchset_properties(issue, patchset) or {}
120 out = [] 120 out = []
121 for filename, state in props.get('files', {}).iteritems(): 121 for filename, state in props.get('files', {}).iteritems():
122 logging.debug('%s' % filename) 122 logging.debug('%s' % filename)
123 # If not status, just assume it's a 'M'. Rietveld often gets it wrong and 123 # If not status, just assume it's a 'M'. Rietveld often gets it wrong and
124 # just has status: null. Oh well. 124 # just has status: null. Oh well.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 content = rietveld_svn_props.pop(0) 228 content = rietveld_svn_props.pop(0)
229 match2 = re.match(r'^ \+ (.*)$', content) 229 match2 = re.match(r'^ \+ (.*)$', content)
230 if not match2: 230 if not match2:
231 raise patch.UnsupportedPatchFormat( 231 raise patch.UnsupportedPatchFormat(
232 filename, 'Unsupported svn property format.') 232 filename, 'Unsupported svn property format.')
233 svn_props.append((match.group(2), match2.group(1))) 233 svn_props.append((match.group(2), match2.group(1)))
234 return svn_props 234 return svn_props
235 235
236 def update_description(self, issue, description): 236 def update_description(self, issue, description):
237 """Sets the description for an issue on Rietveld.""" 237 """Sets the description for an issue on Rietveld."""
238 logging.info('new description for issue %d' % issue) 238 logging.info('new description for issue %s' % issue)
239 self.post('/%d/description' % issue, [ 239 self.post('/%s/description' % issue, [
240 ('description', description), 240 ('description', description),
241 ('xsrf_token', self.xsrf_token())]) 241 ('xsrf_token', self.xsrf_token())])
242 242
243 def add_comment(self, issue, message, add_as_reviewer=False): 243 def add_comment(self, issue, message, add_as_reviewer=False):
244 max_message = 10000 244 max_message = 10000
245 tail = '…\n(message too large)' 245 tail = '…\n(message too large)'
246 if len(message) > max_message: 246 if len(message) > max_message:
247 message = message[:max_message-len(tail)] + tail 247 message = message[:max_message-len(tail)] + tail
248 logging.info('issue %d; comment: %s' % (issue, message)) 248 logging.info('issue %s; comment: %s' % (issue, message))
249 return self.post('/%d/publish' % issue, [ 249 return self.post('/%s/publish' % issue, [
250 ('xsrf_token', self.xsrf_token()), 250 ('xsrf_token', self.xsrf_token()),
251 ('message', message), 251 ('message', message),
252 ('message_only', 'True'), 252 ('message_only', 'True'),
253 ('add_as_reviewer', str(bool(add_as_reviewer))), 253 ('add_as_reviewer', str(bool(add_as_reviewer))),
254 ('send_mail', 'True'), 254 ('send_mail', 'True'),
255 ('no_redirect', 'True')]) 255 ('no_redirect', 'True')])
256 256
257 def set_flag(self, issue, patchset, flag, value): 257 def set_flag(self, issue, patchset, flag, value):
258 return self.post('/%d/edit_flags' % issue, [ 258 return self.post('/%s/edit_flags' % issue, [
259 ('last_patchset', str(patchset)), 259 ('last_patchset', str(patchset)),
260 ('xsrf_token', self.xsrf_token()), 260 ('xsrf_token', self.xsrf_token()),
261 (flag, value)]) 261 (flag, value)])
262 262
263 def search( 263 def search(
264 self, 264 self,
265 owner=None, reviewer=None, 265 owner=None, reviewer=None,
266 base=None, 266 base=None,
267 closed=None, private=None, commit=None, 267 closed=None, private=None, commit=None,
268 created_before=None, created_after=None, 268 created_before=None, created_after=None,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 Returns the keys of the new TryJobResult entites. 327 Returns the keys of the new TryJobResult entites.
328 """ 328 """
329 params = [ 329 params = [
330 ('reason', reason), 330 ('reason', reason),
331 ('clobber', 'True' if clobber else 'False'), 331 ('clobber', 'True' if clobber else 'False'),
332 ('builders', json.dumps(builders_and_tests)), 332 ('builders', json.dumps(builders_and_tests)),
333 ('xsrf_token', self.xsrf_token()), 333 ('xsrf_token', self.xsrf_token()),
334 ] 334 ]
335 if revision: 335 if revision:
336 params.append(('revision', revision)) 336 params.append(('revision', revision))
337 return self.post('/%d/try/%d' % (issue, patchset), params) 337 return self.post('/%s/try/%s' % (issue, patchset), params)
338 338
339 def get_pending_try_jobs(self, cursor=None, limit=100): 339 def get_pending_try_jobs(self, cursor=None, limit=100):
340 """Retrieves the try job requests in pending state. 340 """Retrieves the try job requests in pending state.
341 341
342 Returns a tuple of the list of try jobs and the cursor for the next request. 342 Returns a tuple of the list of try jobs and the cursor for the next request.
343 """ 343 """
344 url = '/get_pending_try_patchsets?limit=%d' % limit 344 url = '/get_pending_try_patchsets?limit=%d' % limit
345 extra = ('&cursor=' + cursor) if cursor else '' 345 extra = ('&cursor=' + cursor) if cursor else ''
346 data = json.loads(self.get(url + extra)) 346 data = json.loads(self.get(url + extra))
347 return data['jobs'], data['cursor'] 347 return data['jobs'], data['cursor']
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 if not 'Name or service not known' in e.reason: 388 if not 'Name or service not known' in e.reason:
389 # Usually internal GAE flakiness. 389 # Usually internal GAE flakiness.
390 raise 390 raise
391 # If reaching this line, loop again. Uses a small backoff. 391 # If reaching this line, loop again. Uses a small backoff.
392 time.sleep(1+maxtries*2) 392 time.sleep(1+maxtries*2)
393 finally: 393 finally:
394 upload.ErrorExit = old_error_exit 394 upload.ErrorExit = old_error_exit
395 395
396 # DEPRECATED. 396 # DEPRECATED.
397 Send = get 397 Send = get
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698