Commit d654330d authored by Hemang Kumar's avatar Hemang Kumar

coala_online: Add coala_online endpoint

parent 8192b825
default_app_config = (
'coala_online.apps.CoalaOnlineConfig'
)
from django.apps import AppConfig
class CoalaOnlineConfig(AppConfig):
name = 'coala_online'
verbose_name = 'API endpoint to run coala and coala-quickstart online'
description = 'The ``coala_online`` endpoint helps' \
'users to run coala-quickstart and coala on their code' \
'snippet or on a git repository.'
COALA_ONLINE_IMAGE = \
'registry.gitlab.com/hemangsk/coala-incremental-results:latest'
import json
import subprocess
from collections import defaultdict
from django.http import JsonResponse
from django.views.decorators.http import require_http_methods
from coala_online.config import COALA_ONLINE_IMAGE
@require_http_methods(['POST'])
def coala_online(request):
"""
Spawns a docker container to run coala and coala-quickstart as specified.
Documentation on the running modes can be found here,
https://gitlab.com/hemangsk/coala-incremental-results/blob/master/README.md
"""
request = json.loads(request.body.decode('utf-8'))
req = defaultdict(lambda : None)
req['mode'] = request['mode']
req['file_content'] = request.get('file_data', None)
req['language'] = request.get('language', None)
req['url'] = request.get('url', None)
req['sections'] = request.get('sections', None)
req_str = json.dumps(req)
proc = subprocess.Popen(
['docker', 'run', '-i', '--rm',
COALA_ONLINE_IMAGE,
'python3', 'run.py', req_str],
stdout=subprocess.PIPE,
)
response = json.loads(proc.stdout.read().decode('utf-8'))
return JsonResponse(response, safe=False)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment