OLD | NEW |
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 """Views for Chromium port of Rietveld.""" | 15 """Views for Chromium port of Rietveld.""" |
16 | 16 |
17 import datetime | 17 import datetime |
18 import logging | 18 import logging |
| 19 import random |
19 import re | 20 import re |
20 | 21 |
21 from google.appengine.api import app_identity | 22 from google.appengine.api import app_identity |
22 from google.appengine.api import datastore_errors | 23 from google.appengine.api import datastore_errors |
23 from google.appengine.api import taskqueue | 24 from google.appengine.api import taskqueue |
24 from google.appengine.api import urlfetch | 25 from google.appengine.api import urlfetch |
25 from google.appengine.api import users | 26 from google.appengine.api import users |
26 from google.appengine.datastore import datastore_query | 27 from google.appengine.datastore import datastore_query |
27 from google.appengine.ext import ndb | 28 from google.appengine.ext import ndb |
28 from google.appengine.runtime import DeadlineExceededError | 29 from google.appengine.runtime import DeadlineExceededError |
29 | 30 |
30 from django import forms | 31 from django import forms |
31 from django.core.urlresolvers import reverse | 32 from django.core.urlresolvers import reverse |
32 from django.http import HttpResponse, HttpResponseRedirect | 33 from django.http import HttpResponse, HttpResponseRedirect |
33 from django.http import HttpResponseBadRequest, HttpResponseForbidden | 34 from django.http import HttpResponseBadRequest, HttpResponseForbidden |
34 from django.http import HttpResponseServerError | 35 from django.http import HttpResponseServerError |
35 from django.utils import simplejson as json | 36 from django.utils import simplejson as json |
36 | 37 |
| 38 from codereview import buildbucket |
37 from codereview import decorators as deco | 39 from codereview import decorators as deco |
38 from codereview import decorators_chromium as deco_cr | 40 from codereview import decorators_chromium as deco_cr |
39 from codereview import models | 41 from codereview import models |
40 from codereview import models_chromium | 42 from codereview import models_chromium |
41 from codereview import responses | 43 from codereview import responses |
42 from codereview import views | 44 from codereview import views |
43 | 45 |
44 | 46 |
45 ### Forms ### | 47 ### Forms ### |
46 | 48 |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 if request.issue.commit and not request.issue.cq_dry_run: | 401 if request.issue.commit and not request.issue.cq_dry_run: |
400 views.notify_approvers_of_new_patchsets(request, request.issue) | 402 views.notify_approvers_of_new_patchsets(request, request.issue) |
401 | 403 |
402 if 'builders' in request.POST: | 404 if 'builders' in request.POST: |
403 new_builders = filter(None, map(unicode.strip, | 405 new_builders = filter(None, map(unicode.strip, |
404 form.cleaned_data['builders'].split(','))) | 406 form.cleaned_data['builders'].split(','))) |
405 if request.issue.private and new_builders: | 407 if request.issue.private and new_builders: |
406 return HttpResponseBadRequest( | 408 return HttpResponseBadRequest( |
407 'Cannot add trybots on private issues', content_type='text/plain') | 409 'Cannot add trybots on private issues', content_type='text/plain') |
408 | 410 |
409 def txn(): | 411 buildbucket.schedule( |
410 jobs_to_save = [] | 412 request.issue, |
411 | 413 last_patchset.key.id(), |
412 # Add any new builders. | 414 [b.split(':', 1) for b in new_builders]) |
413 for builder in new_builders: | |
414 mastername, buildername = builder.split(':', 1) | |
415 try_job = models.TryJobResult(parent=last_patchset.key, | |
416 reason='', | |
417 result=models.TryJobResult.TRYPENDING, | |
418 master=mastername, | |
419 builder=buildername, | |
420 revision='', | |
421 clobber=False) | |
422 jobs_to_save.append(try_job) | |
423 | |
424 # Commit everything. | |
425 ndb.put_multi(jobs_to_save) | |
426 ndb.transaction(txn) | |
427 | 415 |
428 return HttpResponse('OK', content_type='text/plain') | 416 return HttpResponse('OK', content_type='text/plain') |
429 | 417 |
430 | 418 |
431 @deco.login_required | 419 @deco.login_required |
432 @deco.xsrf_required | 420 @deco.xsrf_required |
433 def conversions(request): | 421 def conversions(request): |
434 """/conversions - Show and edit the list of base=>source code URL maps.""" | 422 """/conversions - Show and edit the list of base=>source code URL maps.""" |
435 rules = models_chromium.UrlMap.query().order( | 423 rules = models_chromium.UrlMap.query().order( |
436 models_chromium.UrlMap.base_url_template).fetch() | 424 models_chromium.UrlMap.base_url_template).fetch() |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 next_cursor = query_iter.cursor_after() | 778 next_cursor = query_iter.cursor_after() |
791 else: | 779 else: |
792 next_cursor = cursor | 780 next_cursor = cursor |
793 | 781 |
794 logging.info('Found %d entries, returned %d' % (total, len(jobs))) | 782 logging.info('Found %d entries, returned %d' % (total, len(jobs))) |
795 return { | 783 return { |
796 'has_more': has_more, | 784 'has_more': has_more, |
797 'cursor': next_cursor.urlsafe() if next_cursor else '', | 785 'cursor': next_cursor.urlsafe() if next_cursor else '', |
798 'jobs': jobs | 786 'jobs': jobs |
799 } | 787 } |
OLD | NEW |