Merge branch 'master' of https://github.com/Block8/PHPCI
This commit is contained in:
commit
63e1797249
|
@ -18,9 +18,14 @@ use b8\Registry;
|
|||
*/
|
||||
class Application extends b8\Application
|
||||
{
|
||||
/**
|
||||
* Handle an incoming web request.
|
||||
*/
|
||||
public function handleRequest()
|
||||
{
|
||||
$controllerName = \b8\Registry::getInstance()->get('ControllerName');
|
||||
|
||||
// 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')));
|
||||
$webhookAction = in_array($controllerName, array('Bitbucket', 'Github'));
|
||||
|
||||
|
@ -28,12 +33,16 @@ class Application extends b8\Application
|
|||
$this->validateSession();
|
||||
}
|
||||
|
||||
// Render content into layout and return:
|
||||
$view = new b8\View('Layout');
|
||||
$view->content = parent::handleRequest();
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate whether or not the remote user has a valid session:
|
||||
*/
|
||||
protected function validateSession()
|
||||
{
|
||||
if (!empty($_SESSION['user_id'])) {
|
||||
|
|
|
@ -191,7 +191,7 @@ class Builder
|
|||
if (is_array($message)) {
|
||||
foreach ($message as $item) {
|
||||
if (is_callable($this->logCallback)) {
|
||||
call_user_func_array($this->logCallback, $prefix . $item);
|
||||
call_user_func_array($this->logCallback, array($prefix . $item));
|
||||
}
|
||||
|
||||
$this->log .= $prefix . $item . PHP_EOL;
|
||||
|
@ -201,7 +201,7 @@ class Builder
|
|||
$this->log .= $message . PHP_EOL;
|
||||
|
||||
if (isset($this->logCallback) && is_callable($this->logCallback)) {
|
||||
call_user_func_array($this->logCallback, $prefix . $item);
|
||||
call_user_func_array($this->logCallback, array($message));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class GenerateCommand extends Command
|
|||
->setDescription('Generate models and stores from the database.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute()
|
||||
{
|
||||
$gen = new \b8\Database\CodeGenerator(\b8\Database::getConnection(), 'PHPCI', PHPCI_DIR . '/PHPCI/');
|
||||
$gen->generateModels();
|
||||
|
|
|
@ -32,7 +32,7 @@ class InstallCommand extends Command
|
|||
->setDescription('Install PHPCI.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute()
|
||||
{
|
||||
$dbHost = $this->ask('Enter your MySQL host: ');
|
||||
$dbName = $this->ask('Enter the database name PHPCI should use: ');
|
||||
|
@ -101,9 +101,9 @@ b8\Database::setReadServers(array('{$dbHost}'));
|
|||
print $question . ' ';
|
||||
|
||||
$rtn = '';
|
||||
$fp = fopen('php://stdin', 'r');
|
||||
$rtn = fgets($fp);
|
||||
fclose($fp);
|
||||
$stdin = fopen('php://stdin', 'r');
|
||||
$rtn = fgets($stdin);
|
||||
fclose($stdin);
|
||||
|
||||
$rtn = trim($rtn);
|
||||
|
||||
|
|
|
@ -58,13 +58,13 @@ class ProjectController extends b8\Controller
|
|||
header('Location: /build/view/' . $build->getId());
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
public function delete($projectId)
|
||||
{
|
||||
if (!Registry::getInstance()->get('user')->getIsAdmin()) {
|
||||
throw new \Exception('You do not have permission to do that.');
|
||||
}
|
||||
|
||||
$project = $this->_projectStore->getById($id);
|
||||
$project = $this->_projectStore->getById($projectId);
|
||||
$this->_projectStore->delete($project);
|
||||
|
||||
header('Location: /');
|
||||
|
@ -109,16 +109,16 @@ class ProjectController extends b8\Controller
|
|||
$tempPath = getenv("SystemRoot") . '/TEMP/';
|
||||
}
|
||||
|
||||
$id = $tempPath . md5(microtime(true));
|
||||
$keyFile = $tempPath . md5(microtime(true));
|
||||
|
||||
if (!is_dir($tempPath)) {
|
||||
mkdir($tempPath);
|
||||
}
|
||||
|
||||
shell_exec('ssh-keygen -q -t rsa -b 2048 -f '.$id.' -N "" -C "deploy@phpci"');
|
||||
shell_exec('ssh-keygen -q -t rsa -b 2048 -f '.$keyFile.' -N "" -C "deploy@phpci"');
|
||||
|
||||
$pub = file_get_contents($id . '.pub');
|
||||
$prv = file_get_contents($id);
|
||||
$pub = file_get_contents($keyFile . '.pub');
|
||||
$prv = file_get_contents($keyFile);
|
||||
|
||||
$values = array('key' => $prv, 'pubkey' => $pub, 'token' => $_SESSION['github_token']);
|
||||
}
|
||||
|
@ -126,22 +126,7 @@ class ProjectController extends b8\Controller
|
|||
$form = $this->projectForm($values);
|
||||
|
||||
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
|
||||
$gh = \b8\Registry::getInstance()->get('github_app');
|
||||
$code = $this->getParam('code', null);
|
||||
|
||||
if (!is_null($code)) {
|
||||
$http = new \b8\HttpClient();
|
||||
$url = 'https://github.com/login/oauth/access_token';
|
||||
$params = array('client_id' => $gh['id'], 'client_secret' => $gh['secret'], 'code' => $code);
|
||||
$resp = $http->post($url, $params);
|
||||
|
||||
if ($resp['success']) {
|
||||
parse_str($resp['body'], $resp);
|
||||
$_SESSION['github_token'] = $resp['access_token'];
|
||||
header('Location: /project/add');
|
||||
die;
|
||||
}
|
||||
}
|
||||
$this->handleGithubResponse();
|
||||
|
||||
$view = new b8\View('ProjectForm');
|
||||
$view->type = 'add';
|
||||
|
@ -165,14 +150,34 @@ class ProjectController extends b8\Controller
|
|||
die;
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
protected function handleGithubResponse()
|
||||
{
|
||||
$github = \b8\Registry::getInstance()->get('github_app');
|
||||
$code = $this->getParam('code', null);
|
||||
|
||||
if (!is_null($code)) {
|
||||
$http = new \b8\HttpClient();
|
||||
$url = 'https://github.com/login/oauth/access_token';
|
||||
$params = array('client_id' => $github['id'], 'client_secret' => $github['secret'], 'code' => $code);
|
||||
$resp = $http->post($url, $params);
|
||||
|
||||
if ($resp['success']) {
|
||||
parse_str($resp['body'], $resp);
|
||||
$_SESSION['github_token'] = $resp['access_token'];
|
||||
header('Location: /project/add');
|
||||
die;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function edit($projectId)
|
||||
{
|
||||
if (!Registry::getInstance()->get('user')->getIsAdmin()) {
|
||||
throw new \Exception('You do not have permission to do that.');
|
||||
}
|
||||
|
||||
$method = Registry::getInstance()->get('requestMethod');
|
||||
$project = $this->_projectStore->getById($id);
|
||||
$project = $this->_projectStore->getById($projectId);
|
||||
|
||||
if ($method == 'POST') {
|
||||
$values = $this->getParams();
|
||||
|
@ -181,7 +186,7 @@ class ProjectController extends b8\Controller
|
|||
$values['key'] = $values['git_key'];
|
||||
}
|
||||
|
||||
$form = $this->projectForm($values, 'edit/' . $id);
|
||||
$form = $this->projectForm($values, 'edit/' . $projectId);
|
||||
|
||||
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
|
||||
$view = new b8\View('ProjectForm');
|
||||
|
|
|
@ -74,14 +74,14 @@ class UserController extends b8\Controller
|
|||
die;
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
public function edit($userId)
|
||||
{
|
||||
if (!Registry::getInstance()->get('user')->getIsAdmin()) {
|
||||
throw new \Exception('You do not have permission to do that.');
|
||||
}
|
||||
|
||||
$method = Registry::getInstance()->get('requestMethod');
|
||||
$user = $this->_userStore->getById($id);
|
||||
$user = $this->_userStore->getById($userId);
|
||||
|
||||
if ($method == 'POST') {
|
||||
$values = $this->getParams();
|
||||
|
@ -90,7 +90,7 @@ class UserController extends b8\Controller
|
|||
$values['admin'] = $values['is_admin'];
|
||||
}
|
||||
|
||||
$form = $this->userForm($values, 'edit/' . $id);
|
||||
$form = $this->userForm($values, 'edit/' . $userId);
|
||||
|
||||
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
|
||||
$view = new b8\View('UserForm');
|
||||
|
@ -155,13 +155,13 @@ class UserController extends b8\Controller
|
|||
return $form;
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
public function delete($userId)
|
||||
{
|
||||
if (!Registry::getInstance()->get('user')->getIsAdmin()) {
|
||||
throw new \Exception('You do not have permission to do that.');
|
||||
}
|
||||
|
||||
$user = $this->_userStore->getById($id);
|
||||
$user = $this->_userStore->getById($userId);
|
||||
$this->_userStore->delete($user);
|
||||
|
||||
header('Location: /user');
|
||||
|
|
|
@ -31,10 +31,10 @@ class Mysql implements \PHPCI\Plugin
|
|||
$this->phpci = $phpci;
|
||||
$this->queries = $options;
|
||||
|
||||
$db = \b8\Database::getConnection('write')->getDetails();
|
||||
$config = \b8\Database::getConnection('write')->getDetails();
|
||||
$this->host = PHPCI_DB_HOST;
|
||||
$this->user = $db['user'];
|
||||
$this->pass = $db['pass'];
|
||||
$this->user = $config['user'];
|
||||
$this->pass = $config['pass'];
|
||||
|
||||
$buildSettings = $phpci->getConfig('build_settings');
|
||||
if (isset($buildSettings['mysql'])) {
|
||||
|
|
|
@ -33,13 +33,7 @@ class PhpCodeSniffer implements \PHPCI\Plugin
|
|||
$ignore = '';
|
||||
|
||||
if (count($this->phpci->ignore)) {
|
||||
$map = function ($item) {
|
||||
return substr($item, -1) == '/' ? $item . '*' : $item . '/*';
|
||||
};
|
||||
|
||||
$ignore = array_map($map, $this->phpci->ignore);
|
||||
|
||||
$ignore = ' --ignore=' . implode(',', $ignore);
|
||||
$ignore = ' --ignore=' . implode(',', $this->phpci->ignore);
|
||||
}
|
||||
|
||||
$cmd = PHPCI_BIN_DIR . 'phpcs --standard=%s %s "%s"';
|
||||
|
|
|
@ -29,12 +29,7 @@ class PhpMessDetector implements \PHPCI\Plugin
|
|||
$ignore = '';
|
||||
|
||||
if (count($this->phpci->ignore)) {
|
||||
$map = function ($item) {
|
||||
return substr($item, -1) == '/' ? $item . '*' : $item . '/*';
|
||||
};
|
||||
$ignore = array_map($map, $this->phpci->ignore);
|
||||
|
||||
$ignore = ' --exclude ' . implode(',', $ignore);
|
||||
$ignore = ' --exclude ' . implode(',', $this->phpci->ignore);
|
||||
}
|
||||
|
||||
$cmd = PHPCI_BIN_DIR . 'phpmd "%s" text codesize,unusedcode,naming %s';
|
||||
|
|
|
@ -38,10 +38,22 @@ class PhpUnit implements \PHPCI\Plugin
|
|||
public function __construct(\PHPCI\Builder $phpci, array $options = array())
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->directory = isset($options['directory']) ? $options['directory'] : null;
|
||||
$this->xmlConfigFile = isset($options['config']) ? $options['config'] : null;
|
||||
$this->runFrom = isset($options['run_from']) ? $options['run_from'] : null;
|
||||
$this->args = isset($options['args']) ? $options['args'] : '';
|
||||
|
||||
if(isset($options['directory'])) {
|
||||
$this->directory = $options['directory'];
|
||||
}
|
||||
|
||||
if(isset($options['config'])) {
|
||||
$this->xmlConfigFile = $options['config'];
|
||||
}
|
||||
|
||||
if(isset($options['run_from'])) {
|
||||
$this->runFrom = $options['run_from'];
|
||||
}
|
||||
|
||||
if(isset($options['args'])) {
|
||||
$this->args = $options['args'];
|
||||
}
|
||||
}
|
||||
|
||||
public function execute()
|
||||
|
|
Loading…
Reference in a new issue