diff --git a/PHPCI/Application.php b/PHPCI/Application.php index 3378a050..e7ce142b 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -10,7 +10,6 @@ namespace PHPCI; use b8; -use b8\Registry; use b8\Http\Response\RedirectResponse; use b8\View; @@ -25,9 +24,6 @@ class Application extends b8\Application */ public function handleRequest() { - // Registry legacy: - $registry = new b8\Registry($this->config, $this->request); - $this->initRequest(); // Validate the user's session unless it is a login/logout action or a web hook: @@ -36,9 +32,6 @@ class Application extends b8\Application $skipValidation = ($externalAction || $sessionAction); if($skipValidation || $this->validateSession()) { - if ( !empty($_SESSION['user']) ) { - Registry::getInstance()->set('user', $_SESSION['user']); - } parent::handleRequest(); } diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index f943a092..b8979452 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -11,7 +11,7 @@ namespace PHPCI; use PHPCI\Model\Build; use b8\Store; -use Symfony\Component\Yaml\Parser as YamlParser; +use b8\Config; /** * PHPCI Build Runner @@ -123,7 +123,7 @@ class Builder */ public function getSystemConfig($key) { - return \b8\Registry::getInstance()->get($key); + return Config::getInstance()->get($key); } /** @@ -319,7 +319,7 @@ class Builder { $commitId = $this->build->getCommitId(); $buildId = 'project' . $this->build->getProject()->getId() . '-build' . $this->build->getId(); - $this->ciDir = realpath(dirname(__FILE__) . '/../') . '/'; + $this->ciDir = dirname(__FILE__) . '/../'; $this->buildPath = $this->ciDir . 'build/' . $buildId . '/'; $this->setInterpolationVars(); diff --git a/PHPCI/Controller/BuildController.php b/PHPCI/Controller/BuildController.php index 56bde07c..b907b9bc 100644 --- a/PHPCI/Controller/BuildController.php +++ b/PHPCI/Controller/BuildController.php @@ -10,7 +10,6 @@ namespace PHPCI\Controller; use b8; -use b8\Registry; use PHPCI\Model\Build; /** diff --git a/PHPCI/Controller/GithubController.php b/PHPCI/Controller/GithubController.php index 90bc37fe..71ae0e3b 100644 --- a/PHPCI/Controller/GithubController.php +++ b/PHPCI/Controller/GithubController.php @@ -41,6 +41,11 @@ class GithubController extends \PHPCI\Controller $build->setLog(''); $build->setCreated(new \DateTime()); $build->setBranch(str_replace('refs/heads/', '', $payload['ref'])); + + if (!empty($payload['pusher']['email'])) { + $build->setCommitterEmail($payload['pusher']['email']); + } + } catch (\Exception $ex) { header('HTTP/1.1 400 Bad Request'); header('Ex: ' . $ex->getMessage()); diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index eaad90a1..47894266 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -15,7 +15,6 @@ use b8; use b8\Controller; use b8\Store; use b8\Form; -use b8\Registry; /** * Project Controller - Allows users to create, edit and view projects. @@ -175,7 +174,7 @@ class ProjectController extends \PHPCI\Controller */ protected function handleGithubResponse() { - $github = \b8\Registry::getInstance()->get('github_app'); + $github = \b8\Config::getInstance()->get('phpci.github'); $code = $this->getParam('code', null); if (!is_null($code)) { diff --git a/PHPCI/Controller/UserController.php b/PHPCI/Controller/UserController.php index 402c8792..0a814b9c 100644 --- a/PHPCI/Controller/UserController.php +++ b/PHPCI/Controller/UserController.php @@ -10,7 +10,6 @@ namespace PHPCI\Controller; use b8; -use b8\Registry; use PHPCI\Model\User; use b8\Form; diff --git a/PHPCI/Model/Base/BuildBase.php b/PHPCI/Model/Base/BuildBase.php index e051aac4..b681c110 100644 --- a/PHPCI/Model/Base/BuildBase.php +++ b/PHPCI/Model/Base/BuildBase.php @@ -42,6 +42,7 @@ class BuildBase extends Model 'started' => null, 'finished' => null, 'plugins' => null, + 'committer_email' => null, ); /** @@ -58,6 +59,7 @@ class BuildBase extends Model 'started' => 'getStarted', 'finished' => 'getFinished', 'plugins' => 'getPlugins', + 'committer_email' => 'getCommitterEmail', 'Project' => 'getProject', ); @@ -75,6 +77,7 @@ class BuildBase extends Model 'started' => 'setStarted', 'finished' => 'setFinished', 'plugins' => 'setPlugins', + 'committer_email' => 'setCommitterEmail', 'Project' => 'setProject', ); @@ -129,6 +132,11 @@ class BuildBase extends Model 'length' => '', 'nullable' => true, ), + 'committer_email' => array( + 'type' => 'varchar', + 'length' => '512', + 'nullable' => true, + ), ); /** @@ -299,6 +307,19 @@ class BuildBase extends Model return $rtn; } + /** + * Get the value of CommitterEmail / committer_email. + * + * @return string + */ + public function getCommitterEmail() + { + $rtn = $this->data['committer_email']; + + + return $rtn; + } + /** * Set the value of Id / id. * @@ -309,7 +330,7 @@ class BuildBase extends Model { $this->_validateNotNull('Id', $value); $this->_validateInt('Id', $value); - if ($this->data['id'] === $value) { + if ($this->data['id'] == $value) { return; } @@ -328,7 +349,7 @@ class BuildBase extends Model { $this->_validateNotNull('ProjectId', $value); $this->_validateInt('ProjectId', $value); - if ($this->data['project_id'] === $value) { + if ($this->data['project_id'] == $value) { return; } @@ -347,7 +368,7 @@ class BuildBase extends Model { $this->_validateNotNull('CommitId', $value); $this->_validateString('CommitId', $value); - if ($this->data['commit_id'] === $value) { + if ($this->data['commit_id'] == $value) { return; } @@ -366,7 +387,7 @@ class BuildBase extends Model { $this->_validateNotNull('Status', $value); $this->_validateInt('Status', $value); - if ($this->data['status'] === $value) { + if ($this->data['status'] == $value) { return; } @@ -384,7 +405,7 @@ class BuildBase extends Model { $this->_validateString('Log', $value); - if ($this->data['log'] === $value) { + if ($this->data['log'] == $value) { return; } @@ -403,7 +424,7 @@ class BuildBase extends Model { $this->_validateNotNull('Branch', $value); $this->_validateString('Branch', $value); - if ($this->data['branch'] === $value) { + if ($this->data['branch'] == $value) { return; } @@ -421,7 +442,7 @@ class BuildBase extends Model { $this->_validateDate('Created', $value); - if ($this->data['created'] === $value) { + if ($this->data['created'] == $value) { return; } @@ -439,7 +460,7 @@ class BuildBase extends Model { $this->_validateDate('Started', $value); - if ($this->data['started'] === $value) { + if ($this->data['started'] == $value) { return; } @@ -457,7 +478,7 @@ class BuildBase extends Model { $this->_validateDate('Finished', $value); - if ($this->data['finished'] === $value) { + if ($this->data['finished'] == $value) { return; } @@ -475,7 +496,7 @@ class BuildBase extends Model { $this->_validateString('Plugins', $value); - if ($this->data['plugins'] === $value) { + if ($this->data['plugins'] == $value) { return; } @@ -484,6 +505,24 @@ class BuildBase extends Model $this->_setModified('plugins'); } + /** + * Set the value of CommitterEmail / committer_email. + * + * @param $value string + */ + public function setCommitterEmail($value) + { + + $this->_validateString('CommitterEmail', $value); + if ($this->data['committer_email'] == $value) { + return; + } + + $this->data['committer_email'] = $value; + + $this->_setModified('committer_email'); + } + /** * Get the Project model for this Build by Id. * diff --git a/PHPCI/Model/Base/ProjectBase.php b/PHPCI/Model/Base/ProjectBase.php index 45481dd5..c9d577af 100644 --- a/PHPCI/Model/Base/ProjectBase.php +++ b/PHPCI/Model/Base/ProjectBase.php @@ -199,7 +199,7 @@ class ProjectBase extends Model { $this->_validateNotNull('Id', $value); $this->_validateInt('Id', $value); - if ($this->data['id'] === $value) { + if ($this->data['id'] == $value) { return; } @@ -218,7 +218,7 @@ class ProjectBase extends Model { $this->_validateNotNull('Title', $value); $this->_validateString('Title', $value); - if ($this->data['title'] === $value) { + if ($this->data['title'] == $value) { return; } @@ -237,7 +237,7 @@ class ProjectBase extends Model { $this->_validateNotNull('Reference', $value); $this->_validateString('Reference', $value); - if ($this->data['reference'] === $value) { + if ($this->data['reference'] == $value) { return; } @@ -256,7 +256,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; } @@ -275,7 +275,7 @@ class ProjectBase extends Model { $this->_validateNotNull('Type', $value); $this->_validateString('Type', $value); - if ($this->data['type'] === $value) { + if ($this->data['type'] == $value) { return; } @@ -293,7 +293,7 @@ class ProjectBase extends Model { $this->_validateString('Token', $value); - if ($this->data['token'] === $value) { + if ($this->data['token'] == $value) { return; } diff --git a/PHPCI/Model/Base/UserBase.php b/PHPCI/Model/Base/UserBase.php index 7ce2759c..aab1e21b 100644 --- a/PHPCI/Model/Base/UserBase.php +++ b/PHPCI/Model/Base/UserBase.php @@ -179,7 +179,7 @@ class UserBase extends Model { $this->_validateNotNull('Id', $value); $this->_validateInt('Id', $value); - if ($this->data['id'] === $value) { + if ($this->data['id'] == $value) { return; } @@ -198,7 +198,7 @@ class UserBase extends Model { $this->_validateNotNull('Email', $value); $this->_validateString('Email', $value); - if ($this->data['email'] === $value) { + if ($this->data['email'] == $value) { return; } @@ -217,7 +217,7 @@ class UserBase extends Model { $this->_validateNotNull('Hash', $value); $this->_validateString('Hash', $value); - if ($this->data['hash'] === $value) { + if ($this->data['hash'] == $value) { return; } @@ -236,7 +236,7 @@ class UserBase extends Model { $this->_validateNotNull('IsAdmin', $value); $this->_validateInt('IsAdmin', $value); - if ($this->data['is_admin'] === $value) { + if ($this->data['is_admin'] == $value) { return; } @@ -255,7 +255,7 @@ class UserBase extends Model { $this->_validateNotNull('Name', $value); $this->_validateString('Name', $value); - if ($this->data['name'] === $value) { + if ($this->data['name'] == $value) { return; } diff --git a/PHPCI/Model/Build/GithubBuild.php b/PHPCI/Model/Build/GithubBuild.php index 35ce439b..6518da92 100644 --- a/PHPCI/Model/Build/GithubBuild.php +++ b/PHPCI/Model/Build/GithubBuild.php @@ -67,7 +67,7 @@ class GithubBuild extends RemoteGitBuild break; } - $url = \b8\Registry::getInstance()->get('install_url'); + $url = \b8\Config::getInstance()->get('phpci.url'); $params = array( 'state' => $status, 'target_url' => $url . '/build/view/' . $this->getId()); $headers = array( diff --git a/PHPCI/Model/Build/RemoteGitBuild.php b/PHPCI/Model/Build/RemoteGitBuild.php index d1fe1c74..490b92ef 100644 --- a/PHPCI/Model/Build/RemoteGitBuild.php +++ b/PHPCI/Model/Build/RemoteGitBuild.php @@ -74,7 +74,14 @@ class RemoteGitBuild extends Build protected function cloneBySsh(Builder $builder, $to) { // Copy the project's keyfile to disk: - $keyFile = realpath($to) . '.key'; + $keyPath = realpath($to); + + if ($keyPath === false) { + $keyPath = dirname($to); + } + + $keyFile = $keyPath . '.key'; + file_put_contents($keyFile, $this->getProject()->getGitKey()); chmod($keyFile, 0600); diff --git a/PHPCI/View/ProjectForm.phtml b/PHPCI/View/ProjectForm.phtml index f59a461b..e52cbd9e 100644 --- a/PHPCI/View/ProjectForm.phtml +++ b/PHPCI/View/ProjectForm.phtml @@ -25,7 +25,7 @@ window.return_url = ; get('github_app', null); +$gh = \b8\Config::getInstance()->get('phpci.github', null); if($gh) { print 'window.github_app_id = ' . json_encode($gh['id']) . ';' . PHP_EOL; diff --git a/PHPCI/View/SummaryTable.phtml b/PHPCI/View/SummaryTable.phtml index de374e2c..3db900b2 100644 --- a/PHPCI/View/SummaryTable.phtml +++ b/PHPCI/View/SummaryTable.phtml @@ -80,8 +80,8 @@ foreach($projects as $projectId => $project): break; } - $health = ($project['health'] < 0 ? 'Stormy': ($project['health'] < 5? 'Overcast': 'Sunny')); - $subcls = ($project['health'] < 0 ? 'important': ($project['health'] < 5? 'warning': 'success')); + $health = ($project['health'] <= 0 ? 'Stormy': ($project['successes'] < $project['count']? 'Overcast': 'Sunny')); + $subcls = ($project['health'] <= 0 ? 'important': ($project['successes'] < $project['count']? 'warning': 'success')); ?> diff --git a/bootstrap.php b/bootstrap.php index a2b0e8d3..9cd035e9 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -42,8 +42,6 @@ $conf['b8']['app']['default_controller'] = 'Index'; $conf['b8']['view']['path'] = dirname(__FILE__) . '/PHPCI/View/'; $config = new b8\Config($conf); -$request = new b8\Http\Request(); -$registry = new b8\Registry($config, $request); if (file_exists(APPLICATION_PATH . 'config.php')) { require(APPLICATION_PATH . 'config.php'); diff --git a/index.php b/index.php index cab4239d..b4685c7d 100644 --- a/index.php +++ b/index.php @@ -14,5 +14,5 @@ ini_set('display_errors', 'on'); require_once('bootstrap.php'); -$fc = new PHPCI\Application($config, $request); +$fc = new PHPCI\Application($config, new b8\Http\Request()); print $fc->handleRequest();