Example #1
0
 /**
  * Generates the pending and deploying projects for the view.
  *
  * @param View $view
  */
 public function compose(View $view)
 {
     $pending = $this->deploymentRepository->getPending();
     $view->with('pending', $pending);
     $view->with('pending_count', count($pending));
     $deploying = $this->deploymentRepository->getRunning();
     $view->with('deploying', $deploying);
     $view->with('deploying_count', count($deploying));
 }
 /**
  * Builds the data for the timeline.
  *
  * @param DeploymentRepositoryInterface $deploymentRepository
  *
  * @return array
  */
 private function buildTimelineData(DeploymentRepositoryInterface $deploymentRepository)
 {
     $deployments = $deploymentRepository->getTimeline();
     $deploys_by_date = [];
     foreach ($deployments as $deployment) {
         $date = $deployment->started_at->format('Y-m-d');
         if (!isset($deploys_by_date[$date])) {
             $deploys_by_date[$date] = [];
         }
         $deploys_by_date[$date][] = $deployment;
     }
     return $deploys_by_date;
 }
 /**
  * Takes the data returned from the webhook request and then adds deployers own data, such as project ID
  * and runs any checks such as checks the branch is allowed to be deployed.
  *
  * @param array $payload
  * @param Request $request
  * @param Project $project
  *
  * @return array|false Either an array of the complete deployment config, or false if it is invalid.
  */
 private function appendProjectSettings($payload, Request $request, Project $project)
 {
     // If the payload is empty return false
     if (!is_array($payload) || !count($payload)) {
         return false;
     }
     $payload['project_id'] = $project->id;
     // If there is no branch set get it from the project
     if (is_null($payload['branch']) || empty($payload['branch'])) {
         $payload['branch'] = $project->branch;
     }
     // If the project doesn't allow other branches check the requested branch is the correct one
     if (!$project->allow_other_branch && $payload['branch'] !== $project->branch) {
         return false;
     }
     $payload['optional'] = [];
     // Check if the commands input is set, if so explode on comma and filter out any invalid commands
     if ($request->has('commands')) {
         $valid = $project->commands->lists('id');
         $requested = explode(',', $request->get('commands'));
         $payload['optional'] = collect($requested)->unique()->intersect($valid)->toArray();
     }
     // If the webhook is allowed to deploy other branches check if the request has an update_only
     // query string and if so check the branch matches that which is currently deployed
     if ($project->allow_other_branch && $request->has('update_only') && $request->get('update_only') !== false) {
         $deployment = $this->deploymentRepository->getLatestSuccessful($project->id);
         if (!$deployment || $deployment->branch !== $payload['branch']) {
             return false;
         }
     }
     return $payload;
 }
 /**
  * Abort a deployment.
  *
  * @param int $deployment_id
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function abort($deployment_id)
 {
     $this->deploymentRepository->abort($deployment_id);
     return redirect()->route('deployments', ['id' => $deployment_id]);
 }