def api_build(request, hash): project = models.Project.objects.get(idhash=hash) if project: if request.method == 'POST': if request.POST.get('payload'): r = json.loads(request.POST['payload']) else: r = json.loads(request.body) ref = r.get('ref', '') branch = ref.split('/',2)[-1] if branch != project.branch: return HttpResponse('{"result": "Request ignored"}', content_type='application/json') current_builds = models.Build.objects.filter(project=project, state=0) if not current_builds: build = models.Build.objects.create(project=project, state=0) task = tasks.build(build) build.task_id = task.task_id build.save() return HttpResponse('{"result": "Building"}', content_type='application/json') return HttpResponse('{"result": "Already building"}', content_type='application/json') return redirect('home')
def redirect(self): project = self.getProject(self.id) current_builds = models.Build.objects.filter(project=project, state=0) if current_builds: return redirect('build_view', id=current_builds[0].id) else: build = models.Build.objects.create(project=project, state=0, build_num=bcount) task_id = tasks.build(build) build.task_id = task_id build.save() project.build_counter = bcount project.save() return reverse('build_view', id=build.id) return reverse('home')