def edit_flags(request): """/<issue>/edit_flags - Edit issue's flags.""" last_patchset = models.PatchSet.query(ancestor=request.issue.key).order( -models.PatchSet.created).get() if not last_patchset: return HttpResponseForbidden('Can only modify flags on last patchset', content_type='text/plain') if request.issue.closed: return HttpResponseForbidden('Can not modify flags for a closed issue', content_type='text/plain') if request.method == 'GET': # TODO(maruel): Have it set per project. initial_builders = 'win_rel, mac_rel, linux_rel' form = EditFlagsForm(initial={ 'last_patchset': last_patchset.key.id(), 'commit': request.issue.commit, 'builders': initial_builders}) return responses.respond(request, 'edit_flags.html', {'issue': request.issue, 'form': form}) form = EditFlagsForm(request.POST) if not form.is_valid(): return HttpResponseBadRequest('Invalid POST arguments', content_type='text/plain') if (form.cleaned_data['last_patchset'] != last_patchset.key.id()): return HttpResponseForbidden('Can only modify flags on last patchset', content_type='text/plain') if 'commit' in request.POST: if request.issue.private and form.cleaned_data['commit'] : return HttpResponseBadRequest( 'Cannot set commit on private issues', content_type='text/plain') if not request.issue.is_cq_available and form.cleaned_data['commit']: return HttpResponseBadRequest( 'Cannot set commit on an issue that does not have a commit queue', content_type='text/plain') request.issue.commit = form.cleaned_data['commit'] request.issue.cq_dry_run = form.cleaned_data['cq_dry_run'] user_email = request.user.email().lower() if user_email == views.CQ_SERVICE_ACCOUNT: user_email = views.CQ_COMMIT_BOT_EMAIL if (request.issue.commit and # Add as reviewer if setting, not clearing. user_email != request.issue.owner.email() and user_email not in request.issue.reviewers and user_email not in request.issue.collaborator_emails()): request.issue.reviewers.append(request.user.email()) # Update the issue with the checking/unchecking of the CQ box but reduce # spam by not emailing users. action = 'checked' if request.issue.commit else 'unchecked' commit_checked_msg = 'The CQ bit was %s by %s' % (action, user_email) if request.issue.cq_dry_run: commit_checked_msg += ' to run a CQ dry run' request.issue.cq_dry_run_last_triggered_by = user_email logging.info('CQ dry run has been triggered by %s for %d/%d', user_email, request.issue.key.id(), last_patchset.key.id()) # Mail just the owner and only if the CQ bit was unchecked by someone other # than the owner or CQ itself. More details in # https://code.google.com/p/skia/issues/detail?id=3093 send_mail = (user_email != request.issue.owner.email() and user_email != views.CQ_COMMIT_BOT_EMAIL and not request.issue.commit) views.make_message(request, request.issue, commit_checked_msg, send_mail=send_mail, auto_generated=True, email_to=[request.issue.owner.email()]).put() request.issue.put() if request.issue.commit and not request.issue.cq_dry_run: views.notify_approvers_of_new_patchsets(request, request.issue) if 'builders' in request.POST: new_builders = filter(None, map(unicode.strip, form.cleaned_data['builders'].split(','))) if request.issue.private and new_builders: return HttpResponseBadRequest( 'Cannot add trybots on private issues', content_type='text/plain') builds = [] for b in new_builders: bucket, builder = b.split(':', 1) builds.append({ 'bucket': bucket, 'builder': builder, }) buildbucket.schedule(request.issue, last_patchset.key.id(), builds) return HttpResponse('OK', content_type='text/plain')
def edit_flags(request): """/<issue>/edit_flags - Edit issue's flags.""" last_patchset = models.PatchSet.query(ancestor=request.issue.key).order( -models.PatchSet.created).get() if not last_patchset: return HttpResponseForbidden('Can only modify flags on last patchset', content_type='text/plain') if request.issue.closed: return HttpResponseForbidden('Can not modify flags for a closed issue', content_type='text/plain') if request.method == 'GET': # TODO(maruel): Have it set per project. initial_builders = 'win_rel, mac_rel, linux_rel' form = EditFlagsForm(initial={ 'last_patchset': last_patchset.key.id(), 'commit': request.issue.commit, 'builders': initial_builders}) return responses.respond(request, 'edit_flags.html', {'issue': request.issue, 'form': form}) form = EditFlagsForm(request.POST) if not form.is_valid(): return HttpResponseBadRequest('Invalid POST arguments', content_type='text/plain') if (form.cleaned_data['last_patchset'] != last_patchset.key.id()): return HttpResponseForbidden('Can only modify flags on last patchset', content_type='text/plain') if 'commit' in request.POST: if request.issue.private and form.cleaned_data['commit'] : return HttpResponseBadRequest( 'Cannot set commit on private issues', content_type='text/plain') request.issue.commit = form.cleaned_data['commit'] request.issue.cq_dry_run = form.cleaned_data['cq_dry_run'] user_email = request.user.email().lower() if user_email == views.CQ_SERVICE_ACCOUNT: user_email = views.CQ_COMMIT_BOT_EMAIL if (request.issue.commit and # Add as reviewer if setting, not clearing. user_email != request.issue.owner.email() and user_email not in request.issue.reviewers and user_email not in request.issue.collaborator_emails()): request.issue.reviewers.append(request.user.email()) # Update the issue with the checking/unchecking of the CQ box but reduce # spam by not emailing users. action = 'checked' if request.issue.commit else 'unchecked' commit_checked_msg = 'The CQ bit was %s by %s' % (action, user_email) if request.issue.cq_dry_run: commit_checked_msg += ' to run a CQ dry run' request.issue.cq_dry_run_last_triggered_by = user_email logging.info('CQ dry run has been triggered by %s for %d/%d', user_email, request.issue.key.id(), last_patchset.key.id()) # Mail just the owner if the CQ bit was unchecked by someone other than the # owner. More details in # https://code.google.com/p/skia/issues/detail?id=3093 unchecked_by_non_owner = (user_email != request.issue.owner.email() and not request.issue.commit) views.make_message(request, request.issue, commit_checked_msg, send_mail=unchecked_by_non_owner, auto_generated=True, email_to=[request.issue.owner.email()]).put() request.issue.put() if request.issue.commit and not request.issue.cq_dry_run: views.notify_approvers_of_new_patchsets(request, request.issue) if 'builders' in request.POST: new_builders = filter(None, map(unicode.strip, form.cleaned_data['builders'].split(','))) if request.issue.private and new_builders: return HttpResponseBadRequest( 'Cannot add trybots on private issues', content_type='text/plain') buildbucket.schedule( request.issue, last_patchset.key.id(), [b.split(':', 1) for b in new_builders]) return HttpResponse('OK', content_type='text/plain')
# context see: crbug.com/479881#c12 if not patchset.data.endswith('\n'): patchset.data += '\n' # Commit the gathered revert Issue, PatchSet, Patches and Contents. _db_commit_all_pending_commits(pending_commits) # Notify the original issue that a revert issue has been created. revert_issue_link = request.build_absolute_uri( reverse('codereview.views.show', args=[issue.key.id()])) revert_message = ( 'A revert of this CL (patchset #%s id:%s) has been created in %s by ' '%s.\n\nThe reason for reverting is: %s.' % (original_patch_num, original_patchset_id, revert_issue_link, request.user.email(), revert_reason)) views.make_message(request, original_issue, revert_message, send_mail=True).put() # Post a message saying who CQ'd the revert. This is critical for CQ, which is # using this message to determine when the attempt has been started. if revert_cq: views.make_message(request, issue, 'The CQ bit was checked by %s' % request.user.email(), auto_generated=True, send_mail=False).put() # Notify the revert issue recipients. views.make_message(request, issue, 'Created %s' % subject, send_mail=True).put()
# context see: crbug.com/479881#c12 if not patchset.data.endswith('\n'): patchset.data += '\n' # Commit the gathered revert Issue, PatchSet, Patches and Contents. _db_commit_all_pending_commits(pending_commits) # Notify the original issue that a revert issue has been created. revert_issue_link = request.build_absolute_uri( reverse('codereview.views.show', args=[issue.key.id()])) revert_message = ( 'A revert of this CL (patchset #%s id:%s) has been created in %s by ' '%s.\n\nThe reason for reverting is: %s.' % ( original_patch_num, original_patchset_id, revert_issue_link, request.user.email(), revert_reason)) views.make_message(request, original_issue, revert_message, send_mail=True).put() # Notify the revert issue recipients. views.make_message(request, issue, 'Created %s' % subject, send_mail=True).put() # Now that all patchsets and patches have been committed check the commit box # if the revert_cq checkbox was checked. if revert_cq: issue.commit = True issue.put() return HttpResponseRedirect(reverse('codereview.views.show', args=[issue.key.id()])) def _db_commit_all_pending_commits(pending_commits):
patch.content_key = content.key patch.patched_content_key = patched_content.key pending_commits.append(patch) # Commit the gathered revert Issue, PatchSet, Patches and Contents. _db_commit_all_pending_commits(pending_commits) # Notify the original issue that a revert issue has been created. revert_issue_link = request.build_absolute_uri( reverse('codereview.views.show', args=[issue.key.id()])) revert_message = ( 'A revert of this CL (patchset #%s id:%s) has been created in %s by ' '%s.\n\nThe reason for reverting is: %s.' % ( original_patch_num, original_patchset_id, revert_issue_link, request.user.email(), revert_reason)) views.make_message(request, original_issue, revert_message, send_mail=True).put() # Notify the revert issue recipients. views.make_message(request, issue, 'Created %s' % subject, send_mail=True).put() # Now that all patchsets and patches have been committed check the commit box # if the revert_cq checkbox was checked. if revert_cq: issue.commit = True issue.put() return HttpResponseRedirect(reverse('codereview.views.show', args=[issue.key.id()])) def _db_commit_all_pending_commits(pending_commits):