From 771bee0aa3396d2f386bbfea01d4c7ee0194ab0c Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Mon, 5 Oct 2015 14:41:13 +0100 Subject: [PATCH] Fixings --- PHPCI/BuildFactory.php | 21 ++++++++++++++++----- PHPCI/Model/Build/GithubBuild.php | 18 +++++++++++++----- PHPCI/Service/BuildService.php | 8 +++++++- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/PHPCI/BuildFactory.php b/PHPCI/BuildFactory.php index c7bad338..fb20309d 100644 --- a/PHPCI/BuildFactory.php +++ b/PHPCI/BuildFactory.php @@ -36,12 +36,17 @@ class BuildFactory /** * Takes a generic build and returns a type-specific build model. - * @param Build $base The build from which to get a more specific build type. + * @param Build $build The build from which to get a more specific build type. + * @param string $type Set the type manually if you already know it. * @return Build */ - public static function getBuild(Build $base) + public static function getBuild(Build $build, $type = null) { - switch ($base->getProject()->getType()) { + if (is_null($type) && !is_null($build->getProject())) { + $type = $build->getProject()->getType(); + } + + switch ($type) { case 'remote': $type = 'RemoteGitBuild'; break; @@ -63,10 +68,16 @@ class BuildFactory case 'svn': $type = 'SubversionBuild'; break; + default: + $type = null; + break; } - $type = '\\PHPCI\\Model\\Build\\' . $type; + if (!is_null($type)) { + $type = '\\PHPCI\\Model\\Build\\' . $type; + $build = new $type($build->getDataArray()); + } - return new $type($base->getDataArray()); + return $build; } } diff --git a/PHPCI/Model/Build/GithubBuild.php b/PHPCI/Model/Build/GithubBuild.php index 0ae3b9e0..130d7acb 100644 --- a/PHPCI/Model/Build/GithubBuild.php +++ b/PHPCI/Model/Build/GithubBuild.php @@ -45,12 +45,16 @@ class GithubBuild extends RemoteGitBuild { $token = \b8\Config::getInstance()->get('phpci.github.token'); - if (empty($token)) { + if (empty($token) || empty($this->data['id'])) { return; } $project = $this->getProject(); + if (empty($project)) { + return; + } + $url = 'https://api.github.com/repos/'.$project->getReference().'/statuses/'.$this->getCommitId(); $http = new \b8\HttpClient(); @@ -114,10 +118,14 @@ class GithubBuild extends RemoteGitBuild { $rtn = parent::getCommitMessage($this->data['commit_message']); - $reference = $this->getProject()->getReference(); - $commitLink = '#$1'; - $rtn = preg_replace('/\#([0-9]+)/', $commitLink, $rtn); - $rtn = preg_replace('/\@([a-zA-Z0-9_]+)/', '@$1', $rtn); + $project = $this->getProject(); + + if (!is_null($project)) { + $reference = $project->getReference(); + $commitLink = '#$1'; + $rtn = preg_replace('/\#([0-9]+)/', $commitLink, $rtn); + $rtn = preg_replace('/\@([a-zA-Z0-9_]+)/', '@$1', $rtn); + } return $rtn; } diff --git a/PHPCI/Service/BuildService.php b/PHPCI/Service/BuildService.php index 94eb9792..3f03f559 100644 --- a/PHPCI/Service/BuildService.php +++ b/PHPCI/Service/BuildService.php @@ -87,7 +87,7 @@ class BuildService $build = $this->buildStore->save($build); - $build = BuildFactory::getBuild($build); + $build = BuildFactory::getBuild($build, $project->getType()); $build->sendStatusPostback(); $this->addBuildToQueue($build); @@ -140,6 +140,12 @@ class BuildService */ public function addBuildToQueue(Build $build) { + $buildId = $build->getId(); + + if (empty($buildId)) { + return; + } + $config = Config::getInstance(); $settings = $config->get('phpci.worker', []);