diff --git a/PHPCI/Application.php b/PHPCI/Application.php index 3378a050..bfae830c 100755 --- 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,20 +24,14 @@ 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: $sessionAction = ($this->controllerName == 'Session' && in_array($this->action, array('login', 'logout'))); - $externalAction = in_array($this->controllerName, array('Bitbucket', 'Github', 'BuildStatus')); + $externalAction = in_array($this->controllerName, array('Bitbucket', 'Github', 'Gitlab', 'BuildStatus')); $skipValidation = ($externalAction || $sessionAction); if($skipValidation || $this->validateSession()) { - if ( !empty($_SESSION['user']) ) { - Registry::getInstance()->set('user', $_SESSION['user']); - } parent::handleRequest(); } @@ -72,7 +65,7 @@ class Application extends b8\Application $this->response->setContent(''); } else { $this->response = new RedirectResponse($this->response); - $this->response->setHeader('Location', '/session/login'); + $this->response->setHeader('Location', PHPCI_URL.'session/login'); } return false; diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index f943a092..b8979452 100755 --- 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 100755 --- 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 100755 --- 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/GitlabController.php b/PHPCI/Controller/GitlabController.php new file mode 100644 index 00000000..f3c1dd35 --- /dev/null +++ b/PHPCI/Controller/GitlabController.php @@ -0,0 +1,61 @@ +, Dan Cryer +* @package PHPCI +* @subpackage Web +*/ +class GitlabController extends \PHPCI\Controller +{ + public function init() + { + $this->_buildStore = Store\Factory::getStore('Build'); + } + + /** + * Called by Gitlab Webhooks: + */ + public function webhook($project) + { + $payload = json_decode(file_get_contents("php://input"), true); + + try { + $build = new Build(); + $build->setProjectId($project); + $build->setCommitId($payload['after']); + $build->setStatus(0); + $build->setLog(''); + $build->setCreated(new \DateTime()); + $build->setBranch(str_replace('refs/heads/', '', $payload['ref'])); + } catch (\Exception $ex) { + header('HTTP/1.1 400 Bad Request'); + header('Ex: ' . $ex->getMessage()); + die('FAIL'); + } + + try { + $build = $this->_buildStore->save($build); + $build->sendStatusPostback(); + } catch (\Exception $ex) { + header('HTTP/1.1 500 Internal Server Error'); + header('Ex: ' . $ex->getMessage()); + die('FAIL'); + } + + die('OK'); + } +} diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index eaad90a1..3406cbd6 100755 --- 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)) { @@ -263,13 +262,15 @@ class ProjectController extends \PHPCI\Controller $field->setPattern('^(github|bitbucket|remote|local)'); $field->setOptions($options); $field->setLabel('Where is your project hosted?'); - $field->setClass('span4'); + $field->setClass('form-control'); + $field->setContainerClass('form-group'); $form->addField($field); if (isset($_SESSION['github_token'])) { $field = new Form\Element\Select('github'); $field->setLabel('Choose a Github repository:'); - $field->setClass('span4'); + $field->setClass('form-control'); + $field->setContainerClass('form-group'); $field->setOptions($this->getGithubRepositories()); $form->addField($field); } @@ -303,24 +304,28 @@ class ProjectController extends \PHPCI\Controller $field->setRequired(true); $field->setValidator($referenceValidator); $field->setLabel('Repository Name / URL (Remote) or Path (Local)'); - $field->setClass('span4'); + $field->setClass('form-control'); + $field->setContainerClass('form-group'); $form->addField($field); $field = new Form\Element\Text('title'); $field->setRequired(true); $field->setLabel('Project Title'); - $field->setClass('span4'); + $field->setClass('form-control'); + $field->setContainerClass('form-group'); $form->addField($field); $field = new Form\Element\TextArea('key'); $field->setRequired(false); $field->setLabel('Private key to use to access repository (leave blank for local and/or anonymous remotes)'); - $field->setClass('span7'); + $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'); $field->setClass('btn-success'); $form->addField($field); diff --git a/PHPCI/Controller/SessionController.php b/PHPCI/Controller/SessionController.php index 214f9921..06773305 100755 --- a/PHPCI/Controller/SessionController.php +++ b/PHPCI/Controller/SessionController.php @@ -21,7 +21,7 @@ class SessionController extends \PHPCI\Controller { public function init() { - $this->response->disableLayout(); + $this->response->disableLayout(); $this->_userStore = b8\Store\Factory::getStore('User'); } @@ -29,7 +29,7 @@ class SessionController extends \PHPCI\Controller * Handles user login (form and processing) */ public function login() - { + { if ($this->request->getMethod() == 'POST') { $user = $this->_userStore->getByEmail($this->getParam('email')); @@ -42,22 +42,24 @@ class SessionController extends \PHPCI\Controller $form = new b8\Form(); $form->setMethod('POST'); - $form->setAction('/session/login'); + $form->setAction(PHPCI_URL.'session/login'); $email = new b8\Form\Element\Email('email'); $email->setLabel('Email Address'); $email->setRequired(true); - $email->setClass('span3'); + $email->setContainerClass('form-group'); + $email->setClass('form-control'); $form->addField($email); $pwd = new b8\Form\Element\Password('password'); $pwd->setLabel('Password'); $pwd->setRequired(true); - $pwd->setClass('span3'); + $pwd->setContainerClass('form-group'); + $pwd->setClass('form-control'); $form->addField($pwd); $pwd = new b8\Form\Element\Submit(); - $pwd->setValue('Login »'); + $pwd->setValue('Log in »'); $pwd->setClass('btn-success'); $form->addField($pwd); diff --git a/PHPCI/Controller/UserController.php b/PHPCI/Controller/UserController.php index 402c8792..c866fc52 100755 --- 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; @@ -130,31 +129,35 @@ class UserController extends \PHPCI\Controller { $form = new Form(); $form->setMethod('POST'); - $form->setAction('/user/' . $type); + $form->setAction(PHPCI_URL.'user/' . $type); $form->addField(new Form\Element\Csrf('csrf')); $field = new Form\Element\Email('email'); $field->setRequired(true); $field->setLabel('Email Address'); - $field->setClass('span4'); + $field->setClass('form-control'); + $field->setContainerClass('form-group'); $form->addField($field); $field = new Form\Element\Text('name'); $field->setRequired(true); $field->setLabel('Name'); - $field->setClass('span4'); + $field->setClass('form-control'); + $field->setContainerClass('form-group'); $form->addField($field); $field = new Form\Element\Password('password'); $field->setRequired(true); $field->setLabel('Password' . ($type == 'edit' ? ' (leave blank to keep current password)' : '')); - $field->setClass('span4'); + $field->setClass('form-control'); + $field->setContainerClass('form-group'); $form->addField($field); $field = new Form\Element\Checkbox('admin'); $field->setRequired(false); $field->setCheckedValue(1); $field->setLabel('Is this user an administrator?'); + $field->setContainerClass('form-group'); $form->addField($field); $field = new Form\Element\Submit(); diff --git a/PHPCI/Helper/Build.php b/PHPCI/Helper/Build.php new file mode 100644 index 00000000..3aa7403f --- /dev/null +++ b/PHPCI/Helper/Build.php @@ -0,0 +1,24 @@ + + * @package PHPCI + * @subpackage Web + */ +class Build +{ + public function formatPluginName($name) + { + return str_replace('Php', 'PHP', ucwords(str_replace('_', ' ', $name))); + } +} diff --git a/PHPCI/Model/Base/BuildBase.php b/PHPCI/Model/Base/BuildBase.php index e051aac4..b681c110 100755 --- 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 100755 --- 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 100755 --- 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 100755 --- 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 100755 --- 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/Plugin/Grunt.php b/PHPCI/Plugin/Grunt.php new file mode 100644 index 00000000..892d8303 --- /dev/null +++ b/PHPCI/Plugin/Grunt.php @@ -0,0 +1,56 @@ + +* @package PHPCI +* @subpackage Plugins +*/ +class Grunt implements \PHPCI\Plugin +{ + protected $directory; + protected $task; + protected $preferDist; + protected $phpci; + protected $grunt; + protected $gruntfile; + + public function __construct(\PHPCI\Builder $phpci, array $options = array()) + { + $path = $phpci->buildPath; + $this->phpci = $phpci; + $this->directory = isset($options['directory']) ? $path . '/' . $options['directory'] : $path; + $this->task = isset($options['task']) ? $options['task'] : null; + $this->grunt = isset($options['grunt']) ? $options['grunt'] : 'grunt'; + $this->gruntfile = isset($options['gruntfile']) ? $options['gruntfile'] : 'Gruntfile.js'; + } + + /** + * Executes grunt and runs a specified command (e.g. install / update) + */ + public function execute() + { + // if npm does not work, we cannot use grunt, so we return false + if ( !$this->phpci->executeCommand( 'cd %s && npm install', $this->directory ) ) { + return false; + } + + // build the grunt command + $cmd = 'cd %s && ' . $this->grunt; + $cmd .= ' --no-color'; + $cmd .= ' --gruntfile %s'; + $cmd .= ' %s'; // the task that will be executed + + // and execute it + return $this->phpci->executeCommand($cmd, $this->directory, $this->gruntfile, $this->task); + } +} diff --git a/PHPCI/Plugin/Pdepend.php b/PHPCI/Plugin/Pdepend.php new file mode 100644 index 00000000..95a7a8c0 --- /dev/null +++ b/PHPCI/Plugin/Pdepend.php @@ -0,0 +1,104 @@ + + * @package PHPCI + * @subpackage Plugins + */ +class Pdepend implements \PHPCI\Plugin +{ + protected $args; + /** + * @var \PHPCI\Builder + */ + protected $phpci; + /** + * @var string Directory which needs to be scanned + */ + protected $directory; + /** + * @var string File where the summary.xml is stored + */ + protected $summary; + /** + * @var string File where the chart.svg is stored + */ + protected $chart; + /** + * @var string File where the pyramid.svg is stored + */ + protected $pyramid; + /** + * @var string Location on the server where the files are stored. Preferably in the webroot for inclusion + * in the readme.md of the repository + */ + protected $location; + + + public function __construct(\PHPCI\Builder $phpci, array $options = array()) + { + $this->phpci = $phpci; + + $this->directory = isset($options['directory']) ? $options['directory'] : $phpci->buildPath; + + $this->summary = $phpci->getBuildProjectTitle() . '-summary.xml'; + $this->pyramid = $phpci->getBuildProjectTitle() . '-pyramid.svg'; + $this->chart = $phpci->getBuildProjectTitle() . '-chart.svg'; + $this->location = $this->phpci->buildPath . '..' . DIRECTORY_SEPARATOR . 'pdepend'; + } + + /** + * Runs Pdepend with the given criteria as arguments + */ + public function execute() + { + if (!is_writable($this->location)) { + throw new \Exception(sprintf('The location %s is not writable.', $this->location)); + } + + $cmd = PHPCI_BIN_DIR . 'pdepend --summary-xml=%s --jdepend-chart=%s --overview-pyramid=%s "%s"'; + + //Remove the created files first + unlink($this->location . DIRECTORY_SEPARATOR . $this->summary); + unlink($this->location . DIRECTORY_SEPARATOR . $this->chart); + unlink($this->location . DIRECTORY_SEPARATOR . $this->pyramid); + + $success = $this->phpci->executeCommand( + $cmd, + $this->location . DIRECTORY_SEPARATOR . $this->summary, + $this->location . DIRECTORY_SEPARATOR . $this->chart, + $this->location . DIRECTORY_SEPARATOR . $this->pyramid, + $this->directory + ); + + $config = $this->phpci->getSystemConfig('phpci'); + + if ($success) { + $this->phpci->logSuccess( + sprintf( + "Pdepend successful. You can use %s\n, ![Chart](%s \"Pdepend Chart\")\n + and ![Pyramid](%s \"Pdepend Pyramid\")\n + for inclusion in the readme.md file", + $config['url'] . '/build/pdepend/' . $this->summary, + $config['url'] . '/build/pdepend/' . $this->chart, + $config['url'] . '/build/pdepend/' . $this->pyramid + ) + ); + } else { + $this->phpci->logFailure(sprintf("The function '%s' failed")); + } + + + return $success; + } +} \ No newline at end of file diff --git a/PHPCI/Plugin/PhpCodeSniffer.php b/PHPCI/Plugin/PhpCodeSniffer.php index 4c3c2680..8e28fd22 100755 --- a/PHPCI/Plugin/PhpCodeSniffer.php +++ b/PHPCI/Plugin/PhpCodeSniffer.php @@ -26,6 +26,8 @@ class PhpCodeSniffer implements \PHPCI\Plugin $this->phpci = $phpci; $this->directory = isset($options['directory']) ? $options['directory'] : $phpci->buildPath; $this->standard = isset($options['standard']) ? $options['standard'] : 'PSR2'; + $this->tab_width = isset($options['tab_width']) ? $options['tab_width'] : ''; + $this->encoding = isset($options['encoding']) ? $options['encoding'] : ''; } /** @@ -39,7 +41,27 @@ class PhpCodeSniffer implements \PHPCI\Plugin $ignore = ' --ignore=' . implode(',', $this->phpci->ignore); } - $cmd = PHPCI_BIN_DIR . 'phpcs --standard=%s %s "%s"'; - return $this->phpci->executeCommand($cmd, $this->standard, $ignore, $this->phpci->buildPath); + $standard = ''; + + if (strpos($this->standard, '/') !== false) { + $standard = ' --standard='.$this->directory.$this->standard; + } else { + $standard = ' --standard='.$this->standard; + } + + $tab_width = ''; + + if (strlen($this->tab_width)) { + $tab_width = ' --tab-width='.$this->tab_width; + } + + $encoding = ''; + + if (strlen($this->encoding)) { + $encoding = ' --encoding='.$this->encoding; + } + + $cmd = PHPCI_BIN_DIR . 'phpcs %s %s %s %s "%s"'; + return $this->phpci->executeCommand($cmd, $standard, $ignore, $tab_width, $encoding, $this->phpci->buildPath); } } diff --git a/PHPCI/Plugin/PhpLoc.php b/PHPCI/Plugin/PhpLoc.php new file mode 100644 index 00000000..0ae62200 --- /dev/null +++ b/PHPCI/Plugin/PhpLoc.php @@ -0,0 +1,52 @@ + + * @package PHPCI + * @subpackage Plugins + */ +class PhpLoc implements \PHPCI\Plugin +{ + /** + * @var string + */ + protected $directory; + /** + * @var \PHPCI\Builder + */ + protected $phpci; + + public function __construct(\PHPCI\Builder $phpci, array $options = array()) + { + $this->phpci = $phpci; + $this->directory = isset($options['directory']) ? $options['directory'] : $phpci->buildPath; + } + + /** + * Runs PHP Copy/Paste Detector in a specified directory. + */ + public function execute() + { + $ignore = ''; + if (count($this->phpci->ignore)) { + $map = function ($item) { + return ' --exclude ' . (substr($item, -1) == '/' ? substr($item, 0, -1) : $item); + }; + $ignore = array_map($map, $this->phpci->ignore); + + $ignore = implode('', $ignore); + } + + return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phploc %s "%s"', $ignore, $this->phpci->buildPath); + } +} \ No newline at end of file diff --git a/PHPCI/View/Build/view.phtml b/PHPCI/View/Build/view.phtml index f57a1a45..25ea8809 100755 --- a/PHPCI/View/Build/view.phtml +++ b/PHPCI/View/Build/view.phtml @@ -4,21 +4,20 @@
-
-
-
-
+
diff --git a/PHPCI/View/BuildsTable.phtml b/PHPCI/View/BuildsTable.phtml index 34a5ca72..98cdce91 100755 --- a/PHPCI/View/BuildsTable.phtml +++ b/PHPCI/View/BuildsTable.phtml @@ -10,7 +10,7 @@ switch($build->getStatus()) { case 0: - $cls = 'info'; + $cls = 'active'; $subcls = 'info'; $status = 'Pending'; @@ -29,8 +29,8 @@ switch($build->getStatus()) break; case 3: - $cls = 'error'; - $subcls = 'important'; + $cls = 'danger'; + $subcls = 'danger'; $status = 'Failed'; break; } @@ -48,28 +48,20 @@ switch($build->getStatus()) $plugins = array(); } if ( 0 === count($plugins) ) { - ?> - - - - $pluginstatus): - $subcls = $pluginstatus?'label label-success':'label label-important'; - ?> - - - - + $subcls = $pluginstatus?'label label-success':'label label-danger'; + ?> Build()->formatPluginName($plugin); ?>
- \ No newline at end of file + diff --git a/PHPCI/View/Index/index.phtml b/PHPCI/View/Index/index.phtml index 903b0bc2..e642b62e 100755 --- a/PHPCI/View/Index/index.phtml +++ b/PHPCI/View/Index/index.phtml @@ -2,14 +2,15 @@

