Ejemplo n.º 1
0
 /**
  * 
  * @return SS_HTTPResponse
  */
 protected function createDeploy()
 {
     if (!$this->record->canDeploy($this->getMember())) {
         return $this->message('You are not authorized to do that on this environment', 403);
     }
     $reqBody = $this->getRequestBody();
     if ($reqBody === null) {
         return $this->message('the request body did not contain a valid JSON object.', 400);
     }
     if (empty($reqBody['release'])) {
         return $this->message('deploy requires a {"release": "sha1"} in the body of the request.', 400);
     }
     $deploy = new DNDeployment();
     $deploy->EnvironmentID = $this->record->ID;
     $deploy->SHA = $reqBody['release'];
     $deploy->write();
     $deploy->start();
     $location = Director::absoluteBaseURL() . $this->Link() . '/deploy/' . $deploy->ID;
     $output = array('message' => 'Deploy queued as job ' . $deploy->ResqueToken, 'href' => $location);
     $response = $this->getAPIResponse($output);
     $response->setStatusCode(201);
     $response->addHeader('Location', $location);
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * Deployment form submission handler.
  *
  * Initiate a DNDeployment record and redirect to it for status polling
  * 
  * @return \SS_HTTPResponse
  */
 public function doDeploy($data, $form)
 {
     if (in_array($data['SelectRelease'], array('Tag', 'Branch', 'Redeploy', 'SHA'))) {
         $buildName = $data[$data['SelectRelease']];
     } else {
         throw new LogicException("Bad release selection method " . Convert::raw2xml($data['SelectRelease']));
     }
     if (!preg_match('/^[a-f0-9]{40}$/', $buildName)) {
         throw new LogicException("Bad commit SHA");
     }
     // Performs canView permission check by limiting visible projects
     $project = $this->getCurrentProject();
     if (!$project) {
         return new SS_HTTPResponse("Project '" . Convert::raw2xml($this->getRequest()->latestParam('Project')) . "' not found.", 404);
     }
     // Performs canView permission check by limiting visible projects
     $environment = $this->getCurrentEnvironment($project);
     if (!$environment) {
         return new SS_HTTPResponse("Environment '" . Convert::raw2xml($this->getRequest()->latestParam('Environment')) . "' not found.", 404);
     }
     $sha = $project->DNBuildList()->byName($buildName);
     $deployment = new DNDeployment();
     $deployment->EnvironmentID = $environment->ID;
     $deployment->SHA = $sha->FullName();
     $deployment->write();
     $deployment->start();
     $this->redirect($deployment->Link());
 }