Adding build status images, both to the dashboard and as an external facing feature. Closes #43
This commit is contained in:
parent
14841477a6
commit
653f4cb620
|
@ -27,9 +27,9 @@ class Application extends b8\Application
|
|||
|
||||
// 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'));
|
||||
$externalAction = in_array($controllerName, array('Bitbucket', 'Github', 'BuildStatus'));
|
||||
|
||||
if (!$webhookAction && !$sessionAction) {
|
||||
if (!$externalAction && !$sessionAction) {
|
||||
$this->validateSession();
|
||||
}
|
||||
|
||||
|
|
50
PHPCI/Controller/BuildStatusController.php
Normal file
50
PHPCI/Controller/BuildStatusController.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?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\Controller;
|
||||
|
||||
use b8;
|
||||
use b8\Store;
|
||||
use PHPCI\Model\Project;
|
||||
use PHPCI\Model\Build;
|
||||
|
||||
/**
|
||||
* Build Status Controller - Allows external access to build status information / images.
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* @package PHPCI
|
||||
* @subpackage Web
|
||||
*/
|
||||
class BuildStatusController extends b8\Controller
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->_projectStore = Store\Factory::getStore('Project');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the appropriate build status image for a given project.
|
||||
*/
|
||||
public function image($projectId)
|
||||
{
|
||||
$branch = $this->getParam('branch', 'master');
|
||||
$project = $this->_projectStore->getById($projectId);
|
||||
$status = 'ok';
|
||||
|
||||
if (isset($project) && $project instanceof Project) {
|
||||
$build = $project->getLatestBuild($branch, array(2,3));
|
||||
|
||||
if (isset($build) && $build instanceof Build && $build->getStatus() != 2) {
|
||||
$status = 'failed';
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: image/png');
|
||||
die(file_get_contents(APPLICATION_PATH . 'assets/img/build-' . $status . '.png'));
|
||||
}
|
||||
}
|
|
@ -10,6 +10,8 @@
|
|||
namespace PHPCI\Model;
|
||||
|
||||
use PHPCI\Model\Base\ProjectBase;
|
||||
use PHPCI\Model\Build;
|
||||
use b8\Store;
|
||||
|
||||
/**
|
||||
* Project Model
|
||||
|
@ -20,4 +22,25 @@ use PHPCI\Model\Base\ProjectBase;
|
|||
*/
|
||||
class Project extends ProjectBase
|
||||
{
|
||||
public function getLatestBuild($branch = 'master', $status = null)
|
||||
{
|
||||
$criteria = array('branch' => $branch, 'project_id' => $this->getId());
|
||||
|
||||
if (isset($status)) {
|
||||
$criteria['status'] = $status;
|
||||
}
|
||||
|
||||
$order = array('id' => 'DESC');
|
||||
$builds = Store\Factory::getStore('Build')->getWhere($criteria, 1, $start, array(), $order);
|
||||
|
||||
if (is_array($builds['items']) && count($builds['items'])) {
|
||||
$latest = array_shift($builds['items']);
|
||||
|
||||
if (isset($latest) && $latest instanceof Build) {
|
||||
return $latest;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,31 @@
|
|||
<li class="divider"></li>
|
||||
<li class="nav-header">Projects</li>
|
||||
|
||||
<?php foreach($projects as $project): ?>
|
||||
<li><a href="/project/view/<?php print $project->getId(); ?>"><i class="icon-folder-open"></i> <?php print $project->getTitle(); ?></a></li>
|
||||
<?php
|
||||
foreach($projects as $project):
|
||||
$status = 'icon-build-ok';
|
||||
$build = $project->getLatestBuild('master');
|
||||
|
||||
if (isset($build)) {
|
||||
switch($build->getStatus())
|
||||
{
|
||||
case 0:
|
||||
$status = 'icon-build-pending';
|
||||
break;
|
||||
case 1:
|
||||
$status = 'icon-build-running';
|
||||
break;
|
||||
case 3:
|
||||
$status = 'icon-build-failed';
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
$status = 'icon-build-ok';
|
||||
break;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<li><a href="/project/view/<?php print $project->getId(); ?>"><i class="<?= $status; ?>"></i> <?php print $project->getTitle(); ?></a></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -39,4 +39,24 @@ body
|
|||
font-size: 2em;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.icon-build-ok
|
||||
{
|
||||
background: url('/assets/img/icon-build-ok.png') no-repeat top left;
|
||||
}
|
||||
|
||||
.icon-build-failed
|
||||
{
|
||||
background: url('/assets/img/icon-build-failed.png') no-repeat top left;
|
||||
}
|
||||
|
||||
.icon-build-pending
|
||||
{
|
||||
background: url('/assets/img/icon-build-pending.png') no-repeat top left;
|
||||
}
|
||||
|
||||
.icon-build-running
|
||||
{
|
||||
background: url('/assets/img/icon-build-running.png') no-repeat top left;
|
||||
}
|
BIN
assets/img/build-failed.png
Normal file
BIN
assets/img/build-failed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2 KiB |
BIN
assets/img/build-ok.png
Normal file
BIN
assets/img/build-ok.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
assets/img/icon-build-failed.png
Normal file
BIN
assets/img/icon-build-failed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 282 B |
BIN
assets/img/icon-build-ok.png
Normal file
BIN
assets/img/icon-build-ok.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 290 B |
BIN
assets/img/icon-build-pending.png
Normal file
BIN
assets/img/icon-build-pending.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 292 B |
BIN
assets/img/icon-build-running.png
Normal file
BIN
assets/img/icon-build-running.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 284 B |
Loading…
Reference in a new issue