@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 193 lines 5.6 kB view raw
1<?php 2 3final class HarbormasterBuildableSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Harbormaster Buildables'); 8 } 9 10 public function getApplicationClassName() { 11 return PhabricatorHarbormasterApplication::class; 12 } 13 14 public function newQuery() { 15 return new HarbormasterBuildableQuery(); 16 } 17 18 protected function buildCustomSearchFields() { 19 return array( 20 id(new PhabricatorSearchStringListField()) 21 ->setKey('objectPHIDs') 22 ->setAliases(array('objects')) 23 ->setLabel(pht('Objects')) 24 ->setPlaceholder(pht('rXabcdef, PHID-DIFF-1234, ...')) 25 ->setDescription(pht('Search for builds of particular objects.')), 26 id(new PhabricatorSearchStringListField()) 27 ->setKey('containerPHIDs') 28 ->setAliases(array('containers')) 29 ->setLabel(pht('Containers')) 30 ->setPlaceholder(pht('rXYZ, R123, D456, ...')) 31 ->setDescription( 32 pht('Search for builds by containing revision or repository.')), 33 id(new PhabricatorSearchCheckboxesField()) 34 ->setKey('statuses') 35 ->setLabel(pht('Statuses')) 36 ->setOptions(HarbormasterBuildableStatus::getOptionMap()) 37 ->setDescription(pht('Search for builds by buildable status.')), 38 id(new PhabricatorSearchThreeStateField()) 39 ->setLabel(pht('Manual')) 40 ->setKey('manual') 41 ->setDescription( 42 pht('Search for only manual or automatic buildables.')) 43 ->setOptions( 44 pht('(Show All)'), 45 pht('Show Only Manual Builds'), 46 pht('Show Only Automated Builds')), 47 ); 48 } 49 50 private function resolvePHIDs(array $names) { 51 $viewer = $this->requireViewer(); 52 53 $objects = id(new PhabricatorObjectQuery()) 54 ->setViewer($viewer) 55 ->withNames($names) 56 ->execute(); 57 58 // TODO: Instead of using string lists, we should ideally be using some 59 // kind of smart field with resolver logic that can help users type the 60 // right stuff. For now, just return a bogus value here so nothing matches 61 // but the form doesn't explode. 62 if (!$objects) { 63 return array('-'); 64 } 65 66 return mpull($objects, 'getPHID'); 67 } 68 69 protected function buildQueryFromParameters(array $map) { 70 $query = $this->newQuery(); 71 72 if ($map['objectPHIDs']) { 73 $phids = $this->resolvePHIDs($map['objectPHIDs']); 74 if ($phids) { 75 $query->withBuildablePHIDs($phids); 76 } 77 } 78 79 if ($map['containerPHIDs']) { 80 $phids = $this->resolvePHIDs($map['containerPHIDs']); 81 if ($phids) { 82 $query->withContainerPHIDs($phids); 83 } 84 } 85 86 if ($map['statuses']) { 87 $query->withStatuses($map['statuses']); 88 } 89 90 if ($map['manual'] !== null) { 91 $query->withManualBuildables($map['manual']); 92 } 93 94 return $query; 95 } 96 97 protected function getURI($path) { 98 return '/harbormaster/'.$path; 99 } 100 101 protected function getBuiltinQueryNames() { 102 return array( 103 'all' => pht('All Buildables'), 104 ); 105 } 106 107 public function buildSavedQueryFromBuiltin($query_key) { 108 $query = $this->newSavedQuery(); 109 $query->setQueryKey($query_key); 110 111 switch ($query_key) { 112 case 'all': 113 return $query; 114 } 115 116 return parent::buildSavedQueryFromBuiltin($query_key); 117 } 118 119 /** 120 * @param array<HarbormasterBuildable> $buildables 121 * @param PhabricatorSavedQuery $query 122 * @param array<PhabricatorObjectHandle> $handles 123 */ 124 protected function renderResultList( 125 array $buildables, 126 PhabricatorSavedQuery $query, 127 array $handles) { 128 assert_instances_of($buildables, HarbormasterBuildable::class); 129 130 $viewer = $this->requireViewer(); 131 132 $phids = array(); 133 foreach ($buildables as $buildable) { 134 $phids[] = $buildable->getBuildableObject() 135 ->getHarbormasterBuildableDisplayPHID(); 136 137 $phids[] = $buildable->getContainerPHID(); 138 $phids[] = $buildable->getBuildablePHID(); 139 } 140 $handles = $viewer->loadHandles($phids); 141 142 143 $list = new PHUIObjectItemListView(); 144 foreach ($buildables as $buildable) { 145 $id = $buildable->getID(); 146 147 $display_phid = $buildable->getBuildableObject() 148 ->getHarbormasterBuildableDisplayPHID(); 149 150 $container_phid = $buildable->getContainerPHID(); 151 $buildable_phid = $buildable->getBuildablePHID(); 152 153 $item = id(new PHUIObjectItemView()) 154 ->setObjectName(pht('Buildable %d', $buildable->getID())); 155 156 if ($display_phid) { 157 $handle = $handles[$display_phid]; 158 $item->setHeader($handle->getFullName()); 159 } 160 161 if ($container_phid && ($container_phid != $display_phid)) { 162 $handle = $handles[$container_phid]; 163 $item->addAttribute($handle->getName()); 164 } 165 166 if ($buildable_phid && ($buildable_phid != $display_phid)) { 167 $handle = $handles[$buildable_phid]; 168 $item->addAttribute($handle->getFullName()); 169 } 170 171 $item->setHref($buildable->getURI()); 172 173 if ($buildable->getIsManualBuildable()) { 174 $item->addIcon('fa-wrench grey', pht('Manual')); 175 } 176 177 $status_icon = $buildable->getStatusIcon(); 178 $status_color = $buildable->getStatusColor(); 179 $status_label = $buildable->getStatusDisplayName(); 180 181 $item->setStatusIcon("{$status_icon} {$status_color}", $status_label); 182 183 $list->addItem($item); 184 } 185 186 $result = new PhabricatorApplicationSearchResultView(); 187 $result->setObjectList($list); 188 $result->setNoDataString(pht('No buildables found.')); 189 190 return $result; 191 } 192 193}