/** Handle the action, Ensuring to return a JsonResponse.
  *
  * @param string $action
  * @param mixed $actionParams
  *
  * @return \b8\Http\Response
  */
 public function handleAction($action, $actionParams)
 {
     $response = new b8\Http\Response\JsonResponse();
     try {
         $data = parent::handleAction($action, $actionParams);
         if (isset($data['responseCode'])) {
             $response->setResponseCode($data['responseCode']);
             unset($data['responseCode']);
         }
         $response->setContent($data);
     } catch (Exception $ex) {
         $response->setResponseCode(500);
         $response->setContent(array('status' => 'failed', 'error' => $ex->getMessage()));
     }
     return $response;
 }
示例#2
0
 /**
  * AJAX call to get build data:
  */
 public function data($buildId)
 {
     $response = new JsonResponse();
     $build = BuildFactory::getBuildById($buildId);
     if (!$build) {
         $response->setResponseCode(404);
         $response->setContent(array());
         return $response;
     }
     $response->setContent($this->getBuildData($build));
     return $response;
 }
示例#3
0
 /**
  * Called by Gitlab Webhooks:
  */
 public function gitlab($project)
 {
     $response = new b8\Http\Response\JsonResponse();
     $response->setContent(array('status' => 'ok'));
     $payloadString = file_get_contents("php://input");
     $payload = json_decode($payloadString, true);
     try {
         // build on merge request events
         if (isset($payload['object_kind']) && $payload['object_kind'] == 'merge_request') {
             $attributes = $payload['object_attributes'];
             if ($attributes['state'] == 'opened' || $attributes['state'] == 'reopened') {
                 $branch = $attributes['source_branch'];
                 $commit = $attributes['last_commit'];
                 $committer = $commit['author']['email'];
                 $this->createBuild($project, $commit['id'], $branch, $committer, $commit['message']);
             }
         }
         // build on push events
         if (isset($payload['commits']) && is_array($payload['commits'])) {
             // If we have a list of commits, then add them all as builds to be tested:
             foreach ($payload['commits'] as $commit) {
                 $branch = str_replace('refs/heads/', '', $payload['ref']);
                 $committer = $commit['author']['email'];
                 $this->createBuild($project, $commit['id'], $branch, $committer, $commit['message']);
             }
         }
     } catch (\Exception $ex) {
         $response->setResponseCode(500);
         $response->setContent(array('status' => 'failed', 'error' => $ex->getMessage()));
     }
     return $response;
 }