Dashboard

-
-
-
-
+ +
+

Project Overview

- View + View User()->getIsAdmin()): ?> -
@@ -49,7 +50,7 @@ - + @@ -66,7 +67,7 @@ - + diff --git a/PHPCI/View/Project/view.phtml b/PHPCI/View/Project/view.phtml index 77d488fc..3067f5ed 100755 --- a/PHPCI/View/Project/view.phtml +++ b/PHPCI/View/Project/view.phtml @@ -3,13 +3,13 @@
-
-
-
-
+
Last Success Last Failure Success/Failures
Commit Branch Status
@@ -49,7 +48,7 @@ - + @@ -59,7 +58,7 @@
    '; + print '
      '; $pages = ceil($total / 10); $pages = $pages == 0 ? 1 : $pages; diff --git a/PHPCI/View/ProjectForm.phtml b/PHPCI/View/ProjectForm.phtml index f59a461b..f5c43e77 100755 --- a/PHPCI/View/ProjectForm.phtml +++ b/PHPCI/View/ProjectForm.phtml @@ -3,7 +3,7 @@
    -
    +

    To make it easier to get started, we've generated a public / private key pair for you to use for this project. To use it, just add the following public key to the "deploy keys" section of your repository settings on Github / Bitbucket.

    @@ -16,7 +16,7 @@
    -
    +
    @@ -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/Session/login.phtml b/PHPCI/View/Session/login.phtml index 4d48892e..168d9625 100755 --- a/PHPCI/View/Session/login.phtml +++ b/PHPCI/View/Session/login.phtml @@ -1,7 +1,7 @@ - Log in + Log in to PHPCI @@ -11,39 +11,77 @@
    +
    - +
    diff --git a/PHPCI/View/SummaryTable.phtml b/PHPCI/View/SummaryTable.phtml index de374e2c..d927e6af 100644 --- a/PHPCI/View/SummaryTable.phtml +++ b/PHPCI/View/SummaryTable.phtml @@ -60,12 +60,12 @@ foreach($projects as $projectId => $project): switch($project['lastbuildstatus']) { case 0: - $cls = 'info'; + $cls = 'active'; $status = 'Pending'; break; case 1: - $cls = 'warning'; + $cls = 'danger'; $status = 'Running'; break; @@ -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 ? 'danger': ($project['successes'] < $project['count']? 'warning': 'success')); ?>
