@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 104 lines 3.1 kB view raw
1<?php 2 3final class HarbormasterPlanRunController extends HarbormasterPlanController { 4 5 public function handleRequest(AphrontRequest $request) { 6 $viewer = $this->getViewer(); 7 $plan_id = $request->getURIData('id'); 8 9 $plan = id(new HarbormasterBuildPlanQuery()) 10 ->setViewer($viewer) 11 ->withIDs(array($plan_id)) 12 ->executeOne(); 13 if (!$plan) { 14 return new Aphront404Response(); 15 } 16 17 $plan->assertHasRunCapability($viewer); 18 19 $cancel_uri = $this->getApplicationURI("plan/{$plan_id}/"); 20 21 if (!$plan->canRunManually()) { 22 return $this->newDialog() 23 ->setTitle(pht('Can Not Run Plan')) 24 ->appendParagraph(pht('This plan can not be run manually.')) 25 ->addCancelButton($cancel_uri); 26 } 27 28 $e_name = true; 29 $v_name = null; 30 31 $errors = array(); 32 if ($request->isFormPost()) { 33 $buildable = HarbormasterBuildable::initializeNewBuildable($viewer) 34 ->setIsManualBuildable(true); 35 36 $v_name = $request->getStr('buildablePHID'); 37 38 if ($v_name) { 39 $object = id(new PhabricatorObjectQuery()) 40 ->setViewer($viewer) 41 ->withNames(array($v_name)) 42 ->executeOne(); 43 44 if ($object instanceof HarbormasterBuildableInterface) { 45 $buildable 46 ->setBuildablePHID($object->getHarbormasterBuildablePHID()) 47 ->setContainerPHID($object->getHarbormasterContainerPHID()); 48 } else { 49 $e_name = pht('Invalid'); 50 $errors[] = pht('Enter the name of a revision or commit.'); 51 } 52 } else { 53 $e_name = pht('Required'); 54 $errors[] = pht('You must choose a revision or commit to build.'); 55 } 56 57 if (!$errors) { 58 $buildable->save(); 59 60 $buildable->sendMessage( 61 $viewer, 62 HarbormasterMessageType::BUILDABLE_BUILD, 63 false); 64 65 $buildable->applyPlan($plan, array(), $viewer->getPHID()); 66 67 $buildable_uri = '/B'.$buildable->getID(); 68 return id(new AphrontRedirectResponse())->setURI($buildable_uri); 69 } 70 } 71 72 if ($errors) { 73 $errors = id(new PHUIInfoView())->setErrors($errors); 74 } 75 76 $title = pht('Run Build Plan Manually'); 77 $save_button = pht('Run Plan Manually'); 78 79 $form = id(new PHUIFormLayoutView()) 80 ->setUser($viewer) 81 ->appendRemarkupInstructions( 82 pht( 83 "Enter the name of a commit or revision to run this plan on (for ". 84 "example, `rX123456` or `D123`).\n\n". 85 "For more detailed output, you can also run manual builds from ". 86 "the command line:\n\n". 87 " $ ./bin/harbormaster build <object> --plan %s", 88 $plan->getID())) 89 ->appendChild( 90 id(new AphrontFormTextControl()) 91 ->setLabel(pht('Buildable Name')) 92 ->setName('buildablePHID') 93 ->setError($e_name) 94 ->setValue($v_name)); 95 96 return $this->newDialog() 97 ->setWidth(AphrontDialogView::WIDTH_FULL) 98 ->setTitle($title) 99 ->appendChild($form) 100 ->addCancelButton($cancel_uri) 101 ->addSubmitButton($save_button); 102 } 103 104}