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

Side by Side Diff: reviewbot/rietveld.py

Issue 20495003: Implement interface to Rietveld. (Closed) Base URL: https://src.chromium.org/chrome/trunk/tools/
Patch Set: Created 7 years, 5 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 # Copyright (c) 2013 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 from oauth2client.client import SignedJwtAssertionCredentials
6 import httplib2
7 import model.app_config
8 import urllib
9 import util
10
11
12 EMAIL_SCOPE = 'https://www.googleapis.com/auth/userinfo.email'
13
14
15 class RietveldRequestError(Exception):
16 """Raised on request errors."""
agable 2013/08/02 16:35:35 include explicit 'pass' here.
Mattias Nissler (ping if slow) 2013/08/05 09:08:51 Done.
17
18
19 class Rietveld(object):
20 def __init__(self):
21 self.app_config = model.app_config.get()
22
23 @util.lazy_property
24 def http(self):
25 http = httplib2.Http()
26
27 creds = SignedJwtAssertionCredentials(self.app_config.client_id,
28 self.app_config.service_account_key,
29 EMAIL_SCOPE)
30 creds.authorize(http)
31 return http
32
33 @util.lazy_property
34 def xsrf_token(self):
35 return self.make_request('xsrf_token',
36 headers = {'X-Requesting-XSRF-Token': 1})
37
38 def make_request(self, req, *args, **kwargs):
39 resp, response = self.http.request(
40 '%s/%s' % (self.app_config.server_url, req), *args, **kwargs)
41 if resp.status != 200:
42 raise RietveldRequestError(
43 'Rietveld %s request failed: %s\n%s' %
44 (req, resp.status, str(resp)), resp, response)
45
46 return response
47
48 def post_data(self, req, payload = None):
49 actual_payload = dict(payload or {})
50 actual_payload['xsrf_token'] = self.xsrf_token
51
52 return self.make_request(req, method = 'POST',
53 body = urllib.urlencode(actual_payload))
54
55 def post_issue_data(self, issue, req, payload):
56 return self.post_data('%s/%s' % (issue, req), payload)
57
58 def post_comment(self, issue, comment, submit_inline_comments = False):
59 publish_payload = {
60 'message_only': 0 if submit_inline_comments else 1,
61 'send_mail': 1,
62 'add_as_reviewer': 0,
63 'message': comment,
64 'no_redirect': 1,
65 }
66 self.post_issue_data(issue, 'publish', publish_payload)
67
68 def add_inline_comment(self, issue_id, patchset_id, patch_id, line, a_or_b,
agable 2013/08/02 16:35:35 How necessary is a_or_b? Though we haven't seen th
Mattias Nissler (ping if slow) 2013/08/05 09:08:51 a_or_b determines whether the comment appears on t
69 comment):
70 comment_payload = {
71 'snapshot': 'old' if a_or_b is 'a' else 'new',
72 'lineno': line,
73 'side': a_or_b,
74 'issue': issue_id,
75 'patchset': patchset_id,
76 'patch': patch_id,
77 'text': comment,
78 }
79 self.post_data('inline_draft', comment_payload)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698