/** * Handles incoming requests to trigger deploy. * * @param Request $request * @param string $hash The webhook hash * * @return \Illuminate\View\View */ public function webhook(Request $request, $hash) { $project = $this->projectRepository->getByHash($hash); $success = false; if ($project->servers->where('deploy_code', true)->count() > 0) { $payload = $this->parseWebhookRequest($request, $project); if (is_array($payload)) { $this->deploymentRepository->abortQueued($project->id); $this->deploymentRepository->create($payload); $success = true; } } return ['success' => $success]; }
/** * Adds a deployment for the specified project to the queue. * * @param Request $request * @param int $project_id * * @return \Illuminate\Http\RedirectResponse */ public function deploy(Request $request, $project_id) { $project = $this->projectRepository->getById($project_id); if ($project->servers->where('deploy_code', true)->count() === 0) { return redirect()->route('projects', ['id' => $project->id]); } $data = ['reason' => $request->get('reason'), 'project_id' => $project->id, 'branch' => $project->branch, 'optional' => []]; // If allow other branches is set, check for post data if ($project->allow_other_branch) { if ($request->has('source') && $request->has('source_' . $request->get('source'))) { $data['branch'] = $request->get('source_' . $request->get('source')); } } // Get the optional commands and typecast to integers if ($request->has('optional') && is_array($request->get('optional'))) { $data['optional'] = array_filter(array_map(function ($value) { return filter_var($value, FILTER_VALIDATE_INT); }, $request->get('optional'))); } $deployment = $this->deploymentRepository->create($data); return redirect()->route('deployments', ['id' => $deployment->id]); }