From 8e0122f6a080b8bfc6e0ac98cb857626e6ced67f Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Tue, 13 Oct 2015 16:22:39 +0100 Subject: [PATCH] Added a fixed and broken stage --- PHPCI/Builder.php | 20 +++++++++++++++++++- PHPCI/Languages/lang.en.php | 4 +++- PHPCI/Model/Project.php | 25 ++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 39e8ca41..7bc2359f 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -188,6 +188,14 @@ class Builder implements LoggerAwareInterface $this->build->sendStatusPostback(); $success = true; + $previous_build = $this->build->getProject()->getPreviousBuild($this->build->getBranch()); + + $previous_state = Build::STATUS_NEW; + + if ($previous_build) { + $previous_state = $previous_build->getStatus(); + } + try { // Set up the build: $this->setupBuild(); @@ -210,9 +218,19 @@ class Builder implements LoggerAwareInterface if ($success) { $this->pluginExecutor->executePlugins($this->config, 'success'); + + if ($previous_state == Build::STATUS_FAILED) { + $this->pluginExecutor->executePlugins($this->config, 'fixed'); + } + $this->buildLogger->logSuccess(Lang::get('build_success')); } else { $this->pluginExecutor->executePlugins($this->config, 'failure'); + + if ($previous_state == Build::STATUS_SUCCESS || $previous_state == Build::STATUS_NEW) { + $this->pluginExecutor->executePlugins($this->config, 'broken'); + } + $this->buildLogger->logFailure(Lang::get('build_failed')); } } catch (\Exception $ex) { @@ -402,4 +420,4 @@ class Builder implements LoggerAwareInterface return $pluginFactory; } -} +} \ No newline at end of file diff --git a/PHPCI/Languages/lang.en.php b/PHPCI/Languages/lang.en.php index 68ebd997..66471b7f 100644 --- a/PHPCI/Languages/lang.en.php +++ b/PHPCI/Languages/lang.en.php @@ -305,7 +305,9 @@ PHPCI', 'stage_test' => 'Test', 'stage_complete' => 'Complete', 'stage_success' => 'Success', - 'stage_failure' => 'Failure', + 'stage_failure' => 'Failure' + 'stage_broken' => 'Broken', + 'stage_fixed' => 'Fixed', // Installer 'installation_url' => 'PHPCI Installation URL', diff --git a/PHPCI/Model/Project.php b/PHPCI/Model/Project.php index 4a8b3c69..ac218abb 100644 --- a/PHPCI/Model/Project.php +++ b/PHPCI/Model/Project.php @@ -50,6 +50,29 @@ class Project extends ProjectBase return null; } + /** + * Return the previous build from a specific branch, for this project. + * @param string $branch + * @return mixed|null + */ + public function getPreviousBuild($branch = 'master') + { + $criteria = array('branch' => $branch, 'project_id' => $this->getId()); + + $order = array('id' => 'DESC'); + $builds = Store\Factory::getStore('Build')->getWhere($criteria, 1, 1, array(), $order); + + if (is_array($builds['items']) && count($builds['items'])) { + $previous = array_shift($builds['items']); + + if (isset($previous) && $previous instanceof Build) { + return $previous; + } + } + + return null; + } + /** * Store this project's access_information data * @param string|array $value @@ -131,4 +154,4 @@ class Project extends ProjectBase return $icon; } -} +} \ No newline at end of file