- + - \ No newline at end of file + diff --git a/PHPCI/View/User/index.phtml b/PHPCI/View/User/index.phtml index 9ac17fe7..aacffcf0 100755 --- a/PHPCI/View/User/index.phtml +++ b/PHPCI/View/User/index.phtml @@ -3,25 +3,23 @@
-
-
-
-
+
Commit Branch Status
@@ -109,6 +109,6 @@ foreach($projects as $projectId => $project): /buildbuild now »
- + @@ -47,8 +45,8 @@
Email Address Name Administrator
User()->getIsAdmin()): ?>
- Edit -
-
\ No newline at end of file +
diff --git a/PHPCI/View/UserForm.phtml b/PHPCI/View/UserForm.phtml index c99a3cfd..007dbae5 100755 --- a/PHPCI/View/UserForm.phtml +++ b/PHPCI/View/UserForm.phtml @@ -3,7 +3,7 @@
-
+

Fill in the form to the right to add a new user.

@@ -12,7 +12,7 @@
-
+
\ No newline at end of file diff --git a/PHPCI/View/layout.phtml b/PHPCI/View/layout.phtml index 2db749d3..7dda7489 100755 --- a/PHPCI/View/layout.phtml +++ b/PHPCI/View/layout.phtml @@ -15,19 +15,27 @@