Fixes
This commit is contained in:
commit
0afc28cb69
|
@ -47,24 +47,7 @@ class Application extends b8\Application
|
|||
return false;
|
||||
};
|
||||
|
||||
// Check settings for disable_authentication enabled and user_id
|
||||
$skipAuth = function () {
|
||||
$config = b8\Config::getInstance();
|
||||
$state = (bool)$config->get('phpci.authentication_settings.state', false);
|
||||
$id = $config->get('phpci.authentication_settings.user_id', 0);
|
||||
|
||||
if (false !== $state && 0 != (int)$id) {
|
||||
$user = b8\Store\Factory::getStore('User')
|
||||
->getByPrimaryKey($id);
|
||||
|
||||
if ($user) {
|
||||
$_SESSION['phpci_user'] = $user;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$skipAuth = [$this, 'shouldSkipAuth'];
|
||||
|
||||
// Handler for the route we're about to register, checks for a valid session where necessary:
|
||||
$routeHandler = function (&$route, Response &$response) use (&$request, $validateSession, $skipAuth) {
|
||||
|
@ -152,4 +135,27 @@ class Application extends b8\Application
|
|||
$projectStore = b8\Store\Factory::getStore('Project');
|
||||
$layout->projects = $projectStore->getAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we should skip auth (because it is disabled)
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldSkipAuth()
|
||||
{
|
||||
$config = b8\Config::getInstance();
|
||||
$state = (bool)$config->get('phpci.authentication_settings.state', false);
|
||||
$userId = $config->get('phpci.authentication_settings.user_id', 0);
|
||||
|
||||
if (false !== $state && 0 != (int)$userId) {
|
||||
$user = b8\Store\Factory::getStore('User')
|
||||
->getByPrimaryKey($userId);
|
||||
|
||||
if ($user) {
|
||||
$_SESSION['phpci_user'] = $user;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,16 +72,16 @@ class SettingsController extends Controller
|
|||
$emailSettings = $this->settings['phpci']['email_settings'];
|
||||
}
|
||||
|
||||
$authenticationSettings = array();
|
||||
$authSettings = array();
|
||||
if (isset($this->settings['phpci']['authentication_settings'])) {
|
||||
$authenticationSettings = $this->settings['phpci']['authentication_settings'];
|
||||
$authSettings = $this->settings['phpci']['authentication_settings'];
|
||||
}
|
||||
|
||||
$this->view->basicSettings = $this->getBasicForm($basicSettings);
|
||||
$this->view->buildSettings = $this->getBuildForm($buildSettings);
|
||||
$this->view->github = $this->getGithubForm();
|
||||
$this->view->emailSettings = $this->getEmailForm($emailSettings);
|
||||
$this->view->authenticationSettings = $this->getAuthenticationForm($authenticationSettings);
|
||||
$this->view->authenticationSettings = $this->getAuthenticationForm($authSettings);
|
||||
$this->view->isWriteable = $this->canWriteConfig();
|
||||
|
||||
if (!empty($this->settings['phpci']['github']['token'])) {
|
||||
|
|
|
@ -36,21 +36,33 @@ class BuildInterpolator
|
|||
$this->interpolation_vars = array();
|
||||
$this->interpolation_vars['%PHPCI%'] = 1;
|
||||
$this->interpolation_vars['%COMMIT%'] = $build->getCommitId();
|
||||
$this->interpolation_vars['%SHORT_COMMIT%'] = substr($build->getCommitId(), 0, 7);
|
||||
$this->interpolation_vars['%COMMIT_EMAIL%'] = $build->getCommitterEmail();
|
||||
$this->interpolation_vars['%COMMIT_URI%'] = $build->getCommitLink();
|
||||
$this->interpolation_vars['%BRANCH%'] = $build->getBranch();
|
||||
$this->interpolation_vars['%BRANCH_URI%'] = $build->getBranchLink();
|
||||
$this->interpolation_vars['%PROJECT%'] = $build->getProjectId();
|
||||
$this->interpolation_vars['%BUILD%'] = $build->getId();
|
||||
$this->interpolation_vars['%PROJECT_TITLE%'] = $build->getProjectTitle();
|
||||
$this->interpolation_vars['%PROJECT_URI%'] = $phpCiUrl . "project/view/" . $build->getProjectId();
|
||||
$this->interpolation_vars['%BUILD_PATH%'] = $buildPath;
|
||||
$this->interpolation_vars['%BUILD_URI%'] = $phpCiUrl . "build/view/" . $build->getId();
|
||||
$this->interpolation_vars['%PHPCI_COMMIT%'] = $this->interpolation_vars['%COMMIT%'];
|
||||
$this->interpolation_vars['%PHPCI_SHORT_COMMIT%'] = $this->interpolation_vars['%SHORT_COMMIT%'];
|
||||
$this->interpolation_vars['%PHPCI_COMMIT_EMAIL%'] = $this->interpolation_vars['%COMMIT_EMAIL%'];
|
||||
$this->interpolation_vars['%PHPCI_COMMIT_URI%'] = $this->interpolation_vars['%COMMIT_URI%'];
|
||||
$this->interpolation_vars['%PHPCI_PROJECT%'] = $this->interpolation_vars['%PROJECT%'];
|
||||
$this->interpolation_vars['%PHPCI_BUILD%'] = $this->interpolation_vars['%BUILD%'];
|
||||
$this->interpolation_vars['%PHPCI_PROJECT_TITLE%'] = $this->interpolation_vars['%PROJECT_TITLE%'];
|
||||
$this->interpolation_vars['%PHPCI_PROJECT_URI%'] = $this->interpolation_vars['%PROJECT_URI%'];
|
||||
$this->interpolation_vars['%PHPCI_BUILD_PATH%'] = $this->interpolation_vars['%BUILD_PATH%'];
|
||||
$this->interpolation_vars['%PHPCI_BUILD_URI%'] = $this->interpolation_vars['%BUILD_URI%'];
|
||||
|
||||
putenv('PHPCI=1');
|
||||
putenv('PHPCI_COMMIT=' . $this->interpolation_vars['%COMMIT%']);
|
||||
putenv('PHPCI_SHORT_COMMIT=' . $this->interpolation_vars['%SHORT_COMMIT%']);
|
||||
putenv('PHPCI_COMMIT_EMAIL=' . $this->interpolation_vars['%COMMIT_EMAIL%']);
|
||||
putenv('PHPCI_COMMIT_URI=' . $this->interpolation_vars['%COMMIT_URI%']);
|
||||
putenv('PHPCI_PROJECT=' . $this->interpolation_vars['%PROJECT%']);
|
||||
putenv('PHPCI_BUILD=' . $this->interpolation_vars['%BUILD%']);
|
||||
putenv('PHPCI_PROJECT_TITLE=' . $this->interpolation_vars['%PROJECT_TITLE%']);
|
||||
|
|
35
PHPCI/Helper/LoginIsDisabled.php
Normal file
35
PHPCI/Helper/LoginIsDisabled.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Helper;
|
||||
|
||||
/**
|
||||
* Login Is Disabled Helper - Checks if login is disalbed in the view
|
||||
* @author Stephen Ball <phpci@stephen.rebelinblue.com>
|
||||
* @package PHPCI
|
||||
* @subpackage Web
|
||||
*/
|
||||
class LoginIsDisabled
|
||||
{
|
||||
/**
|
||||
* Checks if
|
||||
* @param $method
|
||||
* @param array $params
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function __call($method, $params = array())
|
||||
{
|
||||
unset($method, $params);
|
||||
|
||||
$config = b8\Config::getInstance();
|
||||
$state = (bool) $config->get('phpci.authentication_settings.state', false);
|
||||
|
||||
return (false !== $state);
|
||||
}
|
||||
}
|
|
@ -69,8 +69,6 @@ class Lint implements PHPCI\Plugin
|
|||
|
||||
$php = $this->phpci->findBinary('php');
|
||||
|
||||
$this->phpci->logExecOutput(false);
|
||||
|
||||
foreach ($this->directories as $dir) {
|
||||
if (!$this->lintDirectory($php, $dir)) {
|
||||
$success = false;
|
||||
|
@ -79,8 +77,6 @@ class Lint implements PHPCI\Plugin
|
|||
|
||||
$this->phpci->quiet = false;
|
||||
|
||||
$this->phpci->logExecOutput(true);
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
|
|
127
PHPCI/Plugin/SlackNotify.php
Normal file
127
PHPCI/Plugin/SlackNotify.php
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Plugin;
|
||||
|
||||
use PHPCI\Builder;
|
||||
use PHPCI\Model\Build;
|
||||
|
||||
/**
|
||||
* Slack Plugin
|
||||
* @author Stephen Ball <phpci@stephen.rebelinblue.com>
|
||||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class SlackNotify implements \PHPCI\Plugin
|
||||
{
|
||||
private $webHook;
|
||||
private $room;
|
||||
private $username;
|
||||
private $message;
|
||||
private $icon;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = array())
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
|
||||
if (is_array($options) && isset($options['webhook_url'])) {
|
||||
$this->webHook = trim($options['webhook_url']);
|
||||
|
||||
if (isset($options['message'])) {
|
||||
$this->message = $options['message'];
|
||||
} else {
|
||||
$this->message = '<%PROJECT_URI%|%PROJECT_TITLE%> - <%BUILD_URI%|Build #%BUILD%> has finished ';
|
||||
$this->message .= 'for commit <%COMMIT_URI%|%SHORT_COMMIT% (%COMMIT_EMAIL%)> ';
|
||||
$this->message .= 'on branch <%BRANCH_URI%|%BRANCH%>';
|
||||
}
|
||||
|
||||
if (isset($options['room'])) {
|
||||
$this->room = $options['room'];
|
||||
} else {
|
||||
$this->room = '#phpci';
|
||||
}
|
||||
|
||||
if (isset($options['username'])) {
|
||||
$this->username = $options['username'];
|
||||
} else {
|
||||
$this->username = 'PHPCI';
|
||||
}
|
||||
|
||||
if (isset($options['icon'])) {
|
||||
$this->icon = $options['icon'];
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new \Exception('Please define the webhook_url for slack_notify plugin!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the Slack plugin.
|
||||
* @return bool
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$message = $this->phpci->interpolate($this->message);
|
||||
|
||||
$successfulBuild = $this->build->isSuccessful();
|
||||
|
||||
if ($successfulBuild) {
|
||||
$message = 'Success';
|
||||
$color = 'good';
|
||||
} else {
|
||||
$message = 'Failed';
|
||||
$color = 'danger';
|
||||
}
|
||||
|
||||
// Build up the attachment data
|
||||
$attachment = new \Maknz\Slack\Attachment(array(
|
||||
'fallback' => $message,
|
||||
'pretext' => $message,
|
||||
'color' => $color,
|
||||
'fields' => array(
|
||||
new \Maknz\Slack\AttachmentField(array(
|
||||
'title' => 'Status',
|
||||
'value' => $message,
|
||||
'short' => false
|
||||
))
|
||||
)
|
||||
));
|
||||
|
||||
$client = new \Maknz\Slack\Client($this->webHook);
|
||||
|
||||
if (!empty($this->room)) {
|
||||
$client->setChannel($this->room);
|
||||
}
|
||||
|
||||
if (!empty($this->username)) {
|
||||
$client->setUsername($this->username);
|
||||
}
|
||||
|
||||
if (!empty($this->icon)) {
|
||||
$client->setIcon($this->icon);
|
||||
}
|
||||
|
||||
$client->attach($attachment);
|
||||
|
||||
$success = true;
|
||||
|
||||
$client->send(''); // FIXME: Handle errors
|
||||
|
||||
return $success;
|
||||
}
|
||||
}
|
|
@ -124,10 +124,12 @@ class BuildStore extends BuildStoreBase
|
|||
$and = $numResults > 1 ? ' AND (`bm`.`build_id` <= :buildId) ' : ' AND (`bm`.`build_id` = :buildId) ';
|
||||
$where = '`bm`.`meta_key` = :key AND `bm`.`project_id` = :projectId ' . $and;
|
||||
$from = ' `build_meta` AS `bm`';
|
||||
|
||||
if ($branch !== null) {
|
||||
$where .= ' AND `b`.`branch` = :branch AND `b`.`id`= `bm`.`build_id` ';
|
||||
$from .= ', `build` AS `b`';
|
||||
}
|
||||
|
||||
$query = 'SELECT '.$select.' FROM '.$from.' WHERE '.$where.' ORDER BY `bm`.id DESC LIMIT :numResults';
|
||||
|
||||
$stmt = Database::getConnection('read')->prepare($query);
|
||||
|
|
|
@ -136,6 +136,7 @@
|
|||
</li>
|
||||
|
||||
|
||||
<?php if (!$this->LoginIsDisabled()): ?>
|
||||
<!-- User Account: style can be found in dropdown.less -->
|
||||
<li class="dropdown user user-menu">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
|
@ -162,6 +163,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
@ -171,6 +173,8 @@
|
|||
<aside class="left-side sidebar-offcanvas">
|
||||
<!-- sidebar: style can be found in sidebar.less -->
|
||||
<section class="sidebar">
|
||||
|
||||
<?php if (!$this->LoginIsDisabled()): ?>
|
||||
<!-- Sidebar user panel -->
|
||||
<div class="user-panel">
|
||||
<div class="pull-left image">
|
||||
|
@ -180,6 +184,7 @@
|
|||
<p><?php Lang::out('hello_name', $this->User()->getName()); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- sidebar menu: : style can be found in sidebar.less -->
|
||||
<ul class="sidebar-menu">
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
"jakub-onderka/php-parallel-lint": "Parallel Linting Tool",
|
||||
"behat/behat": "Behat BDD Testing",
|
||||
"hipchat/hipchat-php": "Hipchat integration",
|
||||
"phptal/phptal": "PHPTAL templating engine"
|
||||
"phptal/phptal": "PHPTAL templating engine",
|
||||
"maknz/slack": "Slack integration"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ var warningsPlugin = ActiveBuild.UiPlugin.extend({
|
|||
var data = google.visualization.arrayToDataTable(data);
|
||||
var options = {
|
||||
hAxis: {title: Lang.get('builds')},
|
||||
vAxis: {title: Lang.get('issues')},
|
||||
vAxis: {title: Lang.get('issues'), logScale:true},
|
||||
backgroundColor: { fill: 'transparent' },
|
||||
height: 275,
|
||||
pointSize: 3
|
||||
|
|
Loading…
Reference in a new issue