@@ -0,0 +1,1873 @@
+from django.core.management.base import BaseCommand%0Afrom ci import models%0Afrom optparse import make_option%0Aimport json, random%0Afrom ci import event%0Afrom django.conf import settings%0Afrom django.core.urlresolvers import reverse%0Aimport requests%0A%0Adef get_rand():%0A  return str(random.randint(1, 10000000000))%0A%0Adef do_post(json_data, ev, base_url):%0A  out_json = json.dumps(json_data, separators=(',', ': '))%0A  server = ev.base.server()%0A  url = %22%22%0A  if server.host_type == settings.GITSERVER_GITHUB:%0A    url = reverse('ci:github:webhook', args=%5Bev.build_user.build_key%5D)%0A  elif server.host_type == settings.GITSERVER_GITLAB:%0A    url = reverse('ci:gitlab:webhook', args=%5Bev.build_user.build_key%5D)%0A  url = %22%25s%25s%22 %25 (base_url, url)%0A  print(%22Posting to URL: %25s%22 %25 url)%0A  response = requests.post(url, out_json)%0A  response.raise_for_status()%0A%0Aclass Command(BaseCommand):%0A  help = 'TESTING ONLY! Grab the event, take the JSON data and change the SHA then post it again to get a new event.'%0A  option_list = BaseCommand.option_list + (%0A      make_option('--pk', dest='pk', type='int', help='The event to update'),%0A      make_option('--url', dest='url', type='str', help='The Civet base URL'),%0A  )%0A%0A  def handle(self, *args, **options):%0A    ev_pk = options.get('pk')%0A    url = options.get('url')%0A    if not url or not ev_pk:%0A      print(%22Missing arguments!%22)%0A      return%0A    ev = models.Event.objects.get(pk=ev_pk)%0A    print(%22Updating event: %25s%22 %25 ev)%0A    settings.REMOTE_UPDATE = False%0A    settings.INSTALL_WEBHOOK = False%0A    json_data = json.loads(ev.json_data)%0A    if ev.cause == ev.PULL_REQUEST:%0A      json_data%5B%22pull_request%22%5D%5B%22head%22%5D%5B%22sha%22%5D = get_rand()%0A      do_post(json_data, ev, url)%0A    elif ev.PUSH:%0A      json_data%5B%22after%22%5D = get_rand()%0A      do_post(json_data, ev, url)%0A    elif ev.MANUAL:%0A      me = event.ManualEvent(ev.build_user, ev.branch, get_rand())%0A      me.save()%0A

Add a small utility for testing to update an event