Initial summary changes

This commit is contained in:
Gabriel Baker 2013-06-05 06:23:47 +01:00
parent 6dce7e2004
commit 76adf14b28
4 changed files with 66 additions and 5 deletions

View file

@ -33,7 +33,7 @@ class IndexController extends \PHPCI\Controller
$projects = $this->_projectStore->getWhere(array(), 50, 0, array(), array('title' => 'ASC'));
$summary = $this->_buildStore->getBuildSummary();
$summaryView = new b8\View('BuildsTable');
$summaryView = new b8\View('SummaryTable');
$summaryView->builds = $summary['items'];
$this->view->builds = $this->getLatestBuildsHtml();

View file

@ -31,7 +31,7 @@ class BuildStore extends BuildStoreBase
$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';
$query = 'SELECT b.* FROM build b LEFT JOIN project p on p.id = b.project_id ORDER BY p.title ASC, b.id DESC';
$stmt = \b8\Database::getConnection('read')->prepare($query);
if ($stmt->execute()) {

View file

@ -44,10 +44,10 @@
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Health</th>
<th>Project</th>
<th>Commit</th>
<th>Branch</th>
<th>Last Success</th>
<th>Last Failure</th>
<th>Status</th>
<th style="width: 1%"></th>
</tr>

View file

@ -0,0 +1,61 @@
<?php
// echo "<pre>";
// var_dump($builds);
// echo "</pre>";
$maxbuildcount = 5;
$projects = array();
$prevBuild = null;
$health = false;
foreach($builds as $build):
if ( is_null($prevBuild) || $build->getProjectId() !== $prevBuild->getProjectId() ) {
$health = false;
$projects[$build->getProjectId()]['count'] = 0;
$projects[$build->getProjectId()]['health'] = 0;
}
if (
$build->getStatus() < 2 ||
(
!is_null($prevBuild) &&
$projects[$build->getProjectId()]['count'] >= $maxbuildcount &&
$build->getProjectId() === $prevBuild->getProjectId()
)
) {
continue;
}
switch ((int)$build->getStatus()) {
case 2:
$projects[$build->getProjectId()]['health']++;
if ( empty($projects[$build->getProjectId()]['lastsuccess']) ) {
$projects[$build->getProjectId()]['lastsuccess'] = $build->getStarted();
}
break;
case 3:
$projects[$build->getProjectId()]['health']--;
if ( empty($projects[$build->getProjectId()]['lastfailure']) ) {
$projects[$build->getProjectId()]['lastfailure'] = $build->getStarted();
}
break;
}
$projects[$build->getProjectId()]['count']++;
$prevBuild = $build;
endforeach;
// echo "<pre>";
// var_dump($projects);
// echo "</pre>";
foreach($projects as $projectId => $project):
?>
<tr>
<td><?= $project['health'] < 0 ? 'Stormy': ($project['health'] < 5? 'Overcast': 'Sunny') ?></td>
<td><?= $projectId ?></td>
<td><?= empty($project['lastsuccess']) ? 'Never' :$project['lastsuccess']->format("d-m-Y H:i:s" ) ?></td>
<td><?= empty($project['lastfailure']) ? 'Never' :$project['lastfailure']->format("d-m-Y H:i:s" ) ?></td>
<td><?= $project['health'] ?></td>
<td><?= $project['count'] ?></td>
</tr>
<?php endforeach; ?>