current progress on webhook

pull/1/head
Raymond Yee 2016-02-22 07:24:59 -08:00
parent fb9a2bcd04
commit ca43d47397
1 changed files with 45 additions and 1 deletions

View File

@ -1,5 +1,7 @@
from tastypie.models import ApiKey
import logging
from django.contrib import auth
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
@ -24,6 +26,8 @@ from regluit.api.models import repo_allowed
from regluit.core import models
logger = logging.getLogger(__name__)
def editions(request):
editions = models.Edition.objects.all()
@ -82,7 +86,47 @@ def load_yaml(request):
@csrf_exempt
def travisci_webhook(request):
return HttpResponse('travisci webhook')
if request.method == "GET":
return HttpResponse('travisci webhook GET')
elif request.method == "POST":
# how to get headers, body
# return HttpResponse('travisci webhook POST')
repo_header = request.META.get('HTTP_TRAVIS_REPO_SLUG', '')
data = request.POST
# [python - How can I get all the request headers in Django? - Stack Overflow](https://stackoverflow.com/questions/3889769/how-can-i-get-all-the-request-headers-in-django)
import re
regex = re.compile('^HTTP_')
all_headers = dict((regex.sub('', header), value) for (header, value)
in request.META.items() if header.startswith('HTTP_'))
# what's the URL to feed to load
# https://github.com/GITenberg/Adventures-of-Huckleberry-Finn_76/raw/master/metadata.yaml
if data.get('status_message') == 'Passed' and data.get('type') == 'push':
repo_url = "https://github.com/{}/raw/master/metadata.yaml".format(repo_header)
logger.info("repo_url:{}".format(repo_url))
try:
work_id = load_from_yaml(repo_url)
logger.info("work_id: {}".format(work_id))
return HttpResponse('successful: {}'.format(work_id))
except Exception as e:
logger.info("exception: {}".format(unicode(e)))
return HttpResponse('unsuccessful: {}'.format(unicode(e)))
else:
return HttpResponse('travisci webhook POST repo_header:{} type:{} state:{} result:{} status_message:{} commit:{} '.format(repo_header,
data.get('type'),
data['state'],
data['result'],
data.get('status_message'),
data.get('commit')
))
class ApiHelpView(TemplateView):
template_name = "api_help.html"