Exemplo n.º 1
0
 /**
  * Handles incoming requests from Gitlab or PHPCI to trigger deploy.
  *
  * @param  string   $hash The webhook hash
  * @return Response
  */
 public function webhook($hash)
 {
     $project = $this->projectRepository->getByHash($hash);
     $success = false;
     if ($project->servers->where('deploy_code', true)->count() > 0) {
         // Get the branch if it is the rquest, otherwise deploy the default branch
         $branch = Input::has('branch') ? Input::get('branch') : $project->branch;
         $do_deploy = true;
         if (Input::has('update_only') && Input::get('update_only') !== false) {
             // Get the latest deployment and check the branch matches
             $deployment = $this->deploymentRepository->getLatestSuccessful($project->id);
             if (!$deployment || $deployment->branch !== $branch) {
                 $do_deploy = false;
             }
         }
         if ($do_deploy) {
             $optional = [];
             // Check if the commands input is set, if so explode on comma and filter out any invalid commands
             if (Input::has('commands')) {
                 $valid = $project->commands->lists('id');
                 $optional = collect(explode(',', Input::get('commands')))->unique()->intersect($valid);
             }
             // TODO: Validate URL and only accept it if source is set?
             $this->deploymentRepository->create(['reason' => Input::get('reason'), 'project_id' => $project->id, 'branch' => $branch, 'optional' => $optional, 'source' => Input::get('source'), 'build_url' => Input::get('url')]);
             $success = true;
         }
     }
     return ['success' => $success];
 }
Exemplo n.º 2
0
 /**
  * Handles incoming requests from Gitlab or PHPCI to trigger deploy.
  *
  * @param  string   $hash The webhook hash
  * @return Response
  */
 public function webhook($hash)
 {
     $project = $this->projectRepository->getByHash($hash);
     $success = false;
     if ($project->servers->where('deploy_code', true)->count() > 0) {
         $optional = [];
         // Check if the commands input is set, if so explode on comma and filter out any invalid commands
         if (Input::has('commands')) {
             $valid = $project->commands->lists('id');
             $optional = collect(explode(',', Input::get('commands')))->unique()->intersect($valid);
         }
         $this->deploymentRepository->create(['reason' => Input::get('reason'), 'project_id' => $project->id, 'branch' => $project->branch, 'optional' => $optional]);
         $success = true;
     }
     return ['success' => $success];
 }
Exemplo n.º 3
0
 /**
  * Adds a deployment for the specified project to the queue.
  *
  * @param  int      $project
  * @return Response
  */
 public function deploy($project_id)
 {
     $project = $this->projectRepository->getById($project_id);
     if ($project->servers->where('deploy_code', true)->count() === 0) {
         return redirect()->url('projects', $project->id);
     }
     $data = ['reason' => Input::get('reason'), 'project_id' => $project->id, 'branch' => $project->branch, 'optional' => []];
     if (Input::has('source') && Input::has('source_' . Input::get('source'))) {
         $data['branch'] = Input::get('source_' . Input::get('source'));
     }
     if (Input::has('optional')) {
         $data['optional'] = Input::get('optional');
     }
     $deployment = $this->deploymentRepository->create($data);
     return redirect()->route('deployment', ['id' => $deployment->id]);
 }
Exemplo n.º 4
0
 /**
  * Abort a deployment.
  *
  * @param  int      $deployment_id
  * @return Response
  */
 public function abort($deployment_id)
 {
     $this->deploymentRepository->abort($deployment_id);
     return redirect()->route('deployment', ['id' => $deployment_id]);
 }