From e0accc7a9791270faa5641b013a22946bf345385 Mon Sep 17 00:00:00 2001 From: Gabriel Baker Date: Mon, 13 May 2013 21:03:32 +0100 Subject: [PATCH 1/7] file system --- PHPCI/Controller/ProjectController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index d0834df8..a9a947f6 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -128,7 +128,7 @@ class ProjectController extends b8\Controller { throw new \Exception('You do not have permission to do that.'); } - + $method = Registry::getInstance()->get('requestMethod'); $project = $this->_projectStore->getById($id); @@ -180,15 +180,15 @@ class ProjectController extends b8\Controller $field = new Form\Element\Select('type'); $field->setRequired(true); - $field->setOptions(array('github' => 'Github', 'bitbucket' => 'Bitbucket')); + $field->setOptions(array('github' => 'Github', 'bitbucket' => 'Bitbucket', 'local' => 'Local FS')); $field->setLabel('Where is your project hosted?'); $field->setClass('span4'); $form->addField($field); $field = new Form\Element\Text('reference'); $field->setRequired(true); - $field->setPattern('[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+'); - $field->setLabel('Repository Name on Github / Bitbucket (e.g. block8/phpci)'); + // $field->setPattern('[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+'); + $field->setLabel('Repository Name on Github / Bitbucket (e.g. block8/phpci) or directory location'); $field->setClass('span4'); $form->addField($field); From 53675c940fe75317b23357a5b6fa972c36b61469 Mon Sep 17 00:00:00 2001 From: Gabriel Baker Date: Mon, 13 May 2013 21:33:59 +0100 Subject: [PATCH 2/7] fixed not type checking status --- PHPCI/Builder.php | 6 +++--- PHPCI/Model/Base/BuildBase.php | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index b3ff03a9..85d7d7e7 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -143,7 +143,7 @@ class Builder // Do an HTTP clone: $this->executeCommand('git clone -b ' .$this->build->getBranch() . ' ' .$url.' '.$this->buildPath); } - + if(!is_file($this->buildPath . 'phpci.yml')) { $this->logFailure('Project does not contain a phpci.yml file.'); @@ -202,7 +202,7 @@ class Builder { $this->success = false; } - + continue; } @@ -216,7 +216,7 @@ class Builder { $this->success = false; } - + $this->logFailure('PLUGIN STATUS: FAILED'); continue; } diff --git a/PHPCI/Model/Base/BuildBase.php b/PHPCI/Model/Base/BuildBase.php index fb9987d5..f4bfcce4 100644 --- a/PHPCI/Model/Base/BuildBase.php +++ b/PHPCI/Model/Base/BuildBase.php @@ -143,7 +143,7 @@ class BuildBase extends Model { $rtn = $this->_data['id']; - + return $rtn; } @@ -151,7 +151,7 @@ class BuildBase extends Model { $rtn = $this->_data['project_id']; - + return $rtn; } @@ -159,7 +159,7 @@ class BuildBase extends Model { $rtn = $this->_data['commit_id']; - + return $rtn; } @@ -167,7 +167,7 @@ class BuildBase extends Model { $rtn = $this->_data['status']; - + return $rtn; } @@ -175,7 +175,7 @@ class BuildBase extends Model { $rtn = $this->_data['log']; - + return $rtn; } @@ -183,7 +183,7 @@ class BuildBase extends Model { $rtn = $this->_data['branch']; - + return $rtn; } @@ -191,13 +191,13 @@ class BuildBase extends Model { $rtn = $this->_data['created']; - + if(!empty($rtn)) { $rtn = new \DateTime($rtn); } - + return $rtn; } @@ -205,13 +205,13 @@ class BuildBase extends Model { $rtn = $this->_data['started']; - + if(!empty($rtn)) { $rtn = new \DateTime($rtn); } - + return $rtn; } @@ -219,13 +219,13 @@ class BuildBase extends Model { $rtn = $this->_data['finished']; - + if(!empty($rtn)) { $rtn = new \DateTime($rtn); } - + return $rtn; } @@ -277,7 +277,7 @@ class BuildBase extends Model { $this->_validateNotNull('Status', $value); $this->_validateInt('Status', $value); - if($this->_data['status'] == $value) + if($this->_data['status'] === $value) { return; } From 8502212c7cdeda194cc6a0dac5a41cb95d8b3f10 Mon Sep 17 00:00:00 2001 From: Gabriel Baker Date: Mon, 13 May 2013 23:46:08 +0100 Subject: [PATCH 3/7] Sorted out a file only type Sorted out some indentation Check if array etc Fixes for phpunit Current working directory in phpunit php code coverage in composer.json --- PHPCI/Builder.php | 46 ++++++--- PHPCI/Model/Base/BuildBase.php | 184 +++++++++++++++------------------ PHPCI/Plugin/PhpUnit.php | 6 +- composer.json | 1 + favicon.ico | Bin 0 -> 198 bytes 5 files changed, 119 insertions(+), 118 deletions(-) create mode 100644 favicon.ico diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 85d7d7e7..b32c106f 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -121,27 +121,41 @@ class Builder $commitId = $this->build->getCommitId(); $url = $this->build->getProject()->getGitUrl(); $key = $this->build->getProject()->getGitKey(); + $type = $this->build->getProject()->getType(); $buildId = 'project' . $this->build->getProject()->getId() . '-build' . $this->build->getId(); $this->ciDir = realpath(dirname(__FILE__) . '/../') . '/'; $this->buildPath = $this->ciDir . 'build/' . $buildId . '/'; - mkdir($this->buildPath, 0777, true); - if(!empty($key)) - { - // Do an SSH clone: - $keyFile = $this->ciDir . 'build/' . $buildId . '.key'; - file_put_contents($keyFile, $key); - chmod($keyFile, 0600); - $this->executeCommand('ssh-agent ssh-add '.$keyFile.' && git clone -b ' .$this->build->getBranch() . ' ' .$url.' '.$this->buildPath.' && ssh-agent -k'); - unlink($keyFile); - } - else - { - // Do an HTTP clone: - $this->executeCommand('git clone -b ' .$this->build->getBranch() . ' ' .$url.' '.$this->buildPath); + switch ($type) { + case 'local': + $reference = $this->build->getProject()->getReference(); + $this->buildPath = $this->ciDir . 'build/' . $buildId; + if(is_link($this->buildPath) && is_file($this->buildPath)) { + } else { + symlink($reference, $this->buildPath); + } + $this->buildPath .= '/'; + break; + default: + mkdir($this->buildPath, 0777, true); + if(!empty($key)) + { + // Do an SSH clone: + $keyFile = $this->ciDir . 'build/' . $buildId . '.key'; + file_put_contents($keyFile, $key); + chmod($keyFile, 0600); + $this->executeCommand('ssh-agent ssh-add '.$keyFile.' && git clone -b ' .$this->build->getBranch() . ' ' .$url.' '.$this->buildPath.' && ssh-agent -k'); + unlink($keyFile); + } + else + { + // Do an HTTP clone: + $this->executeCommand('git clone -b ' .$this->build->getBranch() . ' ' .$url.' '.$this->buildPath); + } + break; } if(!is_file($this->buildPath . 'phpci.yml')) @@ -179,6 +193,10 @@ class Builder protected function executePlugins($stage) { + if ( array_key_exists($stage, $this->config) && !is_array($this->config[$stage]) ) { + return; + } + foreach($this->config[$stage] as $plugin => $options) { $this->log(''); diff --git a/PHPCI/Model/Base/BuildBase.php b/PHPCI/Model/Base/BuildBase.php index f4bfcce4..81726e34 100644 --- a/PHPCI/Model/Base/BuildBase.php +++ b/PHPCI/Model/Base/BuildBase.php @@ -16,126 +16,104 @@ class BuildBase extends Model protected $_tableName = 'build'; protected $_modelName = 'Build'; protected $_data = array( - 'id' => null, - 'project_id' => null, - 'commit_id' => null, - 'status' => null, - 'log' => null, - 'branch' => null, - 'created' => null, - 'started' => null, - 'finished' => null, - ); + 'id' => null, + 'project_id' => null, + 'commit_id' => null, + 'status' => null, + 'log' => null, + 'branch' => null, + 'created' => null, + 'started' => null, + 'finished' => null, + ); protected $_getters = array( - 'id' => 'getId', - 'project_id' => 'getProjectId', - 'commit_id' => 'getCommitId', - 'status' => 'getStatus', - 'log' => 'getLog', - 'branch' => 'getBranch', - 'created' => 'getCreated', - 'started' => 'getStarted', - 'finished' => 'getFinished', + 'id' => 'getId', + 'project_id' => 'getProjectId', + 'commit_id' => 'getCommitId', + 'status' => 'getStatus', + 'log' => 'getLog', + 'branch' => 'getBranch', + 'created' => 'getCreated', + 'started' => 'getStarted', + 'finished' => 'getFinished', - 'Project' => 'getProject', + 'Project' => 'getProject', - ); + ); protected $_setters = array( - 'id' => 'setId', - 'project_id' => 'setProjectId', - 'commit_id' => 'setCommitId', - 'status' => 'setStatus', - 'log' => 'setLog', - 'branch' => 'setBranch', - 'created' => 'setCreated', - 'started' => 'setStarted', - 'finished' => 'setFinished', + 'id' => 'setId', + 'project_id' => 'setProjectId', + 'commit_id' => 'setCommitId', + 'status' => 'setStatus', + 'log' => 'setLog', + 'branch' => 'setBranch', + 'created' => 'setCreated', + 'started' => 'setStarted', + 'finished' => 'setFinished', - 'Project' => 'setProject', - ); + 'Project' => 'setProject', + ); public $columns = array( - 'id' => array( - 'type' => 'int', - 'length' => '11', + 'id' => array( + 'type' => 'int', + 'length' => '11', - 'primary_key' => true, - 'auto_increment' => true, + 'primary_key' => true, + 'auto_increment' => true, - ), - 'project_id' => array( - 'type' => 'int', - 'length' => '11', + ), + 'project_id' => array( + 'type' => 'int', + 'length' => '11', + ), + 'commit_id' => array( + 'type' => 'varchar', + 'length' => '50', + ), + 'status' => array( + 'type' => 'tinyint', + 'length' => '4', + ), + 'log' => array( + 'type' => 'text', + 'length' => '', + 'nullable' => true, - ), - 'commit_id' => array( - 'type' => 'varchar', - 'length' => '50', + ), + 'branch' => array( + 'type' => 'varchar', + 'length' => '50', + ), + 'created' => array( + 'type' => 'datetime', + 'length' => '', + 'nullable' => true, - - - ), - 'status' => array( - 'type' => 'tinyint', - 'length' => '4', - - - - - ), - 'log' => array( - 'type' => 'text', - 'length' => '', - 'nullable' => true, - - - - ), - 'branch' => array( - 'type' => 'varchar', - 'length' => '50', - - - - - ), - 'created' => array( - 'type' => 'datetime', - 'length' => '', - 'nullable' => true, - - - - ), - 'started' => array( - 'type' => 'datetime', - 'length' => '', - 'nullable' => true, - - - - ), - 'finished' => array( - 'type' => 'datetime', - 'length' => '', - 'nullable' => true, - - - - ), - ); + ), + 'started' => array( + 'type' => 'datetime', + 'length' => '', + 'nullable' => true, + ), + 'finished' => array( + 'type' => 'datetime', + 'length' => '', + 'nullable' => true, + ), + ); public $indexes = array( - 'PRIMARY' => array('unique' => true, 'columns' => 'id'), - 'project_id' => array('columns' => 'project_id'), - 'idx_status' => array('columns' => 'status'), - ); + 'PRIMARY' => array('unique' => true, 'columns' => 'id'), + 'project_id' => array('columns' => 'project_id'), + 'idx_status' => array('columns' => 'status'), + ); public $foreignKeys = array( - 'build_ibfk_1' => array('local_col' => 'project_id', 'update' => 'CASCADE', 'delete' => 'CASCADE', 'table' => 'project', 'col' => 'id'), - ); + 'build_ibfk_1' => array('local_col' => 'project_id', 'update' => 'CASCADE', 'delete' => 'CASCADE', 'table' => 'project', 'col' => 'id'), + ); diff --git a/PHPCI/Plugin/PhpUnit.php b/PHPCI/Plugin/PhpUnit.php index d34ee3d5..84b65542 100644 --- a/PHPCI/Plugin/PhpUnit.php +++ b/PHPCI/Plugin/PhpUnit.php @@ -17,6 +17,10 @@ class PhpUnit implements \PHPCI\Plugin public function execute() { - return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit ' . $this->args . ' ' . $this->phpci->buildPath . $this->directory); + $curdir = getcwd(); + chdir($this->phpci->buildPath); + $success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit ' . $this->args . ' ' . $this->phpci->buildPath . $this->directory); + chdir($curdir); + return $success; } } \ No newline at end of file diff --git a/composer.json b/composer.json index 50cc4039..3024b43b 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "require": { "block8/b8framework": "dev-master", "phpunit/phpunit": "3.*", + "phpunit/php-code-coverage": "1.2.x", "phpmd/phpmd" : "1.*", "sebastian/phpcpd": "1.*", "squizlabs/php_codesniffer": "1.*", diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..a9266419f2019baf49bf05560d339a92efa80b94 GIT binary patch literal 198 zcmZQzU<5(|0VW0z*Z{<0K&%180zj+)#2|SPZ~&7K0-_qi{@=pDQ2&pCp#i9j91PP7 JqRGJ^I{|~HBI*DD literal 0 HcmV?d00001 From 7d09a5cd980bd4f9610c6aa8a322b0c21df5eb60 Mon Sep 17 00:00:00 2001 From: Gabriel Baker Date: Tue, 14 May 2013 06:32:17 +0100 Subject: [PATCH 4/7] fix missing ! --- PHPCI/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index b32c106f..26017d86 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -193,7 +193,7 @@ class Builder protected function executePlugins($stage) { - if ( array_key_exists($stage, $this->config) && !is_array($this->config[$stage]) ) { + if ( !array_key_exists($stage, $this->config) && !is_array($this->config[$stage]) ) { return; } From bbff78f0b0106bae1b2324d0bc986d5502205ddd Mon Sep 17 00:00:00 2001 From: Gabriel Baker Date: Tue, 14 May 2013 06:34:24 +0100 Subject: [PATCH 5/7] || --- PHPCI/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 26017d86..4a85d0fd 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -193,7 +193,7 @@ class Builder protected function executePlugins($stage) { - if ( !array_key_exists($stage, $this->config) && !is_array($this->config[$stage]) ) { + if ( !array_key_exists($stage, $this->config) || !is_array($this->config[$stage]) ) { return; } From fa32105992cc894c13d461481c7426db50e97316 Mon Sep 17 00:00:00 2001 From: Gabriel Baker Date: Tue, 14 May 2013 10:51:47 +0100 Subject: [PATCH 6/7] white space, type chekcing --- PHPCI/Model/Base/ProjectBase.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/PHPCI/Model/Base/ProjectBase.php b/PHPCI/Model/Base/ProjectBase.php index 451871e5..c60649fc 100644 --- a/PHPCI/Model/Base/ProjectBase.php +++ b/PHPCI/Model/Base/ProjectBase.php @@ -94,7 +94,7 @@ class ProjectBase extends Model { $rtn = $this->_data['id']; - + return $rtn; } @@ -102,7 +102,7 @@ class ProjectBase extends Model { $rtn = $this->_data['title']; - + return $rtn; } @@ -110,7 +110,7 @@ class ProjectBase extends Model { $rtn = $this->_data['reference']; - + return $rtn; } @@ -118,7 +118,7 @@ class ProjectBase extends Model { $rtn = $this->_data['git_key']; - + return $rtn; } @@ -126,7 +126,7 @@ class ProjectBase extends Model { $rtn = $this->_data['type']; - + return $rtn; } @@ -150,7 +150,7 @@ class ProjectBase extends Model { $this->_validateNotNull('Title', $value); $this->_validateString('Title', $value); - if($this->_data['title'] == $value) + if($this->_data['title'] === $value) { return; } @@ -164,7 +164,7 @@ class ProjectBase extends Model { $this->_validateNotNull('Reference', $value); $this->_validateString('Reference', $value); - if($this->_data['reference'] == $value) + if($this->_data['reference'] === $value) { return; } @@ -178,7 +178,7 @@ class ProjectBase extends Model { $this->_validateNotNull('GitKey', $value); $this->_validateString('GitKey', $value); - if($this->_data['git_key'] == $value) + if($this->_data['git_key'] === $value) { return; } @@ -192,7 +192,7 @@ class ProjectBase extends Model { $this->_validateNotNull('Type', $value); $this->_validateString('Type', $value); - if($this->_data['type'] == $value) + if($this->_data['type'] === $value) { return; } From ec47a93e23f92495d27d74fd9c48ea63bec1c819 Mon Sep 17 00:00:00 2001 From: Gabriel Baker Date: Tue, 14 May 2013 10:54:09 +0100 Subject: [PATCH 7/7] tweak --- PHPCI/Builder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 4a85d0fd..5ac7a9b0 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -193,7 +193,8 @@ class Builder protected function executePlugins($stage) { - if ( !array_key_exists($stage, $this->config) || !is_array($this->config[$stage]) ) { + if ( !array_key_exists($stage, $this->config) || !is_array($this->config[$stage]) ) + { return; }