Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
0e89e39366
|
@ -10,7 +10,8 @@
|
|||
namespace PHPCI;
|
||||
|
||||
use b8;
|
||||
use b8\Registry;
|
||||
use b8\Http\Response\RedirectResponse;
|
||||
use b8\View;
|
||||
|
||||
/**
|
||||
* PHPCI Front Controller
|
||||
|
@ -18,35 +19,32 @@ use b8\Registry;
|
|||
*/
|
||||
class Application extends b8\Application
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if (isset($_SERVER['REDIRECT_PATH_INFO'])) {
|
||||
$_SERVER['REQUEST_URI'] = $_SERVER['REDIRECT_PATH_INFO'];
|
||||
}
|
||||
|
||||
return parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming web request.
|
||||
*/
|
||||
public function handleRequest()
|
||||
{
|
||||
$controllerName = \b8\Registry::getInstance()->get('ControllerName');
|
||||
// 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 = ($controllerName == 'Session' && in_array($this->action, array('login', 'logout')));
|
||||
$externalAction = in_array($controllerName, array('Bitbucket', 'Github', 'BuildStatus'));
|
||||
|
||||
if (!$externalAction && !$sessionAction) {
|
||||
$this->validateSession();
|
||||
$sessionAction = ($this->controllerName == 'Session' && in_array($this->action, array('login', 'logout')));
|
||||
$externalAction = in_array($this->controllerName, array('Bitbucket', 'Github', 'BuildStatus'));
|
||||
$skipValidation = ($externalAction || $sessionAction);
|
||||
|
||||
if($skipValidation || $this->validateSession()) {
|
||||
parent::handleRequest();
|
||||
}
|
||||
|
||||
// Render content into layout and return:
|
||||
$view = new b8\View('Layout');
|
||||
$view->content = parent::handleRequest();
|
||||
|
||||
return $view->render();
|
||||
if (View::exists('layout') && $this->response->hasLayout()) {
|
||||
$view = new View('layout');
|
||||
$view->content = $this->response->getContent();
|
||||
$this->response->setContent($view->render());
|
||||
}
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,14 +56,21 @@ class Application extends b8\Application
|
|||
$user = b8\Store\Factory::getStore('User')->getByPrimaryKey($_SESSION['user_id']);
|
||||
|
||||
if ($user) {
|
||||
Registry::getInstance()->set('user', $user);
|
||||
return;
|
||||
$_SESSION['user'] = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
unset($_SESSION['user_id']);
|
||||
}
|
||||
|
||||
header('Location: /session/login');
|
||||
die;
|
||||
if ($this->request->isAjax()) {
|
||||
$this->response->setResponseCode(401);
|
||||
$this->response->setContent('');
|
||||
} else {
|
||||
$this->response = new RedirectResponse($this->response);
|
||||
$this->response->setHeader('Location', '/session/login');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,6 +73,15 @@ class Builder
|
|||
* @var array
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* An array of key => value pairs that will be used for
|
||||
* interpolation and environment variables
|
||||
* @var array
|
||||
* @see setInterpolationVars()
|
||||
* @see getInterpolationVars()
|
||||
*/
|
||||
protected $interpolation_vars = array();
|
||||
|
||||
/**
|
||||
* Set up the builder.
|
||||
|
@ -236,7 +245,47 @@ class Builder
|
|||
{
|
||||
$this->log("\033[0;31m" . $message . "\033[0m");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array key => value pairs that are used for interpolation
|
||||
* @return array
|
||||
*/
|
||||
public function getInterpolationVars()
|
||||
{
|
||||
return $this->interpolation_vars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace every occurance of the interpolation vars in the given string
|
||||
* Example: "This is build %PHPCI_BUILD%" => "This is build 182"
|
||||
* @param string $input
|
||||
* @return string
|
||||
*/
|
||||
public function interpolate($input)
|
||||
{
|
||||
$trans_table = array();
|
||||
foreach ($this->getInterpolationVars() as $key => $value) {
|
||||
$trans_table['%'.$key.'%'] = $value;
|
||||
}
|
||||
return strtr($input, $trans_table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the variables that will be used for interpolation. This must be run
|
||||
* from setupBuild() because prior to that, we don't know the buildPath
|
||||
*/
|
||||
protected function setInterpolationVars()
|
||||
{
|
||||
$this->interpolation_vars = array(
|
||||
'PHPCI' => 1,
|
||||
'PHPCI_COMMIT' => $this->build->getCommitId(),
|
||||
'PHPCI_PROJECT' => $this->build->getProject()->getId(),
|
||||
'PHPCI_BUILD' => $this->build->getId(),
|
||||
'PHPCI_PROJECT_TITLE' => $this->build->getProject()->getTitle(),
|
||||
'PHPCI_BUILD_PATH' => $this->buildPath,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up a working copy of the project for building.
|
||||
*/
|
||||
|
@ -247,14 +296,13 @@ class Builder
|
|||
$this->ciDir = realpath(dirname(__FILE__) . '/../') . '/';
|
||||
$this->buildPath = $this->ciDir . 'build/' . $buildId . '/';
|
||||
|
||||
$this->setInterpolationVars();
|
||||
|
||||
// Setup environment vars that will be accessible during exec()
|
||||
putenv("PHPCI=1");
|
||||
putenv("PHPCI_COMMIT=".$commitId);
|
||||
putenv("PHPCI_PROJECT=".$this->build->getProject()->getId());
|
||||
putenv("PHPCI_BUILD=".$this->build->getId());
|
||||
putenv("PHPCI_PROJECT_TITLE=".$this->build->getProject()->getTitle());
|
||||
putenv("PHPCI_BUILD_PATH=".$this->buildPath);
|
||||
|
||||
foreach ($this->getInterpolationVars() as $key => $value) {
|
||||
putenv($key.'='.$value);
|
||||
}
|
||||
|
||||
// Create a working copy of the project:
|
||||
if (!$this->build->createWorkingCopy($this, $this->buildPath)) {
|
||||
return false;
|
||||
|
|
|
@ -63,8 +63,8 @@ b8\Database::setDetails('{$dbName}', '{$dbUser}', '{$dbPass}');
|
|||
b8\Database::setWriteServers(array('{$dbHost}'));
|
||||
b8\Database::setReadServers(array('{$dbHost}'));
|
||||
|
||||
\$registry = b8\Registry::getInstance();
|
||||
\$registry->set('install_url', '{$ciUrl}');
|
||||
\$config = b8\Config::getInstance();
|
||||
\$config->set('install_url', '{$ciUrl}');
|
||||
";
|
||||
|
||||
// Has the user entered Github app details? If so add those to config:
|
||||
|
|
54
PHPCI/Controller.php
Normal file
54
PHPCI/Controller.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCI;
|
||||
|
||||
use b8\Config;
|
||||
use b8\Http\Request;
|
||||
use b8\Http\Response;
|
||||
use b8\View;
|
||||
|
||||
class Controller extends \b8\Controller
|
||||
{
|
||||
public function init() {}
|
||||
|
||||
public function __construct(Config $config, Request $request, Response $response)
|
||||
{
|
||||
parent::__construct($config, $request, $response);
|
||||
|
||||
$class = explode('\\', get_class($this));
|
||||
$this->className = substr(array_pop($class), 0, -10);
|
||||
$this->setControllerView();
|
||||
}
|
||||
|
||||
protected function setControllerView()
|
||||
{
|
||||
if (View::exists($this->className)) {
|
||||
$this->controllerView = new View($this->className);
|
||||
} else {
|
||||
$this->controllerView = new View\UserView('{@content}');
|
||||
}
|
||||
}
|
||||
|
||||
protected function setView($action)
|
||||
{
|
||||
if (View::exists($this->className . '/' . $action)) {
|
||||
$this->view = new View($this->className . '/' . $action);
|
||||
}
|
||||
}
|
||||
|
||||
public function handleAction($action, $actionParams)
|
||||
{
|
||||
$this->setView($action);
|
||||
$response = parent::handleAction($action, $actionParams);
|
||||
|
||||
if (is_string($response)) {
|
||||
$this->controllerView->content = $response;
|
||||
} elseif (isset($this->view)) {
|
||||
$this->controllerView->content = $this->view->render();
|
||||
}
|
||||
|
||||
$this->response->setContent($this->controllerView->render());
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@ use PHPCI\Model\Build;
|
|||
* @package PHPCI
|
||||
* @subpackage Web
|
||||
*/
|
||||
class BitbucketController extends b8\Controller
|
||||
class BitbucketController extends \PHPCI\Controller
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@ use PHPCI\Model\Build;
|
|||
* @package PHPCI
|
||||
* @subpackage Web
|
||||
*/
|
||||
class BuildController extends b8\Controller
|
||||
class BuildController extends \PHPCI\Controller
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
|
@ -32,11 +32,8 @@ class BuildController extends b8\Controller
|
|||
public function view($buildId)
|
||||
{
|
||||
$build = $this->_buildStore->getById($buildId);
|
||||
$view = new b8\View('Build');
|
||||
$view->build = $build;
|
||||
$view->data = $this->getBuildData($buildId);
|
||||
|
||||
return $view->render();
|
||||
$this->view->build = $build;
|
||||
$this->view->data = $this->getBuildData($buildId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,7 @@ use PHPCI\Model\Build;
|
|||
* @package PHPCI
|
||||
* @subpackage Web
|
||||
*/
|
||||
class BuildStatusController extends b8\Controller
|
||||
class BuildStatusController extends \PHPCI\Controller
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@ use PHPCI\Model\Build;
|
|||
* @package PHPCI
|
||||
* @subpackage Web
|
||||
*/
|
||||
class GithubController extends b8\Controller
|
||||
class GithubController extends \PHPCI\Controller
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@ use b8;
|
|||
* @package PHPCI
|
||||
* @subpackage Web
|
||||
*/
|
||||
class IndexController extends b8\Controller
|
||||
class IndexController extends \PHPCI\Controller
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
|
@ -31,11 +31,16 @@ class IndexController extends b8\Controller
|
|||
public function index()
|
||||
{
|
||||
$projects = $this->_projectStore->getWhere(array(), 50, 0, array(), array('title' => 'ASC'));
|
||||
$view = new b8\View('Index');
|
||||
$view->builds = $this->getLatestBuildsHtml();
|
||||
$view->projects = $projects['items'];
|
||||
$summary = $this->_buildStore->getBuildSummary();
|
||||
|
||||
return $view->render();
|
||||
$summaryView = new b8\View('BuildsTable');
|
||||
$summaryView->builds = $summary['items'];
|
||||
|
||||
$this->view->builds = $this->getLatestBuildsHtml();
|
||||
$this->view->projects = $projects['items'];
|
||||
$this->view->summary = $summaryView->render();
|
||||
|
||||
return $this->view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +56,7 @@ class IndexController extends b8\Controller
|
|||
*/
|
||||
protected function getLatestBuildsHtml()
|
||||
{
|
||||
$builds = $this->_buildStore->getWhere(array(), 10, 0, array(), array('id' => 'DESC'));
|
||||
$builds = $this->_buildStore->getWhere(array(), 5, 0, array(), array('id' => 'DESC'));
|
||||
$view = new b8\View('BuildsTable');
|
||||
$view->builds = $builds['items'];
|
||||
|
||||
|
|
|
@ -9,9 +9,11 @@
|
|||
|
||||
namespace PHPCI\Controller;
|
||||
|
||||
use b8;
|
||||
use PHPCI\Model\Build;
|
||||
use PHPCI\Model\Project;
|
||||
use b8;
|
||||
use b8\Controller;
|
||||
use b8\Store;
|
||||
use b8\Form;
|
||||
use b8\Registry;
|
||||
|
||||
|
@ -21,12 +23,12 @@ use b8\Registry;
|
|||
* @package PHPCI
|
||||
* @subpackage Web
|
||||
*/
|
||||
class ProjectController extends b8\Controller
|
||||
class ProjectController extends \PHPCI\Controller
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->_buildStore = b8\Store\Factory::getStore('Build');
|
||||
$this->_projectStore = b8\Store\Factory::getStore('Project');
|
||||
$this->_buildStore = Store\Factory::getStore('Build');
|
||||
$this->_projectStore = Store\Factory::getStore('Project');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,13 +40,12 @@ class ProjectController extends b8\Controller
|
|||
$page = $this->getParam('p', 1);
|
||||
$builds = $this->getLatestBuildsHtml($projectId, (($page - 1) * 10));
|
||||
|
||||
$view = new b8\View('Project');
|
||||
$view->builds = $builds[0];
|
||||
$view->total = $builds[1];
|
||||
$view->project = $project;
|
||||
$view->page = $page;
|
||||
$this->view->builds = $builds[0];
|
||||
$this->view->total = $builds[1];
|
||||
$this->view->project = $project;
|
||||
$this->view->page = $page;
|
||||
|
||||
return $view->render();
|
||||
return $this->view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,7 +70,7 @@ class ProjectController extends b8\Controller
|
|||
*/
|
||||
public function delete($projectId)
|
||||
{
|
||||
if (!Registry::getInstance()->get('user')->getIsAdmin()) {
|
||||
if (!$_SESSION['user']->getIsAdmin()) {
|
||||
throw new \Exception('You do not have permission to do that.');
|
||||
}
|
||||
|
||||
|
@ -107,11 +108,11 @@ class ProjectController extends b8\Controller
|
|||
*/
|
||||
public function add()
|
||||
{
|
||||
if (!Registry::getInstance()->get('user')->getIsAdmin()) {
|
||||
if (!$_SESSION['user']->getIsAdmin()) {
|
||||
throw new \Exception('You do not have permission to do that.');
|
||||
}
|
||||
|
||||
$method = Registry::getInstance()->get('requestMethod');
|
||||
$method = $this->request->getMethod();
|
||||
$this->handleGithubResponse();
|
||||
|
||||
if ($method == 'POST') {
|
||||
|
@ -199,11 +200,11 @@ class ProjectController extends b8\Controller
|
|||
*/
|
||||
public function edit($projectId)
|
||||
{
|
||||
if (!Registry::getInstance()->get('user')->getIsAdmin()) {
|
||||
if (!$_SESSION['user']->getIsAdmin()) {
|
||||
throw new \Exception('You do not have permission to do that.');
|
||||
}
|
||||
|
||||
$method = Registry::getInstance()->get('requestMethod');
|
||||
$method = $this->request->getMethod();
|
||||
$project = $this->_projectStore->getById($projectId);
|
||||
|
||||
if ($method == 'POST') {
|
||||
|
|
|
@ -17,10 +17,11 @@ use b8;
|
|||
* @package PHPCI
|
||||
* @subpackage Web
|
||||
*/
|
||||
class SessionController extends b8\Controller
|
||||
class SessionController extends \PHPCI\Controller
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->response->disableLayout();
|
||||
$this->_userStore = b8\Store\Factory::getStore('User');
|
||||
}
|
||||
|
||||
|
@ -28,10 +29,10 @@ class SessionController extends b8\Controller
|
|||
* Handles user login (form and processing)
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
if (b8\Registry::getInstance()->get('requestMethod') == 'POST') {
|
||||
{
|
||||
if ($this->request->getMethod() == 'POST') {
|
||||
$user = $this->_userStore->getByEmail($this->getParam('email'));
|
||||
|
||||
|
||||
if ($user && password_verify($this->getParam('password', ''), $user->getHash())) {
|
||||
$_SESSION['user_id'] = $user->getId();
|
||||
header('Location: ' . PHPCI_URL);
|
||||
|
@ -60,9 +61,9 @@ class SessionController extends b8\Controller
|
|||
$pwd->setClass('btn-success');
|
||||
$form->addField($pwd);
|
||||
|
||||
$view = new b8\View('Login');
|
||||
$view->form = $form->render();
|
||||
die($view->render());
|
||||
$this->view->form = $form->render();
|
||||
|
||||
return $this->view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,7 @@ use b8\Form;
|
|||
* @package PHPCI
|
||||
* @subpackage Web
|
||||
*/
|
||||
class UserController extends b8\Controller
|
||||
class UserController extends \PHPCI\Controller
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
|
@ -33,10 +33,9 @@ class UserController extends b8\Controller
|
|||
public function index()
|
||||
{
|
||||
$users = $this->_userStore->getWhere(array(), 1000, 0, array(), array('email' => 'ASC'));
|
||||
$view = new b8\View('User');
|
||||
$view->users = $users;
|
||||
$this->view->users = $users;
|
||||
|
||||
return $view->render();
|
||||
return $this->view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,11 +43,11 @@ class UserController extends b8\Controller
|
|||
*/
|
||||
public function add()
|
||||
{
|
||||
if (!Registry::getInstance()->get('user')->getIsAdmin()) {
|
||||
if (!$_SESSION['user']->getIsAdmin()) {
|
||||
throw new \Exception('You do not have permission to do that.');
|
||||
}
|
||||
|
||||
$method = Registry::getInstance()->get('requestMethod');
|
||||
$method = $this->request->getMethod();
|
||||
|
||||
if ($method == 'POST') {
|
||||
$values = $this->getParams();
|
||||
|
@ -85,11 +84,11 @@ class UserController extends b8\Controller
|
|||
*/
|
||||
public function edit($userId)
|
||||
{
|
||||
if (!Registry::getInstance()->get('user')->getIsAdmin()) {
|
||||
if (!$_SESSION['user']->getIsAdmin()) {
|
||||
throw new \Exception('You do not have permission to do that.');
|
||||
}
|
||||
|
||||
$method = Registry::getInstance()->get('requestMethod');
|
||||
$method = $this->request->getMethod();
|
||||
$user = $this->_userStore->getById($userId);
|
||||
|
||||
if ($method == 'POST') {
|
||||
|
@ -172,7 +171,7 @@ class UserController extends b8\Controller
|
|||
*/
|
||||
public function delete($userId)
|
||||
{
|
||||
if (!Registry::getInstance()->get('user')->getIsAdmin()) {
|
||||
if (!$_SESSION['user']->getIsAdmin()) {
|
||||
throw new \Exception('You do not have permission to do that.');
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class User
|
|||
{
|
||||
public function __call($method, $params = array())
|
||||
{
|
||||
$user = \b8\Registry::getInstance()->get('user');
|
||||
$user = $_SESSION['user'];
|
||||
return call_user_func_array(array($user, $method), $params);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ class BuildBase extends Model
|
|||
'length' => '4',
|
||||
),
|
||||
'log' => array(
|
||||
'type' => 'text',
|
||||
'type' => 'longtext',
|
||||
'length' => '',
|
||||
'nullable' => true,
|
||||
),
|
||||
|
@ -500,11 +500,11 @@ class BuildBase extends Model
|
|||
}
|
||||
|
||||
$cacheKey = 'Cache.Project.' . $key;
|
||||
$rtn = $this->registry->get($cacheKey, null);
|
||||
$rtn = $this->cache->get($cacheKey, null);
|
||||
|
||||
if (empty($rtn)) {
|
||||
$rtn = \b8\Store\Factory::getStore('Project')->getById($key);
|
||||
$this->registry->set($cacheKey, $rtn);
|
||||
$this->cache->set($cacheKey, $rtn);
|
||||
}
|
||||
|
||||
return $rtn;
|
||||
|
|
|
@ -41,7 +41,7 @@ class Env implements \PHPCI\Plugin
|
|||
$env_var = "$key=$value";
|
||||
}
|
||||
|
||||
if (!putenv($env_var)) {
|
||||
if (!putenv($this->phpci->interpolate($env_var))) {
|
||||
$success = false;
|
||||
$this->phpci->logFailure("Unable to set environment variable");
|
||||
}
|
||||
|
|
|
@ -51,8 +51,8 @@ class Mysql implements \PHPCI\Plugin
|
|||
if (isset($buildSettings['mysql'])) {
|
||||
$sql = $buildSettings['mysql'];
|
||||
|
||||
$this->host = !empty($sql['host']) ? $sql['host'] : $this->host;
|
||||
$this->user = !empty($sql['user']) ? $sql['user'] : $this->user;
|
||||
$this->host = !empty($sql['host']) ? $sql['host'] : $this->phpci->interpolate($this->host);
|
||||
$this->user = !empty($sql['user']) ? $sql['user'] : $this->phpci->interpolate($this->user);
|
||||
$this->pass = array_key_exists('pass', $sql) ? $sql['pass'] : $this->pass;
|
||||
}
|
||||
}
|
||||
|
@ -71,10 +71,12 @@ class Mysql implements \PHPCI\Plugin
|
|||
foreach ($this->queries as $query) {
|
||||
if (!is_array($query)) {
|
||||
// Simple query
|
||||
$this->pdo->query($query);
|
||||
$this->pdo->query($this->phpci->interpolate($query));
|
||||
} else if (isset($query['import'])) {
|
||||
// SQL file execution
|
||||
$this->executeFile($query['import']);
|
||||
} else {
|
||||
throw new \Exception("Invalid command");
|
||||
}
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
|
@ -88,15 +90,15 @@ class Mysql implements \PHPCI\Plugin
|
|||
protected function executeFile($query)
|
||||
{
|
||||
if (!isset($query['file'])) {
|
||||
throw new \Exception("Import statement must contiain an 'file' key");
|
||||
throw new \Exception("Import statement must contain a 'file' key");
|
||||
}
|
||||
|
||||
$import_file = $this->phpci->buildPath . $query['file'];
|
||||
$import_file = $this->phpci->buildPath . $this->phpci->interpolate($query['file']);
|
||||
if (!is_readable($import_file)) {
|
||||
throw new \Exception("Cannot open SQL import file: $import_file");
|
||||
}
|
||||
|
||||
$database = isset($query['database'])? $query['database']: null;
|
||||
$database = isset($query['database'])? $this->phpci->interpolate($query['database']): null;
|
||||
|
||||
$import_command = $this->getImportCommand($import_file, $database);
|
||||
if (!$this->phpci->executeCommand($import_command)) {
|
||||
|
|
89
PHPCI/Plugin/PhpCsFixer.php
Normal file
89
PHPCI/Plugin/PhpCsFixer.php
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2013, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link http://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Plugin;
|
||||
|
||||
/**
|
||||
* PHP CS Fixer - Works with the PHP CS Fixer for testing coding standards.
|
||||
* @author Gabriel Baker <gabriel@autonomicpilot.co.uk>
|
||||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class PhpCsFixer implements \PHPCI\Plugin
|
||||
{
|
||||
protected $phpci;
|
||||
|
||||
protected $args = '';
|
||||
|
||||
protected $workingDir = '';
|
||||
protected $level = 'all';
|
||||
protected $dryRun = true;
|
||||
protected $verbose = false;
|
||||
protected $diff = false;
|
||||
protected $levels = array('psr0', 'psr1', 'psr2', 'all');
|
||||
|
||||
public function __construct(\PHPCI\Builder $phpci, array $options = array())
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->workingdir = $this->phpci->buildPath;
|
||||
$this->buildArgs($options);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$success = false;
|
||||
|
||||
$curdir = getcwd();
|
||||
chdir($this->workingdir);
|
||||
|
||||
$cmd = PHPCI_BIN_DIR . 'php-cs-fixer fix . %s';
|
||||
$success = $this->phpci->executeCommand($cmd, $this->args);
|
||||
|
||||
chdir($curdir);
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
public function buildArgs($options)
|
||||
{
|
||||
$argstring = "";
|
||||
|
||||
if ( array_key_exists('verbose', $options) && $options['verbose'] )
|
||||
{
|
||||
$this->verbose = true;
|
||||
$this->args .= ' --verbose';
|
||||
}
|
||||
|
||||
if ( array_key_exists('diff', $options) && $options['diff'] )
|
||||
{
|
||||
$this->diff = true;
|
||||
$this->args .= ' --diff';
|
||||
}
|
||||
|
||||
if ( array_key_exists('level', $options) && in_array($options['level'], $this->levels) )
|
||||
{
|
||||
$this->level = $options['level'];
|
||||
$this->args .= ' --level='.$options['level'];
|
||||
}
|
||||
|
||||
if ( array_key_exists('dryrun', $options) && $options['dryrun'] )
|
||||
{
|
||||
$this->dryRun = true;
|
||||
$this->args .= ' --dry-run';
|
||||
}
|
||||
|
||||
if ( array_key_exists('workingdir', $options)
|
||||
&& $options['workingdir']
|
||||
&& is_dir($this->phpci->buildPath.$options['workingdir']) )
|
||||
{
|
||||
$this->workingdir = $this->phpci->buildPath.$options['workingdir'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
52
PHPCI/Plugin/Shell.php
Normal file
52
PHPCI/Plugin/Shell.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2013, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link http://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Plugin;
|
||||
|
||||
/**
|
||||
* Shell Plugin - Allows execute shell commands.
|
||||
* @author Kinn Coelho Julião <kinncj@gmail.com>
|
||||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Shell implements \PHPCI\Plugin
|
||||
{
|
||||
protected $args;
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var string $command The command to be executed
|
||||
*/
|
||||
protected $command;
|
||||
|
||||
public function __construct(\PHPCI\Builder $phpci, array $options = array())
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
|
||||
if (isset($options['command'])) {
|
||||
$command = $options['command'];
|
||||
$command = str_replace("%buildpath%", $this->phpci->buildPath, $command);
|
||||
$this->command = $command;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the shell command.
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if (!defined('ENABLE_SHELL_PLUGIN') || !ENABLE_SHELL_PLUGIN) {
|
||||
throw new \Exception('The shell plugin is not enabled.');
|
||||
}
|
||||
|
||||
$success = $this->phpci->executeCommand($this->command);
|
||||
|
||||
return $success;
|
||||
}
|
||||
}
|
|
@ -19,5 +19,32 @@ use PHPCI\Store\Base\BuildStoreBase;
|
|||
*/
|
||||
class BuildStore extends BuildStoreBase
|
||||
{
|
||||
// This class has been left blank so that you can modify it - changes in this file will not be overwritten.
|
||||
public function getBuildSummary()
|
||||
{
|
||||
$query = 'SELECT COUNT(*) AS cnt FROM build b LEFT JOIN project p on p.id = b.project_id GROUP BY b.project_id ORDER BY p.title ASC, b.id DESC';
|
||||
$stmt = \b8\Database::getConnection('read')->prepare($query);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$count = (int)$res['cnt'];
|
||||
} else {
|
||||
$count = 0;
|
||||
}
|
||||
|
||||
$query = 'SELECT b.* FROM build b LEFT JOIN project p on p.id = b.project_id GROUP BY b.project_id ORDER BY p.title ASC, b.id DESC';
|
||||
$stmt = \b8\Database::getConnection('read')->prepare($query);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$map = function ($item) {
|
||||
return new \PHPCI\Model\Build($item);
|
||||
};
|
||||
$rtn = array_map($map, $res);
|
||||
|
||||
return array('items' => $rtn, 'count' => $count);
|
||||
} else {
|
||||
return array('items' => array(), 'count' => 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,24 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="span9">
|
||||
<h3>Project Overview</h3>
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Project</th>
|
||||
<th>Commit</th>
|
||||
<th>Branch</th>
|
||||
<th>Status</th>
|
||||
<th style="width: 1%"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php print $summary; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3>Last 5 Builds</h3>
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
|
@ -59,4 +59,11 @@ body
|
|||
.icon-build-running
|
||||
{
|
||||
background: url('/assets/img/icon-build-running.png') no-repeat top left;
|
||||
}
|
||||
|
||||
h3
|
||||
{
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
margin-top: 0;
|
||||
padding-top: 0;
|
||||
}
|
|
@ -36,16 +36,20 @@ if (!defined('APPLICATION_PATH')) {
|
|||
require_once(APPLICATION_PATH . 'vendor/autoload.php');
|
||||
|
||||
// Load configuration if present:
|
||||
$config = new b8\Config();
|
||||
$request = new b8\Http\Request();
|
||||
$registry = new b8\Registry($config, $request);
|
||||
|
||||
if (file_exists(APPLICATION_PATH . 'config.php')) {
|
||||
require(APPLICATION_PATH . 'config.php');
|
||||
|
||||
// Define our PHPCI_URL, if not already defined:
|
||||
if (!defined('PHPCI_URL')) {
|
||||
define('PHPCI_URL', $registry->get('install_url', '') . '/');
|
||||
define('PHPCI_URL', $config->get('install_url', '') . '/');
|
||||
}
|
||||
}
|
||||
|
||||
// Set up the registry:
|
||||
b8\Registry::getInstance()->set('app_namespace', 'PHPCI');
|
||||
b8\Registry::getInstance()->set('DefaultController', 'Index');
|
||||
b8\Registry::getInstance()->set('ViewPath', dirname(__FILE__) . '/PHPCI/View/');
|
||||
$config->set('app_namespace', 'PHPCI');
|
||||
$config->set('default_controller', 'Index');
|
||||
$config->set('view_path', dirname(__FILE__) . '/PHPCI/View/');
|
|
@ -1,36 +1,37 @@
|
|||
{
|
||||
"name": "block8/phpci",
|
||||
"description": "Simple continuous integration for PHP projects.",
|
||||
"name" : "block8/phpci",
|
||||
"description" : "Simple continuous integration for PHP projects.",
|
||||
"minimum-stability": "dev",
|
||||
"type": "library",
|
||||
"keywords": ["php", "phpci", "ci", "continuous", "integration", "testing", "phpunit", "continuous integration", "jenkins", "travis"],
|
||||
"homepage": "http://www.phptesting.org/",
|
||||
"license": "BSD-2-Clause",
|
||||
"type" : "library",
|
||||
"keywords" : ["php", "phpci", "ci", "continuous", "integration", "testing", "phpunit", "continuous integration", "jenkins", "travis"],
|
||||
"homepage" : "http://www.phptesting.org/",
|
||||
"license" : "BSD-2-Clause",
|
||||
|
||||
"authors": [
|
||||
{
|
||||
"name": "Dan Cryer",
|
||||
"email": "dan.cryer@block8.co.uk",
|
||||
"name" : "Dan Cryer",
|
||||
"email" : "dan.cryer@block8.co.uk",
|
||||
"homepage": "http://www.block8.co.uk",
|
||||
"role": "Developer"
|
||||
"role" : "Developer"
|
||||
}
|
||||
],
|
||||
|
||||
"support": {
|
||||
"email": "hello+phpci@block8.co.uk",
|
||||
"email" : "hello+phpci@block8.co.uk",
|
||||
"issues": "https://github.com/Block8/PHPCI/issues",
|
||||
"source": "https://github.com/Block8/PHPCI"
|
||||
},
|
||||
|
||||
"require": {
|
||||
"block8/b8framework": "dev-master",
|
||||
"phpunit/phpunit": "3.*",
|
||||
"phpmd/phpmd" : "1.*",
|
||||
"sebastian/phpcpd": "1.*",
|
||||
"block8/b8framework" : "dev-master",
|
||||
"phpunit/phpunit" : "3.*",
|
||||
"phpmd/phpmd" : "1.*",
|
||||
"sebastian/phpcpd" : "1.*",
|
||||
"squizlabs/php_codesniffer": "1.*",
|
||||
"ircmaxell/password-compat": "1.x",
|
||||
"phpspec/phpspec": "2.*",
|
||||
"symfony/yaml": "2.2.x-dev",
|
||||
"symfony/console": "2.2.*"
|
||||
"phpspec/phpspec" : "2.*",
|
||||
"symfony/yaml" : "2.2.x-dev",
|
||||
"symfony/console" : "2.2.*",
|
||||
"fabpot/php-cs-fixer" : "0.3.*@dev"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue