@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 202 lines 5.1 kB view raw
1<?php 2 3final class DiffusionPushLogListView extends AphrontView { 4 5 private $logs; 6 7 /** 8 * @param array<PhabricatorRepositoryPushLog> $logs 9 */ 10 public function setLogs(array $logs) { 11 assert_instances_of($logs, PhabricatorRepositoryPushLog::class); 12 $this->logs = $logs; 13 return $this; 14 } 15 16 public function render() { 17 $logs = $this->logs; 18 $viewer = $this->getViewer(); 19 20 $reject_herald = PhabricatorRepositoryPushLog::REJECT_HERALD; 21 22 $handle_phids = array(); 23 foreach ($logs as $log) { 24 $handle_phids[] = $log->getPusherPHID(); 25 $device_phid = $log->getDevicePHID(); 26 if ($device_phid) { 27 $handle_phids[] = $device_phid; 28 } 29 30 if ($log->getPushEvent()->getRejectCode() == $reject_herald) { 31 $handle_phids[] = $log->getPushEvent()->getRejectDetails(); 32 } 33 } 34 35 $viewer->loadHandles($handle_phids); 36 37 // Only administrators can view remote addresses. 38 $remotes_visible = $viewer->getIsAdmin(); 39 40 $flag_map = PhabricatorRepositoryPushLog::getFlagDisplayNames(); 41 $reject_map = PhabricatorRepositoryPushLog::getRejectCodeDisplayNames(); 42 43 $rows = array(); 44 $any_host = false; 45 foreach ($logs as $log) { 46 $repository = $log->getRepository(); 47 $event = $log->getPushEvent(); 48 49 if ($remotes_visible) { 50 $remote_address = $event->getRemoteAddress(); 51 } else { 52 $remote_address = null; 53 } 54 55 $event_id = $log->getPushEvent()->getID(); 56 57 $old_ref_link = null; 58 if ($log->getRefOld() != DiffusionCommitHookEngine::EMPTY_HASH) { 59 $old_ref_link = phutil_tag( 60 'a', 61 array( 62 'href' => $repository->getCommitURI($log->getRefOld()), 63 ), 64 $log->getRefOldShort()); 65 } 66 67 $device_phid = $log->getDevicePHID(); 68 if ($device_phid) { 69 $device = $viewer->renderHandle($device_phid); 70 $any_host = true; 71 } else { 72 $device = null; 73 } 74 75 $flags = $log->getChangeFlags(); 76 $flag_names = array(); 77 foreach ($flag_map as $flag_key => $flag_name) { 78 if (($flags & $flag_key) === $flag_key) { 79 $flag_names[] = $flag_name; 80 } 81 } 82 $flag_names = phutil_implode_html( 83 phutil_tag('br'), 84 $flag_names); 85 86 $reject_code = $event->getRejectCode(); 87 88 if ($reject_code == $reject_herald) { 89 $rule_phid = $event->getRejectDetails(); 90 $handle = $viewer->renderHandle($rule_phid); 91 $reject_label = pht('Blocked: %s', $handle); 92 } else { 93 $reject_label = idx( 94 $reject_map, 95 $reject_code, 96 pht('Unknown ("%s")', $reject_code)); 97 } 98 99 $host_wait = $this->formatMicroseconds($event->getHostWait()); 100 $write_wait = $this->formatMicroseconds($event->getWriteWait()); 101 $read_wait = $this->formatMicroseconds($event->getReadWait()); 102 $hook_wait = $this->formatMicroseconds($event->getHookWait()); 103 104 $rows[] = array( 105 phutil_tag( 106 'a', 107 array( 108 'href' => '/diffusion/pushlog/view/'.$event_id.'/', 109 ), 110 $event_id), 111 phutil_tag( 112 'a', 113 array( 114 'href' => $repository->getURI(), 115 ), 116 $repository->getDisplayName()), 117 $viewer->renderHandle($log->getPusherPHID()), 118 $remote_address, 119 $event->getRemoteProtocol(), 120 $device, 121 $log->getRefType(), 122 $log->getRefName(), 123 $old_ref_link, 124 phutil_tag( 125 'a', 126 array( 127 'href' => $repository->getCommitURI($log->getRefNew()), 128 ), 129 $log->getRefNewShort()), 130 $flag_names, 131 $reject_label, 132 $viewer->formatShortDateTime($log->getEpoch()), 133 $host_wait, 134 $write_wait, 135 $read_wait, 136 $hook_wait, 137 ); 138 } 139 140 $table = id(new AphrontTableView($rows)) 141 ->setHeaders( 142 array( 143 pht('Push'), 144 pht('Repository'), 145 pht('Pusher'), 146 pht('From'), 147 pht('Via'), 148 pht('Host'), 149 pht('Type'), 150 pht('Name'), 151 pht('Old'), 152 pht('New'), 153 pht('Flags'), 154 pht('Result'), 155 pht('Date'), 156 pht('Host Wait'), 157 pht('Write Wait'), 158 pht('Read Wait'), 159 pht('Hook Wait'), 160 )) 161 ->setColumnClasses( 162 array( 163 '', 164 '', 165 '', 166 '', 167 '', 168 '', 169 '', 170 'wide', 171 'n', 172 'n', 173 '', 174 '', 175 'right', 176 'n right', 177 'n right', 178 'n right', 179 'n right', 180 )) 181 ->setColumnVisibility( 182 array( 183 true, 184 true, 185 true, 186 $remotes_visible, 187 true, 188 $any_host, 189 )); 190 191 return $table; 192 } 193 194 private function formatMicroseconds($duration) { 195 if ($duration === null) { 196 return null; 197 } 198 199 return pht('%sus', new PhutilNumber($duration)); 200 } 201 202}