forked from shans/chromez
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redirect.py
83 lines (77 loc) · 3.48 KB
/
redirect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from apiclient.discovery import build
import logging
import webapp2
from google.appengine.api import urlfetch
from google.appengine.api import app_identity
from oauth2client.contrib.appengine import AppAssertionCredentials
from httplib2 import Http
import json
class MainPage(webapp2.RequestHandler):
Monorail_cans = {
'': 'open',
'1': 'all',
'2': 'open',
'closed': 'all',
}
for x in ['all', 'new', 'open', 'owned', 'reported', 'starred', 'to_verify']:
Monorail_cans[x] = x
def get(self):
scope = 'https://www.googleapis.com/auth/userinfo.email'
credentials = AppAssertionCredentials(scope)
http = credentials.authorize(Http())
MONORAIL_DISCOVERY_URL = (
'https://monorail-prod.appspot.com/_ah/api/discovery/v1/apis/'
'{api}/{apiVersion}/rest'
)
monorail = build(
'monorail', 'v1',
discoveryServiceUrl=MONORAIL_DISCOVERY_URL,
http=http
)
scope = "https://www.googleapis.com/auth/gerritcodereview"
auth_token, _ = app_identity.get_access_token(scope)
if self.request.get('site') == 'issues':
urlfetch.set_default_fetch_deadline(10)
startIndex = self.request.get('start')
try:
startIndex = int(startIndex)
except:
startIndex = 0
self.response.headers.add_header("Access-Control-Allow-Origin", "*")
result = monorail.issues().list(projectId='chromium', q=self.request.get('q'),
can=MainPage.Monorail_cans.get(self.request.get('can',''),'open'),
startIndex=startIndex).execute()
self.response.write(json.dumps(result))
elif self.request.get('site') == 'issue':
urlfetch.set_default_fetch_deadline(10)
self.response.headers.add_header("Access-Control-Allow-Origin", "*")
result = monorail.issues().get(projectId='chromium', issueId=self.request.get('issueId')).execute()
self.response.write(json.dumps(result))
elif self.request.get('site') == 'comments':
urlfetch.set_default_fetch_deadline(10)
startIndex = self.request.get('start')
try:
startIndex = int(startIndex)
except:
startIndex = 0
maxResults = self.request.get('max')
try:
maxResults = int(maxResults)
if (maxResults > 200):
maxResults = 200
logging.error('You can only fetch 200 comments at a time. If you need to fetch more comments than that please paginate using the startIndex.')
except:
maxResults = 0
self.response.headers.add_header("Access-Control-Allow-Origin", "*")
result = monorail.issues().comments().list(projectId='chromium', issueId=self.request.get('issueId'), maxResults=maxResults, startIndex=startIndex).execute()
self.response.write(json.dumps(result))
elif self.request.get('site') == 'gerrit':
urlfetch.set_default_fetch_deadline(10)
self.response.headers.add_header("Access-Control-Allow-Origin", "*")
result = urlfetch.fetch(url="https://chromium-review.googlesource.com/a/changes/?q="
+ self.request.get('q') + "&o=" + self.request.get('o') + "&o=DETAILED_ACCOUNTS&o=REVIEWER_UPDATES",
headers={"Authorization": "Bearer " + auth_token});
self.response.write(json.dumps(result.content[5:]));
app = webapp2.WSGIApplication([
('/.*', MainPage),
], debug=True)