@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 upstream/main 110 lines 2.9 kB view raw
1<?php 2 3final class DiffusionRepositoryAutomationManagementPanel 4 extends DiffusionRepositoryManagementPanel { 5 6 const PANELKEY = 'automation'; 7 8 public function getManagementPanelLabel() { 9 return pht('Automation'); 10 } 11 12 public function getManagementPanelOrder() { 13 return 800; 14 } 15 16 public function getManagementPanelGroupKey() { 17 return DiffusionRepositoryManagementBuildsPanelGroup::PANELGROUPKEY; 18 } 19 20 public function shouldEnableForRepository( 21 PhabricatorRepository $repository) { 22 return $repository->isGit(); 23 } 24 25 protected function getEditEngineFieldKeys() { 26 return array( 27 'automationBlueprintPHIDs', 28 ); 29 } 30 31 public function getManagementPanelIcon() { 32 $repository = $this->getRepository(); 33 34 if (!$repository->canPerformAutomation()) { 35 return 'fa-truck grey'; 36 } 37 38 $blueprint_phids = $repository->getAutomationBlueprintPHIDs(); 39 if (!$blueprint_phids) { 40 return 'fa-truck grey'; 41 } 42 43 $is_authorized = DrydockAuthorizationQuery::isFullyAuthorized( 44 $repository->getPHID(), 45 $blueprint_phids); 46 if (!$is_authorized) { 47 return 'fa-exclamation-triangle yellow'; 48 } 49 50 return 'fa-truck'; 51 } 52 53 public function buildManagementPanelCurtain() { 54 $repository = $this->getRepository(); 55 $viewer = $this->getViewer(); 56 $action_list = $this->newActionList(); 57 58 $can_edit = PhabricatorPolicyFilter::hasCapability( 59 $viewer, 60 $repository, 61 PhabricatorPolicyCapability::CAN_EDIT); 62 63 $can_test = $can_edit && $repository->canPerformAutomation(); 64 65 $automation_uri = $this->getEditPageURI(); 66 $test_uri = $repository->getPathURI('edit/testautomation/'); 67 68 $action_list->addAction( 69 id(new PhabricatorActionView()) 70 ->setIcon('fa-pencil') 71 ->setName(pht('Edit Automation')) 72 ->setHref($automation_uri) 73 ->setDisabled(!$can_edit) 74 ->setWorkflow(!$can_edit)); 75 76 $action_list->addAction( 77 id(new PhabricatorActionView()) 78 ->setIcon('fa-gamepad') 79 ->setName(pht('Test Configuration')) 80 ->setWorkflow(true) 81 ->setDisabled(!$can_test) 82 ->setHref($test_uri)); 83 84 return $this->newCurtainView() 85 ->setActionList($action_list); 86 } 87 88 public function buildManagementPanelContent() { 89 $repository = $this->getRepository(); 90 $viewer = $this->getViewer(); 91 92 $view = id(new PHUIPropertyListView()) 93 ->setViewer($viewer); 94 95 $blueprint_phids = $repository->getAutomationBlueprintPHIDs(); 96 if (!$blueprint_phids) { 97 $blueprint_view = phutil_tag('em', array(), pht('Not Configured')); 98 } else { 99 $blueprint_view = id(new DrydockObjectAuthorizationView()) 100 ->setUser($viewer) 101 ->setObjectPHID($repository->getPHID()) 102 ->setBlueprintPHIDs($blueprint_phids); 103 } 104 105 $view->addProperty(pht('Automation'), $blueprint_view); 106 107 return $this->newBox(pht('Automation'), $view); 108 } 109 110}