diff --git a/src/applications/harbormaster/controller/HarbormasterBuildActionController.php b/src/applications/harbormaster/controller/HarbormasterBuildActionController.php --- a/src/applications/harbormaster/controller/HarbormasterBuildActionController.php +++ b/src/applications/harbormaster/controller/HarbormasterBuildActionController.php @@ -64,6 +64,11 @@ 'restart. Side effects of the build will occur again. Really '. 'restart build?'); $submit = pht('Restart Build'); + } else if (!$build->getBuildPlan()->canRestartBuildPlan()) { + $title = pht('Not Restartable'); + $body = pht( + 'The build plan for this build is not restartable, so you '. + 'can not restart the build.'); } else { $title = pht('Unable to Restart Build'); if ($build->isRestarting()) { @@ -135,8 +140,7 @@ break; } - $dialog = id(new AphrontDialogView()) - ->setUser($viewer) + $dialog = $this->newDialog() ->setTitle($title) ->appendChild($body) ->addCancelButton($return_uri); @@ -145,7 +149,7 @@ $dialog->addSubmitButton($submit); } - return id(new AphrontDialogResponse())->setDialog($dialog); + return $dialog; } } diff --git a/src/applications/harbormaster/plan/HarbormasterBuildPlanBehavior.php b/src/applications/harbormaster/plan/HarbormasterBuildPlanBehavior.php --- a/src/applications/harbormaster/plan/HarbormasterBuildPlanBehavior.php +++ b/src/applications/harbormaster/plan/HarbormasterBuildPlanBehavior.php @@ -13,6 +13,10 @@ const RUNNABLE_IF_VIEWABLE = 'view'; const RUNNABLE_IF_EDITABLE = 'edit'; + const BEHAVIOR_RESTARTABLE = 'restartable'; + const RESTARTABLE_ALWAYS = 'always'; + const RESTARTABLE_NEVER = 'never'; + public function setKey($key) { $this->key = $key; return $this; @@ -225,14 +229,14 @@ $restart_options = array( id(new HarbormasterBuildPlanBehaviorOption()) - ->setKey('always') + ->setKey(self::RESTARTABLE_ALWAYS) ->setIcon('fa-repeat green') ->setName(pht('Always')) ->setIsDefault(true) ->setDescription( pht('The build may be restarted.')), id(new HarbormasterBuildPlanBehaviorOption()) - ->setKey('never') + ->setKey(self::RESTARTABLE_NEVER) ->setIcon('fa-times red') ->setName(pht('Never')) ->setDescription( @@ -317,7 +321,7 @@ ->setName(pht('Affects Buildable')) ->setOptions($aggregate_options), id(new self()) - ->setKey('restartable') + ->setKey(self::BEHAVIOR_RESTARTABLE) ->setEditInstructions( pht( 'Usually, builds may be restarted. This may be useful if you '. diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuild.php b/src/applications/harbormaster/storage/build/HarbormasterBuild.php --- a/src/applications/harbormaster/storage/build/HarbormasterBuild.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuild.php @@ -215,6 +215,11 @@ return false; } + $plan = $this->getBuildPlan(); + if (!$plan->canRestartBuildPlan()) { + return false; + } + return !$this->isRestarting(); } diff --git a/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php b/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php --- a/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php +++ b/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php @@ -175,6 +175,16 @@ $capability); } + public function canRestartBuildPlan() { + $restartable = HarbormasterBuildPlanBehavior::BEHAVIOR_RESTARTABLE; + $is_restartable = HarbormasterBuildPlanBehavior::RESTARTABLE_ALWAYS; + + $option = HarbormasterBuildPlanBehavior::getBehavior($restartable) + ->getPlanOption($this); + + return ($option->getKey() === $is_restartable); + } + /* -( PhabricatorSubscribableInterface )----------------------------------- */