public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $this->requireApplicationCapability(HarbormasterManagePlansCapability::CAPABILITY);
     $plan = id(new HarbormasterBuildPlanQuery())->setViewer($viewer)->withIDs(array($this->id))->executeOne();
     if (!$plan) {
         return new Aphront404Response();
     }
     $plan_id = $plan->getID();
     $cancel_uri = $this->getApplicationURI("plan/{$plan_id}/");
     $errors = array();
     if ($request->isFormPost()) {
         $class = $request->getStr('class');
         if (!HarbormasterBuildStepImplementation::getImplementation($class)) {
             $errors[] = pht('Choose the type of build step you want to add.');
         }
         if (!$errors) {
             $new_uri = $this->getApplicationURI("step/new/{$plan_id}/{$class}/");
             return id(new AphrontRedirectResponse())->setURI($new_uri);
         }
     }
     $control = id(new AphrontFormRadioButtonControl())->setName('class');
     $all = HarbormasterBuildStepImplementation::getImplementations();
     foreach ($all as $class => $implementation) {
         $control->addButton($class, $implementation->getName(), $implementation->getGenericDescription());
     }
     if ($errors) {
         $errors = id(new AphrontErrorView())->setErrors($errors);
     }
     return $this->newDialog()->setTitle(pht('Add New Step'))->addSubmitButton(pht('Add Build Step'))->addCancelButton($cancel_uri)->appendChild($errors)->appendParagraph(pht('Choose a type of build step to add:'))->appendChild($control);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $plan = id(new HarbormasterBuildPlanQuery())->setViewer($viewer)->withIDs(array($request->getURIData('id')))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$plan) {
         return new Aphront404Response();
     }
     $plan_id = $plan->getID();
     $cancel_uri = $this->getApplicationURI("plan/{$plan_id}/");
     $plan_title = pht('Plan %d', $plan_id);
     $all = HarbormasterBuildStepImplementation::getImplementations();
     $all = msort($all, 'getName');
     $all_groups = HarbormasterBuildStepGroup::getAllGroups();
     foreach ($all as $impl) {
         $group_key = $impl->getBuildStepGroupKey();
         if (empty($all_groups[$group_key])) {
             throw new Exception(pht('Build step "%s" has step group key "%s", but no step group ' . 'with that key exists.', get_class($impl), $group_key));
         }
     }
     $groups = mgroup($all, 'getBuildStepGroupKey');
     $boxes = array();
     $enabled_groups = HarbormasterBuildStepGroup::getAllEnabledGroups();
     foreach ($enabled_groups as $group) {
         $list = id(new PHUIObjectItemListView())->setNoDataString(pht('This group has no available build steps.'));
         $steps = idx($groups, $group->getGroupKey(), array());
         foreach ($steps as $key => $impl) {
             if ($impl->shouldRequireAutotargeting()) {
                 unset($steps[$key]);
                 continue;
             }
         }
         if (!$steps && !$group->shouldShowIfEmpty()) {
             continue;
         }
         foreach ($steps as $key => $impl) {
             $class = get_class($impl);
             $new_uri = $this->getApplicationURI("step/new/{$plan_id}/{$class}/");
             $item = id(new PHUIObjectItemView())->setHeader($impl->getName())->setHref($new_uri)->addAttribute($impl->getGenericDescription());
             $list->addItem($item);
         }
         $box = id(new PHUIObjectBoxView())->setHeaderText($group->getGroupName())->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->appendChild($list);
         $boxes[] = $box;
     }
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb($plan_title, $cancel_uri)->addTextCrumb(pht('Add Build Step'))->setBorder(true);
     $title = array($plan_title, pht('Add Build Step'));
     $header = id(new PHUIHeaderView())->setHeader(pht('Add Build Step'))->setHeaderIcon('fa-plus-square');
     $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($boxes));
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $this->requireApplicationCapability(HarbormasterManagePlansCapability::CAPABILITY);
     $plan = id(new HarbormasterBuildPlanQuery())->setViewer($viewer)->withIDs(array($request->getURIData('id')))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$plan) {
         return new Aphront404Response();
     }
     $plan_id = $plan->getID();
     $cancel_uri = $this->getApplicationURI("plan/{$plan_id}/");
     $all = HarbormasterBuildStepImplementation::getImplementations();
     foreach ($all as $key => $impl) {
         if ($impl->shouldRequireAutotargeting()) {
             unset($all[$key]);
         }
     }
     $errors = array();
     if ($request->isFormPost()) {
         $class = $request->getStr('class');
         if (empty($all[$class])) {
             $errors[] = pht('Choose the type of build step you want to add.');
         }
         if (!$errors) {
             $new_uri = $this->getApplicationURI("step/new/{$plan_id}/{$class}/");
             return id(new AphrontRedirectResponse())->setURI($new_uri);
         }
     }
     $control = id(new AphrontFormRadioButtonControl())->setName('class');
     foreach ($all as $class => $implementation) {
         $control->addButton($class, $implementation->getName(), $implementation->getGenericDescription());
     }
     if ($errors) {
         $errors = id(new PHUIInfoView())->setErrors($errors);
     }
     return $this->newDialog()->setTitle(pht('Add New Step'))->addSubmitButton(pht('Add Build Step'))->addCancelButton($cancel_uri)->appendChild($errors)->appendParagraph(pht('Choose a type of build step to add:'))->appendChild($control);
 }
 /**
  * Get all of the @{class:HarbormasterBuildStepImplementation} objects for
  * a list of autotarget keys.
  *
  * @param list<string> Autotarget keys, like `"core.arc.lint"`.
  * @return map<string, object> Map of keys to implementations.
  */
 private function getAutosteps(array $autotargets)
 {
     $all_steps = HarbormasterBuildStepImplementation::getImplementations();
     $all_steps = mpull($all_steps, null, 'getBuildStepAutotargetStepKey');
     // Make sure all the targets really exist.
     foreach ($autotargets as $autotarget) {
         if (empty($all_steps[$autotarget])) {
             throw new Exception(pht('No build step provides autotarget "%s"!', $autotarget));
         }
     }
     return array_select_keys($all_steps, $autotargets);
 }
 public function testGetImplementations()
 {
     HarbormasterBuildStepImplementation::getImplementations();
     $this->assertTrue(true);
 }