@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.

Support data export on push logs

Summary: Depends on D18967. Ref T13049. Nothing too fancy going on here.

Test Plan: Exported push logs, looked at the export, seemed sensible.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13049

Differential Revision: https://secure.phabricator.com/D18968

+187 -32
+1 -1
src/applications/diffusion/application/PhabricatorDiffusionApplication.php
··· 121 121 $this->getEditRoutePattern('edit/') => 122 122 'DiffusionRepositoryEditController', 123 123 'pushlog/' => array( 124 - '(?:query/(?P<queryKey>[^/]+)/)?' => 'DiffusionPushLogListController', 124 + $this->getQueryRoutePattern() => 'DiffusionPushLogListController', 125 125 'view/(?P<id>\d+)/' => 'DiffusionPushEventViewController', 126 126 ), 127 127 'pulllog/' => array(
+22 -31
src/applications/repository/query/PhabricatorRepositoryPushLogQuery.php
··· 46 46 return $this; 47 47 } 48 48 49 - protected function loadPage() { 50 - $table = new PhabricatorRepositoryPushLog(); 51 - $conn_r = $table->establishConnection('r'); 49 + public function newResultObject() { 50 + return new PhabricatorRepositoryPushLog(); 51 + } 52 52 53 - $data = queryfx_all( 54 - $conn_r, 55 - 'SELECT * FROM %T %Q %Q %Q', 56 - $table->getTableName(), 57 - $this->buildWhereClause($conn_r), 58 - $this->buildOrderClause($conn_r), 59 - $this->buildLimitClause($conn_r)); 60 - 61 - return $table->loadAllFromArray($data); 53 + protected function loadPage() { 54 + return $this->loadStandardPage($this->newResultObject()); 62 55 } 63 56 64 57 protected function willFilterPage(array $logs) { ··· 82 75 return $logs; 83 76 } 84 77 85 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 86 - $where = array(); 78 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 79 + $where = parent::buildWhereClauseParts($conn); 87 80 88 - if ($this->ids) { 81 + if ($this->ids !== null) { 89 82 $where[] = qsprintf( 90 - $conn_r, 83 + $conn, 91 84 'id IN (%Ld)', 92 85 $this->ids); 93 86 } 94 87 95 - if ($this->phids) { 88 + if ($this->phids !== null) { 96 89 $where[] = qsprintf( 97 - $conn_r, 90 + $conn, 98 91 'phid IN (%Ls)', 99 92 $this->phids); 100 93 } 101 94 102 - if ($this->repositoryPHIDs) { 95 + if ($this->repositoryPHIDs !== null) { 103 96 $where[] = qsprintf( 104 - $conn_r, 97 + $conn, 105 98 'repositoryPHID IN (%Ls)', 106 99 $this->repositoryPHIDs); 107 100 } 108 101 109 - if ($this->pusherPHIDs) { 102 + if ($this->pusherPHIDs !== null) { 110 103 $where[] = qsprintf( 111 - $conn_r, 104 + $conn, 112 105 'pusherPHID in (%Ls)', 113 106 $this->pusherPHIDs); 114 107 } 115 108 116 - if ($this->pushEventPHIDs) { 109 + if ($this->pushEventPHIDs !== null) { 117 110 $where[] = qsprintf( 118 - $conn_r, 111 + $conn, 119 112 'pushEventPHID in (%Ls)', 120 113 $this->pushEventPHIDs); 121 114 } 122 115 123 - if ($this->refTypes) { 116 + if ($this->refTypes !== null) { 124 117 $where[] = qsprintf( 125 - $conn_r, 118 + $conn, 126 119 'refType IN (%Ls)', 127 120 $this->refTypes); 128 121 } 129 122 130 - if ($this->newRefs) { 123 + if ($this->newRefs !== null) { 131 124 $where[] = qsprintf( 132 - $conn_r, 125 + $conn, 133 126 'refNew IN (%Ls)', 134 127 $this->newRefs); 135 128 } 136 129 137 - $where[] = $this->buildPagingClause($conn_r); 138 - 139 - return $this->formatWhereClause($where); 130 + return $where; 140 131 } 141 132 142 133 public function getQueryApplicationClass() {
+142
src/applications/repository/query/PhabricatorRepositoryPushLogSearchEngine.php
··· 82 82 ->setTable($table); 83 83 } 84 84 85 + protected function newExportFields() { 86 + $viewer = $this->requireViewer(); 87 + 88 + $fields = array( 89 + $fields[] = id(new PhabricatorIDExportField()) 90 + ->setKey('pushID') 91 + ->setLabel(pht('Push ID')), 92 + $fields[] = id(new PhabricatorStringExportField()) 93 + ->setKey('protocol') 94 + ->setLabel(pht('Protocol')), 95 + $fields[] = id(new PhabricatorPHIDExportField()) 96 + ->setKey('repositoryPHID') 97 + ->setLabel(pht('Repository PHID')), 98 + $fields[] = id(new PhabricatorStringExportField()) 99 + ->setKey('repository') 100 + ->setLabel(pht('Repository')), 101 + $fields[] = id(new PhabricatorPHIDExportField()) 102 + ->setKey('pusherPHID') 103 + ->setLabel(pht('Pusher PHID')), 104 + $fields[] = id(new PhabricatorStringExportField()) 105 + ->setKey('pusher') 106 + ->setLabel(pht('Pusher')), 107 + $fields[] = id(new PhabricatorPHIDExportField()) 108 + ->setKey('devicePHID') 109 + ->setLabel(pht('Device PHID')), 110 + $fields[] = id(new PhabricatorStringExportField()) 111 + ->setKey('device') 112 + ->setLabel(pht('Device')), 113 + $fields[] = id(new PhabricatorStringExportField()) 114 + ->setKey('type') 115 + ->setLabel(pht('Ref Type')), 116 + $fields[] = id(new PhabricatorStringExportField()) 117 + ->setKey('name') 118 + ->setLabel(pht('Ref Name')), 119 + $fields[] = id(new PhabricatorStringExportField()) 120 + ->setKey('old') 121 + ->setLabel(pht('Ref Old')), 122 + $fields[] = id(new PhabricatorStringExportField()) 123 + ->setKey('new') 124 + ->setLabel(pht('Ref New')), 125 + $fields[] = id(new PhabricatorIntExportField()) 126 + ->setKey('flags') 127 + ->setLabel(pht('Flags')), 128 + $fields[] = id(new PhabricatorStringListExportField()) 129 + ->setKey('flagNames') 130 + ->setLabel(pht('Flag Names')), 131 + $fields[] = id(new PhabricatorIntExportField()) 132 + ->setKey('result') 133 + ->setLabel(pht('Result')), 134 + $fields[] = id(new PhabricatorStringExportField()) 135 + ->setKey('resultName') 136 + ->setLabel(pht('Result Name')), 137 + ); 138 + 139 + if ($viewer->getIsAdmin()) { 140 + $fields[] = id(new PhabricatorStringExportField()) 141 + ->setKey('remoteAddress') 142 + ->setLabel(pht('Remote Address')); 143 + } 144 + 145 + return $fields; 146 + } 147 + 148 + protected function newExportData(array $logs) { 149 + $viewer = $this->requireViewer(); 150 + 151 + $phids = array(); 152 + foreach ($logs as $log) { 153 + $phids[] = $log->getPusherPHID(); 154 + $phids[] = $log->getDevicePHID(); 155 + $phids[] = $log->getPushEvent()->getRepositoryPHID(); 156 + } 157 + $handles = $viewer->loadHandles($phids); 158 + 159 + $flag_map = PhabricatorRepositoryPushLog::getFlagDisplayNames(); 160 + $reject_map = PhabricatorRepositoryPushLog::getRejectCodeDisplayNames(); 161 + 162 + $export = array(); 163 + foreach ($logs as $log) { 164 + $event = $log->getPushEvent(); 165 + 166 + $repository_phid = $event->getRepositoryPHID(); 167 + if ($repository_phid) { 168 + $repository_name = $handles[$repository_phid]->getName(); 169 + } else { 170 + $repository_name = null; 171 + } 172 + 173 + $pusher_phid = $log->getPusherPHID(); 174 + if ($pusher_phid) { 175 + $pusher_name = $handles[$pusher_phid]->getName(); 176 + } else { 177 + $pusher_name = null; 178 + } 179 + 180 + $device_phid = $log->getDevicePHID(); 181 + if ($device_phid) { 182 + $device_name = $handles[$device_phid]->getName(); 183 + } else { 184 + $device_name = null; 185 + } 186 + 187 + $flags = $log->getChangeFlags(); 188 + $flag_names = array(); 189 + foreach ($flag_map as $flag_key => $flag_name) { 190 + if (($flags & $flag_key) === $flag_key) { 191 + $flag_names[] = $flag_name; 192 + } 193 + } 194 + 195 + $result = $event->getRejectCode(); 196 + $result_name = idx($reject_map, $result, pht('Unknown ("%s")', $result)); 197 + 198 + $map = array( 199 + 'pushID' => $event->getID(), 200 + 'protocol' => $event->getRemoteProtocol(), 201 + 'repositoryPHID' => $repository_phid, 202 + 'repository' => $repository_name, 203 + 'pusherPHID' => $pusher_phid, 204 + 'pusher' => $pusher_name, 205 + 'devicePHID' => $device_phid, 206 + 'device' => $device_name, 207 + 'type' => $log->getRefType(), 208 + 'name' => $log->getRefName(), 209 + 'old' => $log->getRefOld(), 210 + 'new' => $log->getRefNew(), 211 + 'flags' => $flags, 212 + 'flagNames' => $flag_names, 213 + 'result' => $result, 214 + 'resultName' => $result_name, 215 + ); 216 + 217 + if ($viewer->getIsAdmin()) { 218 + $map['remoteAddress'] = $event->getRemoteAddress(); 219 + } 220 + 221 + $export[] = $map; 222 + } 223 + 224 + return $export; 225 + } 226 + 85 227 }
+22
src/applications/repository/storage/PhabricatorRepositoryPushLog.php
··· 55 55 ->setPusherPHID($viewer->getPHID()); 56 56 } 57 57 58 + public static function getFlagDisplayNames() { 59 + return array( 60 + self::CHANGEFLAG_ADD => pht('Create'), 61 + self::CHANGEFLAG_DELETE => pht('Delete'), 62 + self::CHANGEFLAG_APPEND => pht('Append'), 63 + self::CHANGEFLAG_REWRITE => pht('Rewrite'), 64 + self::CHANGEFLAG_DANGEROUS => pht('Dangerous'), 65 + self::CHANGEFLAG_ENORMOUS => pht('Enormous'), 66 + ); 67 + } 68 + 69 + public static function getRejectCodeDisplayNames() { 70 + return array( 71 + self::REJECT_ACCEPT => pht('Accepted'), 72 + self::REJECT_DANGEROUS => pht('Rejected: Dangerous'), 73 + self::REJECT_HERALD => pht('Rejected: Herald'), 74 + self::REJECT_EXTERNAL => pht('Rejected: External Hook'), 75 + self::REJECT_BROKEN => pht('Rejected: Broken'), 76 + self::REJECT_ENORMOUS => pht('Rejected: Enormous'), 77 + ); 78 + } 79 + 58 80 public static function getHeraldChangeFlagConditionOptions() { 59 81 return array( 60 82 self::CHANGEFLAG_ADD =>