From 4037964d4c55c0565d0c5ed38cc09ab5afd8203a Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Tue, 14 May 2013 13:09:54 +0100 Subject: [PATCH] Adding a status indicator for each plugin on the build page, fixing ignores for PHPCPD --- PHPCI/Builder.php | 43 ++++++++++++++++++++++------ PHPCI/Controller/BuildController.php | 1 + PHPCI/Model/Base/BuildBase.php | 33 +++++++++++++++++++++ PHPCI/Plugin/PhpCpd.php | 6 ++-- PHPCI/View/Build.phtml | 35 ++++++++++++++++++++++ README.md | 4 +-- 6 files changed, 108 insertions(+), 14 deletions(-) diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index b3ff03a9..7c3c1dc1 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -14,6 +14,7 @@ class Builder protected $success = true; protected $log = ''; protected $verbose = false; + protected $plugins = array(); protected $build; public function __construct(Build $build) @@ -61,6 +62,7 @@ class Builder $this->build->setFinished(new \DateTime()); $this->build->setLog($this->log); + $this->build->setPlugins(json_encode($this->plugins)); $this->store->save($this->build); } @@ -103,6 +105,7 @@ class Builder } $this->build->setLog($this->log); + $this->build->setPlugins(json_encode($this->plugins)); $this->build = $this->store->save($this->build); } @@ -198,9 +201,14 @@ class Builder { $this->logFailure('Plugin does not exist: ' . $plugin); - if($stage == 'test' && !$options['allow_failures']) + if($stage == 'test') { - $this->success = false; + $this->plugins[$plugin] = false; + + if(!$options['allow_failures']) + { + $this->success = false; + } } continue; @@ -208,13 +216,18 @@ class Builder try { - $plugin = new $class($this, $options); + $obj = new $class($this, $options); - if(!$plugin->execute()) + if(!$obj->execute()) { - if($stage == 'test' && !$options['allow_failures']) + if($stage == 'test') { - $this->success = false; + $this->plugins[$plugin] = false; + + if(!$options['allow_failures']) + { + $this->success = false; + } } $this->logFailure('PLUGIN STATUS: FAILED'); @@ -225,13 +238,25 @@ class Builder { $this->logFailure('EXCEPTION: ' . $ex->getMessage()); - if($stage == 'test' && !$options['allow_failures']) + if($stage == 'test') { - $this->success = false; - continue; + $this->plugins[$plugin] = false; + + if(!$options['allow_failures']) + { + $this->success = false; + } } + + $this->logFailure('PLUGIN STATUS: FAILED'); + continue; } + if($stage == 'test') + { + $this->plugins[$plugin] = true; + } + $this->logSuccess('PLUGIN STATUS: SUCCESS!'); } } diff --git a/PHPCI/Controller/BuildController.php b/PHPCI/Controller/BuildController.php index 2552c2dd..d508b183 100644 --- a/PHPCI/Controller/BuildController.php +++ b/PHPCI/Controller/BuildController.php @@ -35,6 +35,7 @@ class BuildController extends b8\Controller $data = array(); $data['status'] = (int)$build->getStatus(); $data['log'] = $this->cleanLog($build->getLog()); + $data['plugins'] = json_decode($build->getPlugins(), true); $data['created'] = !is_null($build->getCreated()) ? $build->getCreated()->format('Y-m-d H:i:s') : null; $data['started'] = !is_null($build->getStarted()) ? $build->getStarted()->format('Y-m-d H:i:s') : null; $data['finished'] = !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : null; diff --git a/PHPCI/Model/Base/BuildBase.php b/PHPCI/Model/Base/BuildBase.php index fb9987d5..81e27d4f 100644 --- a/PHPCI/Model/Base/BuildBase.php +++ b/PHPCI/Model/Base/BuildBase.php @@ -25,6 +25,7 @@ class BuildBase extends Model 'created' => null, 'started' => null, 'finished' => null, + 'plugins' => null, ); protected $_getters = array( 'id' => 'getId', @@ -36,6 +37,7 @@ class BuildBase extends Model 'created' => 'getCreated', 'started' => 'getStarted', 'finished' => 'getFinished', + 'plugins' => 'getPlugins', 'Project' => 'getProject', @@ -51,6 +53,7 @@ class BuildBase extends Model 'created' => 'setCreated', 'started' => 'setStarted', 'finished' => 'setFinished', + 'plugins' => 'setPlugins', 'Project' => 'setProject', ); @@ -126,6 +129,14 @@ class BuildBase extends Model + ), + 'plugins' => array( + 'type' => 'text', + 'length' => '', + 'nullable' => true, + + + ), ); public $indexes = array( @@ -229,6 +240,14 @@ class BuildBase extends Model return $rtn; } + public function getPlugins() + { + $rtn = $this->_data['plugins']; + + + return $rtn; + } + public function setId($value) @@ -357,6 +376,20 @@ class BuildBase extends Model $this->_setModified('finished'); } + public function setPlugins($value) + { + + $this->_validateString('Plugins', $value); + if($this->_data['plugins'] == $value) + { + return; + } + + $this->_data['plugins'] = $value; + + $this->_setModified('plugins'); + } + /** diff --git a/PHPCI/Plugin/PhpCpd.php b/PHPCI/Plugin/PhpCpd.php index 30d9f0ae..a57e8aa1 100644 --- a/PHPCI/Plugin/PhpCpd.php +++ b/PHPCI/Plugin/PhpCpd.php @@ -21,12 +21,12 @@ class PhpCpd implements \PHPCI\Plugin { $ignore = array_map(function($item) { - return ' --exclude ' . (substr($item, -1) == '/' ? $item . '' : $item . '/'); + return ' --exclude ' . (substr($item, -1) == '/' ? substr($item, 0, -1) : $item); }, $this->phpci->ignore); - $ignore = ' ' . implode('', $ignore); + $ignore = implode('', $ignore); } - return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpcpd ' . $ignore . ' ' . $this->phpci->buildPath); + return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpcpd' . $ignore . ' ' . $this->phpci->buildPath); } } \ No newline at end of file diff --git a/PHPCI/View/Build.phtml b/PHPCI/View/Build.phtml index 8cae9be2..0ff07932 100644 --- a/PHPCI/View/Build.phtml +++ b/PHPCI/View/Build.phtml @@ -17,6 +17,17 @@ + + + + + + + + + + +
Plugin Status
@@ -125,6 +136,30 @@ setInterval(function() $('#finished').text('Not finished yet.'); } + if(data.plugins) + { + $('#plugins').empty(); + + for(var plugin in data.plugins) + { + var row = $('').addClass(data.plugins[plugin] ? 'success' : 'error'); + var name = $('').html('' + plugin + ''); + var status = $('').text(data.plugins[plugin] ? 'OK' : 'Failed'); + + row.append(name); + row.append(status); + $('#plugins').append(row); + } + } + else + { + var row = $(''); + var col = $('').attr('colspan', 2).text('No plugins have run yet.'); + + row.append(col); + $('#plugins').empty().append(row); + } + $('#log').html(data.log); } diff --git a/README.md b/README.md index 4b07c7c9..082b93a4 100644 --- a/README.md +++ b/README.md @@ -76,8 +76,8 @@ Similar to Travis CI, to support PHPCI in your project, you simply need to add a action: "install" ignore: - - "vendor/" - - "tests/" + - "vendor" + - "tests" test: php_unit: