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

Side by Side Diff: appengine/chromium_rietveld/codereview/buildbucket.py

Issue 1058893004: Rietveld schedules builds on buildbucket (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
1 # Copyright 2008 Google Inc. 1 # Copyright 2008 Google Inc.
2 # 2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License. 4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at 5 # You may obtain a copy of the License at
6 # 6 #
7 # http://www.apache.org/licenses/LICENSE-2.0 7 # http://www.apache.org/licenses/LICENSE-2.0
8 # 8 #
9 # Unless required by applicable law or agreed to in writing, software 9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and 12 # See the License for the specific language governing permissions and
13 # limitations under the License. 13 # limitations under the License.
14 14
15 """Rietveld-BuildBucket integration module.""" 15 """Rietveld-BuildBucket integration module."""
16 16
17 import datetime 17 import datetime
18 import json 18 import json
19 import logging 19 import logging
20 import os 20 import os
21 import urllib 21 import urllib
22 22
23 from google.appengine.api import app_identity
24 from google.appengine.api import urlfetch 23 from google.appengine.api import urlfetch
25 from google.appengine.api import users 24 from google.appengine.api import users
26 from google.appengine.ext import ndb 25 from google.appengine.ext import ndb
27 26
28 from django.conf import settings
29
30 from codereview import common 27 from codereview import common
31 from codereview import models 28 from codereview import models
32 29
33 EPOCH = datetime.datetime.utcfromtimestamp(0) 30 EPOCH = datetime.datetime.utcfromtimestamp(0)
34 BUILDBUCKET_HOSTNAME = ( 31 BUILDBUCKET_HOSTNAME = (
35 'cr-buildbucket-test.appspot.com' if common.IS_DEV 32 'cr-buildbucket-test.appspot.com' if common.IS_DEV
36 else 'cr-buildbucket.appspot.com') 33 else 'cr-buildbucket.appspot.com')
37 BUILDBUCKET_API_ROOT = ( 34 BUILDBUCKET_API_ROOT = (
38 'https://%s/_ah/api/buildbucket/v1' % BUILDBUCKET_HOSTNAME) 35 'https://%s/_ah/api/buildbucket/v1' % BUILDBUCKET_HOSTNAME)
39 36
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 timestamp=timestamp, 130 timestamp=timestamp,
134 clobber=read_prop('clobber', bool), 131 clobber=read_prop('clobber', bool),
135 tests=read_prop('testfilter', list) or [], 132 tests=read_prop('testfilter', list) or [],
136 project=read_prop('project', basestring), 133 project=read_prop('project', basestring),
137 requester=requester, 134 requester=requester,
138 category=read_prop('category', basestring), 135 category=read_prop('category', basestring),
139 build_properties=json.dumps(properties, sort_keys=True), 136 build_properties=json.dumps(properties, sort_keys=True),
140 ) 137 )
141 138
142 139
143 def get_self_hostname(): 140 ################################################################################
144 """Returns hostname to use for buildset tag. 141 ## Gettings builds.
145
146 See tag conventions http://cr-buildbucket.appspot.com/#docs/conventions
147 """
148 app_id = app_identity.get_application_id()
149 return settings.PREFERRED_DOMAIN_NAMES.get(app_id)
150 142
151 143
152 def get_builds_for_patchset(issue_id, patchset_id): 144 def get_builds_for_patchset(issue_id, patchset_id):
153 """Queries BuildBucket for builds associated with the patchset. 145 """Queries BuildBucket for builds associated with the patchset.
154 146
155 Requests for max 500 builds and does not check "next_cursor". Currently if 147 Requests for max 500 builds and does not check "next_cursor". Currently if
156 more than 100 builds are requested, only 100 are returned. Presumably there 148 more than 100 builds are requested, only 100 are returned. Presumably there
157 will be no patchsets with >100 builds. 149 will be no patchsets with >100 builds.
158 150
159 Returns: 151 Returns:
160 A list of buildbucket build dicts. 152 A list of buildbucket build dicts.
161 """ 153 """
162 hostname = get_self_hostname() 154 hostname = common.get_preferred_domain_name()
163 if not hostname: 155 if not hostname:
164 logging.error( 156 logging.error(
165 'Preferred domain name for this app is not set. ' 157 'Preferred domain name for this app is not set. '
166 'See PREFERRED_DOMAIN_NAMES in settings.py') 158 'See PREFERRED_DOMAIN_NAMES in settings.py')
167 return [] 159 return []
168 160
169 buildset_tag = BUILDSET_TAG_FORMAT.format( 161 buildset_tag = BUILDSET_TAG_FORMAT.format(
170 hostname=hostname, 162 hostname=hostname,
171 issue=issue_id, 163 issue=issue_id,
172 patch=patchset_id, 164 patch=patchset_id,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 return None 237 return None
246 return value 238 return value
247 239
248 240
249 def timestamp_to_datetime(timestamp): 241 def timestamp_to_datetime(timestamp):
250 if timestamp is None: 242 if timestamp is None:
251 return None 243 return None
252 if isinstance(timestamp, basestring): 244 if isinstance(timestamp, basestring):
253 timestamp = int(timestamp) 245 timestamp = int(timestamp)
254 return EPOCH + datetime.timedelta(microseconds=timestamp) 246 return EPOCH + datetime.timedelta(microseconds=timestamp)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698