Esempio n. 1
0
 /** 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;
 }
Esempio n. 2
0
 /**
  * Get an array of repositories from Github's API.
  */
 protected function githubRepositories()
 {
     $github = new Github();
     $response = new b8\Http\Response\JsonResponse();
     $response->setContent($github->getRepositories());
     return $response;
 }
Esempio n. 3
0
 /**
  * Look up available versions of a given package on packagist.org
  */
 public function packagistVersions()
 {
     $name = $this->getParam('p', '');
     $http = new \b8\HttpClient();
     $http->setHeaders(array('User-Agent: PHPCI/1.0 (+https://www.phptesting.org)'));
     $res = $http->get('https://packagist.org/packages/' . $name . '.json');
     $response = new b8\Http\Response\JsonResponse();
     $response->setContent($res['body']);
     return $response;
 }
Esempio n. 4
0
 /**
  * Allows the UI to poll for the latest running and pending builds.
  */
 public function latest()
 {
     $rtn = array('pending' => $this->formatBuilds($this->buildStore->getByStatus(Build::STATUS_NEW)), 'running' => $this->formatBuilds($this->buildStore->getByStatus(Build::STATUS_RUNNING)));
     $response = new JsonResponse();
     $response->setContent($rtn);
     return $response;
 }
Esempio n. 5
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;
 }