@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 273 lines 8.3 kB view raw
1<?php 2 3final class PhabricatorRepositoryPushLogSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Push Logs'); 8 } 9 10 public function getApplicationClassName() { 11 return PhabricatorDiffusionApplication::class; 12 } 13 14 public function newQuery() { 15 return new PhabricatorRepositoryPushLogQuery(); 16 } 17 18 protected function buildQueryFromParameters(array $map) { 19 $query = $this->newQuery(); 20 21 if ($map['repositoryPHIDs']) { 22 $query->withRepositoryPHIDs($map['repositoryPHIDs']); 23 } 24 25 if ($map['pusherPHIDs']) { 26 $query->withPusherPHIDs($map['pusherPHIDs']); 27 } 28 29 if ($map['createdStart'] || $map['createdEnd']) { 30 $query->withEpochBetween( 31 $map['createdStart'], 32 $map['createdEnd']); 33 } 34 35 if ($map['blockingHeraldRulePHIDs']) { 36 $query->withBlockingHeraldRulePHIDs($map['blockingHeraldRulePHIDs']); 37 } 38 39 return $query; 40 } 41 42 protected function buildCustomSearchFields() { 43 return array( 44 id(new PhabricatorSearchDatasourceField()) 45 ->setDatasource(new DiffusionRepositoryDatasource()) 46 ->setKey('repositoryPHIDs') 47 ->setAliases(array('repository', 'repositories', 'repositoryPHID')) 48 ->setLabel(pht('Repositories')) 49 ->setDescription( 50 pht('Search for push logs for specific repositories.')), 51 id(new PhabricatorUsersSearchField()) 52 ->setKey('pusherPHIDs') 53 ->setAliases(array('pusher', 'pushers', 'pusherPHID')) 54 ->setLabel(pht('Pushers')) 55 ->setDescription( 56 pht('Search for push logs by specific users.')), 57 id(new PhabricatorSearchDatasourceField()) 58 ->setDatasource(new HeraldRuleDatasource()) 59 ->setKey('blockingHeraldRulePHIDs') 60 ->setLabel(pht('Blocked By')) 61 ->setDescription( 62 pht('Search for pushes blocked by particular Herald rules.')), 63 id(new PhabricatorSearchDateField()) 64 ->setLabel(pht('Created After')) 65 ->setKey('createdStart'), 66 id(new PhabricatorSearchDateField()) 67 ->setLabel(pht('Created Before')) 68 ->setKey('createdEnd'), 69 ); 70 } 71 72 protected function getURI($path) { 73 return '/diffusion/pushlog/'.$path; 74 } 75 76 protected function getBuiltinQueryNames() { 77 return array( 78 'all' => pht('All Push Logs'), 79 ); 80 } 81 82 public function buildSavedQueryFromBuiltin($query_key) { 83 $query = $this->newSavedQuery(); 84 $query->setQueryKey($query_key); 85 86 switch ($query_key) { 87 case 'all': 88 return $query; 89 } 90 91 return parent::buildSavedQueryFromBuiltin($query_key); 92 } 93 94 protected function renderResultList( 95 array $logs, 96 PhabricatorSavedQuery $query, 97 array $handles) { 98 99 $table = id(new DiffusionPushLogListView()) 100 ->setViewer($this->requireViewer()) 101 ->setLogs($logs); 102 103 return id(new PhabricatorApplicationSearchResultView()) 104 ->setTable($table); 105 } 106 107 protected function newExportFields() { 108 $viewer = $this->requireViewer(); 109 110 $fields = array( 111 id(new PhabricatorIDExportField()) 112 ->setKey('pushID') 113 ->setLabel(pht('Push ID')), 114 id(new PhabricatorStringExportField()) 115 ->setKey('unique') 116 ->setLabel(pht('Unique')), 117 id(new PhabricatorStringExportField()) 118 ->setKey('protocol') 119 ->setLabel(pht('Protocol')), 120 id(new PhabricatorPHIDExportField()) 121 ->setKey('repositoryPHID') 122 ->setLabel(pht('Repository PHID')), 123 id(new PhabricatorStringExportField()) 124 ->setKey('repository') 125 ->setLabel(pht('Repository')), 126 id(new PhabricatorPHIDExportField()) 127 ->setKey('pusherPHID') 128 ->setLabel(pht('Pusher PHID')), 129 id(new PhabricatorStringExportField()) 130 ->setKey('pusher') 131 ->setLabel(pht('Pusher')), 132 id(new PhabricatorPHIDExportField()) 133 ->setKey('devicePHID') 134 ->setLabel(pht('Device PHID')), 135 id(new PhabricatorStringExportField()) 136 ->setKey('device') 137 ->setLabel(pht('Device')), 138 id(new PhabricatorStringExportField()) 139 ->setKey('type') 140 ->setLabel(pht('Ref Type')), 141 id(new PhabricatorStringExportField()) 142 ->setKey('name') 143 ->setLabel(pht('Ref Name')), 144 id(new PhabricatorStringExportField()) 145 ->setKey('old') 146 ->setLabel(pht('Ref Old')), 147 id(new PhabricatorStringExportField()) 148 ->setKey('new') 149 ->setLabel(pht('Ref New')), 150 id(new PhabricatorIntExportField()) 151 ->setKey('flags') 152 ->setLabel(pht('Flags')), 153 id(new PhabricatorStringListExportField()) 154 ->setKey('flagNames') 155 ->setLabel(pht('Flag Names')), 156 id(new PhabricatorIntExportField()) 157 ->setKey('result') 158 ->setLabel(pht('Result')), 159 id(new PhabricatorStringExportField()) 160 ->setKey('resultName') 161 ->setLabel(pht('Result Name')), 162 id(new PhabricatorStringExportField()) 163 ->setKey('resultDetails') 164 ->setLabel(pht('Result Details')), 165 id(new PhabricatorIntExportField()) 166 ->setKey('hostWait') 167 ->setLabel(pht('Host Wait (us)')), 168 id(new PhabricatorIntExportField()) 169 ->setKey('writeWait') 170 ->setLabel(pht('Write Wait (us)')), 171 id(new PhabricatorIntExportField()) 172 ->setKey('readWait') 173 ->setLabel(pht('Read Wait (us)')), 174 id(new PhabricatorIntExportField()) 175 ->setKey('hookWait') 176 ->setLabel(pht('Hook Wait (us)')), 177 ); 178 179 if ($viewer->getIsAdmin()) { 180 $fields[] = id(new PhabricatorStringExportField()) 181 ->setKey('remoteAddress') 182 ->setLabel(pht('Remote Address')); 183 } 184 185 return $fields; 186 } 187 188 protected function newExportData(array $logs) { 189 $viewer = $this->requireViewer(); 190 191 $phids = array(); 192 foreach ($logs as $log) { 193 $phids[] = $log->getPusherPHID(); 194 $phids[] = $log->getDevicePHID(); 195 $phids[] = $log->getPushEvent()->getRepositoryPHID(); 196 } 197 $handles = $viewer->loadHandles($phids); 198 199 $flag_map = PhabricatorRepositoryPushLog::getFlagDisplayNames(); 200 $reject_map = PhabricatorRepositoryPushLog::getRejectCodeDisplayNames(); 201 202 $export = array(); 203 foreach ($logs as $log) { 204 $event = $log->getPushEvent(); 205 206 $repository_phid = $event->getRepositoryPHID(); 207 if ($repository_phid) { 208 $repository_name = $handles[$repository_phid]->getName(); 209 } else { 210 $repository_name = null; 211 } 212 213 $pusher_phid = $log->getPusherPHID(); 214 if ($pusher_phid) { 215 $pusher_name = $handles[$pusher_phid]->getName(); 216 } else { 217 $pusher_name = null; 218 } 219 220 $device_phid = $log->getDevicePHID(); 221 if ($device_phid) { 222 $device_name = $handles[$device_phid]->getName(); 223 } else { 224 $device_name = null; 225 } 226 227 $flags = $log->getChangeFlags(); 228 $flag_names = array(); 229 foreach ($flag_map as $flag_key => $flag_name) { 230 if (($flags & $flag_key) === $flag_key) { 231 $flag_names[] = $flag_name; 232 } 233 } 234 235 $result = $event->getRejectCode(); 236 $result_name = idx($reject_map, $result, pht('Unknown ("%s")', $result)); 237 238 $map = array( 239 'pushID' => $event->getID(), 240 'unique' => $event->getRequestIdentifier(), 241 'protocol' => $event->getRemoteProtocol(), 242 'repositoryPHID' => $repository_phid, 243 'repository' => $repository_name, 244 'pusherPHID' => $pusher_phid, 245 'pusher' => $pusher_name, 246 'devicePHID' => $device_phid, 247 'device' => $device_name, 248 'type' => $log->getRefType(), 249 'name' => $log->getRefName(), 250 'old' => $log->getRefOld(), 251 'new' => $log->getRefNew(), 252 'flags' => $flags, 253 'flagNames' => $flag_names, 254 'result' => $result, 255 'resultName' => $result_name, 256 'resultDetails' => $event->getRejectDetails(), 257 'hostWait' => $event->getHostWait(), 258 'writeWait' => $event->getWriteWait(), 259 'readWait' => $event->getReadWait(), 260 'hookWait' => $event->getHookWait(), 261 ); 262 263 if ($viewer->getIsAdmin()) { 264 $map['remoteAddress'] = $event->getRemoteAddress(); 265 } 266 267 $export[] = $map; 268 } 269 270 return $export; 271 } 272 273}