From 7a910631e65af0b8b76cc0e7e350bad24ea452b9 Mon Sep 17 00:00:00 2001 From: Corpsee Date: Sat, 15 Mar 2014 12:18:12 +0700 Subject: [PATCH] Added database-based yml build config --- PHPCI/Controller/ProjectController.php | 8 ++++ PHPCI/Model/Base/ProjectBase.php | 58 +++++++++++++++++++++----- PHPCI/Model/Build/LocalBuild.php | 17 ++++---- PHPCI/Model/Build/MercurialBuild.php | 19 +++++---- PHPCI/Model/Build/RemoteGitBuild.php | 18 ++++---- 5 files changed, 88 insertions(+), 32 deletions(-) diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 19fb3149..94390582 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -318,6 +318,14 @@ class ProjectController extends \PHPCI\Controller $field->setRows(6); $form->addField($field); + $field = new Form\Element\TextArea('build_config'); + $field->setRequired(false); + $field->setLabel('PHPCI build config for this project (instead phpci.yml in the project repository)'); + $field->setClass('form-control'); + $field->setContainerClass('form-group'); + $field->setRows(6); + $form->addField($field); + $field = new Form\Element\Submit(); $field->setValue('Save Project'); $field->setContainerClass('form-group'); diff --git a/PHPCI/Model/Base/ProjectBase.php b/PHPCI/Model/Base/ProjectBase.php index df1c0a34..adb9ac5a 100644 --- a/PHPCI/Model/Base/ProjectBase.php +++ b/PHPCI/Model/Base/ProjectBase.php @@ -37,6 +37,7 @@ class ProjectBase extends Model 'title' => null, 'reference' => null, 'git_key' => null, + 'build_config' => null, 'type' => null, 'token' => null, 'access_information' => null, @@ -52,6 +53,7 @@ class ProjectBase extends Model 'title' => 'getTitle', 'reference' => 'getReference', 'git_key' => 'getGitKey', + 'build_config' => 'getBuildConfig', 'type' => 'getType', 'token' => 'getToken', 'access_information' => 'getAccessInformation', @@ -69,6 +71,7 @@ class ProjectBase extends Model 'title' => 'setTitle', 'reference' => 'setReference', 'git_key' => 'setGitKey', + 'build_config' => 'setBuildConfig', 'type' => 'setType', 'token' => 'setToken', 'access_information' => 'setAccessInformation', @@ -103,6 +106,11 @@ class ProjectBase extends Model 'nullable' => true, 'default' => null, ), + 'build_config' => array( + 'type' => 'text', + 'nullable' => true, + 'default' => null, + ), 'type' => array( 'type' => 'varchar', 'length' => 50, @@ -132,8 +140,8 @@ class ProjectBase extends Model * @var array */ public $indexes = array( - 'PRIMARY' => array('unique' => true, 'columns' => 'id'), - 'idx_project_title' => array('columns' => 'title'), + 'PRIMARY' => array('unique' => true, 'columns' => 'id'), + 'idx_project_title' => array('columns' => 'title'), ); /** @@ -149,7 +157,7 @@ class ProjectBase extends Model */ public function getId() { - $rtn = $this->data['id']; + $rtn = $this->data['id']; return $rtn; } @@ -161,7 +169,7 @@ class ProjectBase extends Model */ public function getTitle() { - $rtn = $this->data['title']; + $rtn = $this->data['title']; return $rtn; } @@ -173,7 +181,7 @@ class ProjectBase extends Model */ public function getReference() { - $rtn = $this->data['reference']; + $rtn = $this->data['reference']; return $rtn; } @@ -185,7 +193,19 @@ class ProjectBase extends Model */ public function getGitKey() { - $rtn = $this->data['git_key']; + $rtn = $this->data['git_key']; + + return $rtn; + } + + /** + * Get the value of BuildConfig / build_config. + * + * @return string + */ + public function getBuildConfig() + { + $rtn = $this->data['build_config']; return $rtn; } @@ -197,7 +217,7 @@ class ProjectBase extends Model */ public function getType() { - $rtn = $this->data['type']; + $rtn = $this->data['type']; return $rtn; } @@ -209,7 +229,7 @@ class ProjectBase extends Model */ public function getToken() { - $rtn = $this->data['token']; + $rtn = $this->data['token']; return $rtn; } @@ -221,7 +241,7 @@ class ProjectBase extends Model */ public function getAccessInformation() { - $rtn = $this->data['access_information']; + $rtn = $this->data['access_information']; return $rtn; } @@ -233,7 +253,7 @@ class ProjectBase extends Model */ public function getLastCommit() { - $rtn = $this->data['last_commit']; + $rtn = $this->data['last_commit']; return $rtn; } @@ -316,6 +336,24 @@ class ProjectBase extends Model $this->_setModified('git_key'); } + /** + * Set the value of BuildConfig / build_config. + * + * @param $value string + */ + public function setBuildConfig($value) + { + $this->_validateString('BuildConfig', $value); + + if ($this->data['build_config'] === $value) { + return; + } + + $this->data['build_config'] = $value; + + $this->_setModified('build_config'); + } + /** * Set the value of Type / type. * diff --git a/PHPCI/Model/Build/LocalBuild.php b/PHPCI/Model/Build/LocalBuild.php index 485376ad..3feae1b1 100644 --- a/PHPCI/Model/Build/LocalBuild.php +++ b/PHPCI/Model/Build/LocalBuild.php @@ -86,15 +86,18 @@ class LocalBuild extends Build protected function handleConfig(Builder $builder, $reference) { - /** @todo Add support for database-based yml definition */ - if (!is_file($reference . '/phpci.yml')) { - $builder->logFailure('Project does not contain a phpci.yml file.'); - return false; - } + $build_config = $this->getProject()->getBuildConfig(); + if (!$build_config) + { + if (!is_file($reference . '/phpci.yml')) { + $builder->logFailure('Project does not contain a phpci.yml file.'); + return false; + } + $build_config = file_get_contents($reference . '/phpci.yml'); + } $yamlParser = new YamlParser(); - $yamlFile = file_get_contents($reference . '/phpci.yml'); - $builder->setConfigArray($yamlParser->parse($yamlFile)); + $builder->setConfigArray($yamlParser->parse($build_config)); return $builder->getConfig('build_settings'); } } diff --git a/PHPCI/Model/Build/MercurialBuild.php b/PHPCI/Model/Build/MercurialBuild.php index dbfcf4e2..412c2ad3 100644 --- a/PHPCI/Model/Build/MercurialBuild.php +++ b/PHPCI/Model/Build/MercurialBuild.php @@ -34,17 +34,20 @@ class MercurialBuild extends Build */ public function createWorkingCopy(Builder $builder, $buildPath) { - $yamlParser = new YamlParser(); - $this->cloneByHttp($builder, $buildPath); - if (!is_file($buildPath . 'phpci.yml')) { - $builder->logFailure('Project does not contain a phpci.yml file.'); - return false; - } + $build_config = $this->getProject()->getBuildConfig(); + if (!$build_config) + { + if (!is_file($buildPath . '/phpci.yml')) { + $builder->logFailure('Project does not contain a phpci.yml file.'); + return false; + } + $build_config = file_get_contents($buildPath . '/phpci.yml'); + } - $yamlFile = file_get_contents($buildPath . 'phpci.yml'); - $builder->setConfigArray($yamlParser->parse($yamlFile)); + $yamlParser = new YamlParser(); + $builder->setConfigArray($yamlParser->parse($build_config)); return true; } diff --git a/PHPCI/Model/Build/RemoteGitBuild.php b/PHPCI/Model/Build/RemoteGitBuild.php index 4faf2557..3c84b06d 100644 --- a/PHPCI/Model/Build/RemoteGitBuild.php +++ b/PHPCI/Model/Build/RemoteGitBuild.php @@ -34,7 +34,6 @@ class RemoteGitBuild extends Build */ public function createWorkingCopy(Builder $builder, $buildPath) { - $yamlParser = new YamlParser(); $key = trim($this->getProject()->getGitKey()); if (!empty($key)) { @@ -48,13 +47,18 @@ class RemoteGitBuild extends Build return false; } - if (!is_file($buildPath . 'phpci.yml')) { - $builder->logFailure('Project does not contain a phpci.yml file.'); - return false; - } + $build_config = $this->getProject()->getBuildConfig(); + if (!$build_config) + { + if (!is_file($buildPath . '/phpci.yml')) { + $builder->logFailure('Project does not contain a phpci.yml file.'); + return false; + } + $build_config = file_get_contents($buildPath . '/phpci.yml'); + } - $yamlFile = file_get_contents($buildPath . 'phpci.yml'); - $builder->setConfigArray($yamlParser->parse($yamlFile)); + $yamlParser = new YamlParser(); + $builder->setConfigArray($yamlParser->parse($build_config)); return true; }