diff --git a/PHPCI/Controller/HomeController.php b/PHPCI/Controller/HomeController.php index 3d42775d..f84bebe0 100644 --- a/PHPCI/Controller/HomeController.php +++ b/PHPCI/Controller/HomeController.php @@ -70,13 +70,24 @@ class HomeController extends \PHPCI\Controller protected function getSummaryHtml($projects) { $summaryBuilds = array(); + $successes = array(); + $failures = array(); + foreach ($projects['items'] as $project) { $summaryBuilds[$project->getId()] = $this->buildStore->getLatestBuilds($project->getId()); + + $success = $this->buildStore->getLastBuildByStatus($project->getId(), Build::STATUS_SUCCESS); + $failure = $this->buildStore->getLastBuildByStatus($project->getId(), Build::STATUS_FAILED); + + $successes[$project->getId()] = $success; + $failures[$project->getId()] = $failure; } $summaryView = new b8\View('SummaryTable'); $summaryView->projects = $projects['items']; $summaryView->builds = $summaryBuilds; + $summaryView->successful = $successes; + $summaryView->failed = $failures; return $summaryView->render(); } diff --git a/PHPCI/Store/BuildStore.php b/PHPCI/Store/BuildStore.php index 8c36b3b1..b28142a7 100644 --- a/PHPCI/Store/BuildStore.php +++ b/PHPCI/Store/BuildStore.php @@ -53,6 +53,21 @@ class BuildStore extends BuildStoreBase } } + public function getLastBuildByStatus($projectId = null, $status = Build::STATUS_SUCCESS) + { + $query = 'SELECT * FROM build WHERE project_id = :pid AND status = :status ORDER BY id DESC LIMIT 1'; + $stmt = Database::getConnection('read')->prepare($query); + $stmt->bindValue(':pid', $projectId); + $stmt->bindValue(':status', $status); + + if ($stmt->execute()) { + $res = $stmt->fetch(\PDO::FETCH_ASSOC); + return new Build($res); + } else { + return array(); + } + } + public function getByProjectAndCommit($projectId, $commitId) { $query = 'SELECT * FROM `build` WHERE `project_id` = :project_id AND `commit_id` = :commit_id'; diff --git a/PHPCI/View/Home/index.phtml b/PHPCI/View/Home/index.phtml index 5a1f7a84..fb49ba88 100644 --- a/PHPCI/View/Home/index.phtml +++ b/PHPCI/View/Home/index.phtml @@ -1,5 +1,10 @@
Project | -Health | -- |
---|
+ 0): ?> + out of the last + getId()]); ?> builds have failed. + + getId()])): ?> + The last successful build was + getId()]->getFinished()->format('M j Y'); ?> + + This project has never built successfully. + + + All of the last getId()]); ?> builds passed. + + getId()])): ?> + The last failed build was + getId()]->getFinished()->format('M j Y'); ?> + + This project has never failed to build. + + +
+