3 final class PhabricatorRepositoryPushLogSearchEngine
4 extends PhabricatorApplicationSearchEngine
{
6 public function getResultTypeDescription() {
7 return pht('Push Logs');
10 public function getApplicationClassName() {
11 return 'PhabricatorDiffusionApplication';
14 public function newQuery() {
15 return new PhabricatorRepositoryPushLogQuery();
18 protected function buildQueryFromParameters(array $map) {
19 $query = $this->newQuery();
21 if ($map['repositoryPHIDs']) {
22 $query->withRepositoryPHIDs($map['repositoryPHIDs']);
25 if ($map['pusherPHIDs']) {
26 $query->withPusherPHIDs($map['pusherPHIDs']);
29 if ($map['createdStart'] ||
$map['createdEnd']) {
30 $query->withEpochBetween(
35 if ($map['blockingHeraldRulePHIDs']) {
36 $query->withBlockingHeraldRulePHIDs($map['blockingHeraldRulePHIDs']);
42 protected function buildCustomSearchFields() {
44 id(new PhabricatorSearchDatasourceField())
45 ->setDatasource(new DiffusionRepositoryDatasource())
46 ->setKey('repositoryPHIDs')
47 ->setAliases(array('repository', 'repositories', 'repositoryPHID'))
48 ->setLabel(pht('Repositories'))
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'))
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'))
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'),
72 protected function getURI($path) {
73 return '/diffusion/pushlog/'.$path;
76 protected function getBuiltinQueryNames() {
78 'all' => pht('All Push Logs'),
82 public function buildSavedQueryFromBuiltin($query_key) {
83 $query = $this->newSavedQuery();
84 $query->setQueryKey($query_key);
91 return parent
::buildSavedQueryFromBuiltin($query_key);
94 protected function renderResultList(
96 PhabricatorSavedQuery
$query,
99 $table = id(new DiffusionPushLogListView())
100 ->setViewer($this->requireViewer())
103 return id(new PhabricatorApplicationSearchResultView())
107 protected function newExportFields() {
108 $viewer = $this->requireViewer();
111 id(new PhabricatorIDExportField())
113 ->setLabel(pht('Push ID')),
114 id(new PhabricatorStringExportField())
116 ->setLabel(pht('Unique')),
117 id(new PhabricatorStringExportField())
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())
131 ->setLabel(pht('Pusher')),
132 id(new PhabricatorPHIDExportField())
133 ->setKey('devicePHID')
134 ->setLabel(pht('Device PHID')),
135 id(new PhabricatorStringExportField())
137 ->setLabel(pht('Device')),
138 id(new PhabricatorStringExportField())
140 ->setLabel(pht('Ref Type')),
141 id(new PhabricatorStringExportField())
143 ->setLabel(pht('Ref Name')),
144 id(new PhabricatorStringExportField())
146 ->setLabel(pht('Ref Old')),
147 id(new PhabricatorStringExportField())
149 ->setLabel(pht('Ref New')),
150 id(new PhabricatorIntExportField())
152 ->setLabel(pht('Flags')),
153 id(new PhabricatorStringListExportField())
154 ->setKey('flagNames')
155 ->setLabel(pht('Flag Names')),
156 id(new PhabricatorIntExportField())
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())
167 ->setLabel(pht('Host Wait (us)')),
168 id(new PhabricatorIntExportField())
169 ->setKey('writeWait')
170 ->setLabel(pht('Write Wait (us)')),
171 id(new PhabricatorIntExportField())
173 ->setLabel(pht('Read Wait (us)')),
174 id(new PhabricatorIntExportField())
176 ->setLabel(pht('Hook Wait (us)')),
179 if ($viewer->getIsAdmin()) {
180 $fields[] = id(new PhabricatorStringExportField())
181 ->setKey('remoteAddress')
182 ->setLabel(pht('Remote Address'));
188 protected function newExportData(array $logs) {
189 $viewer = $this->requireViewer();
192 foreach ($logs as $log) {
193 $phids[] = $log->getPusherPHID();
194 $phids[] = $log->getDevicePHID();
195 $phids[] = $log->getPushEvent()->getRepositoryPHID();
197 $handles = $viewer->loadHandles($phids);
199 $flag_map = PhabricatorRepositoryPushLog
::getFlagDisplayNames();
200 $reject_map = PhabricatorRepositoryPushLog
::getRejectCodeDisplayNames();
203 foreach ($logs as $log) {
204 $event = $log->getPushEvent();
206 $repository_phid = $event->getRepositoryPHID();
207 if ($repository_phid) {
208 $repository_name = $handles[$repository_phid]->getName();
210 $repository_name = null;
213 $pusher_phid = $log->getPusherPHID();
215 $pusher_name = $handles[$pusher_phid]->getName();
220 $device_phid = $log->getDevicePHID();
222 $device_name = $handles[$device_phid]->getName();
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;
235 $result = $event->getRejectCode();
236 $result_name = idx($reject_map, $result, pht('Unknown ("%s")', $result));
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(),
253 'flagNames' => $flag_names,
255 'resultName' => $result_name,
256 'resultDetails' => $event->getRejectDetails(),
257 'hostWait' => $event->getHostWait(),
258 'writeWait' => $event->getWriteWait(),
259 'readWait' => $event->getReadWait(),
260 'hookWait' => $event->getHookWait(),
263 if ($viewer->getIsAdmin()) {
264 $map['remoteAddress'] = $event->getRemoteAddress();