2014-05-13 23:00:24 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DiffusionPushLogListView extends AphrontView {
|
|
|
|
|
|
|
|
private $logs;
|
|
|
|
|
|
|
|
public function setLogs(array $logs) {
|
|
|
|
assert_instances_of($logs, 'PhabricatorRepositoryPushLog');
|
|
|
|
$this->logs = $logs;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
$logs = $this->logs;
|
2016-04-20 05:25:21 +02:00
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
$handle_phids = array();
|
|
|
|
foreach ($logs as $log) {
|
|
|
|
$handle_phids[] = $log->getPusherPHID();
|
|
|
|
$device_phid = $log->getDevicePHID();
|
|
|
|
if ($device_phid) {
|
|
|
|
$handle_phids[] = $device_phid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$handles = $viewer->loadHandles($handle_phids);
|
2014-05-13 23:00:24 +02:00
|
|
|
|
|
|
|
// Figure out which repositories are editable. We only let you see remote
|
|
|
|
// IPs if you have edit capability on a repository.
|
|
|
|
$editable_repos = array();
|
|
|
|
if ($logs) {
|
|
|
|
$editable_repos = id(new PhabricatorRepositoryQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->withPHIDs(mpull($logs, 'getRepositoryPHID'))
|
|
|
|
->execute();
|
|
|
|
$editable_repos = mpull($editable_repos, null, 'getPHID');
|
|
|
|
}
|
|
|
|
|
|
|
|
$rows = array();
|
2016-04-19 19:10:12 +02:00
|
|
|
$any_host = false;
|
2014-05-13 23:00:24 +02:00
|
|
|
foreach ($logs as $log) {
|
2016-01-02 20:28:31 +01:00
|
|
|
$repository = $log->getRepository();
|
2014-05-13 23:00:24 +02:00
|
|
|
|
|
|
|
// Reveal this if it's valid and the user can edit the repository.
|
2016-02-02 18:59:49 +01:00
|
|
|
$remote_address = '-';
|
2014-05-13 23:00:24 +02:00
|
|
|
if (isset($editable_repos[$log->getRepositoryPHID()])) {
|
2016-02-02 18:59:49 +01:00
|
|
|
$remote_address = $log->getPushEvent()->getRemoteAddress();
|
2014-05-13 23:00:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$event_id = $log->getPushEvent()->getID();
|
|
|
|
|
2014-12-31 00:17:49 +01:00
|
|
|
$old_ref_link = null;
|
|
|
|
if ($log->getRefOld() != DiffusionCommitHookEngine::EMPTY_HASH) {
|
|
|
|
$old_ref_link = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
2016-01-02 20:28:31 +01:00
|
|
|
'href' => $repository->getCommitURI($log->getRefOld()),
|
2014-12-31 00:17:49 +01:00
|
|
|
),
|
|
|
|
$log->getRefOldShort());
|
|
|
|
}
|
2016-01-02 20:28:31 +01:00
|
|
|
|
2016-04-19 19:10:12 +02:00
|
|
|
$device_phid = $log->getDevicePHID();
|
|
|
|
if ($device_phid) {
|
2016-04-20 05:25:21 +02:00
|
|
|
$device = $viewer->renderHandle($device_phid);
|
2016-04-19 19:10:12 +02:00
|
|
|
$any_host = true;
|
|
|
|
} else {
|
|
|
|
$device = null;
|
|
|
|
}
|
|
|
|
|
2014-05-13 23:00:24 +02:00
|
|
|
$rows[] = array(
|
|
|
|
phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/diffusion/pushlog/view/'.$event_id.'/',
|
|
|
|
),
|
|
|
|
$event_id),
|
|
|
|
phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
2016-01-02 20:28:31 +01:00
|
|
|
'href' => $repository->getURI(),
|
2014-05-13 23:00:24 +02:00
|
|
|
),
|
2016-01-02 20:28:31 +01:00
|
|
|
$repository->getDisplayName()),
|
2016-04-20 05:25:21 +02:00
|
|
|
$viewer->renderHandle($log->getPusherPHID()),
|
2016-02-02 18:59:49 +01:00
|
|
|
$remote_address,
|
2014-05-13 23:00:24 +02:00
|
|
|
$log->getPushEvent()->getRemoteProtocol(),
|
2016-04-19 19:10:12 +02:00
|
|
|
$device,
|
2014-05-13 23:00:24 +02:00
|
|
|
$log->getRefType(),
|
|
|
|
$log->getRefName(),
|
2014-12-31 00:17:49 +01:00
|
|
|
$old_ref_link,
|
2014-05-13 23:00:24 +02:00
|
|
|
phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
2016-01-02 20:28:31 +01:00
|
|
|
'href' => $repository->getCommitURI($log->getRefNew()),
|
2014-05-13 23:00:24 +02:00
|
|
|
),
|
|
|
|
$log->getRefNewShort()),
|
|
|
|
|
|
|
|
// TODO: Make these human-readable.
|
|
|
|
$log->getChangeFlags(),
|
|
|
|
$log->getPushEvent()->getRejectCode(),
|
2016-03-18 16:59:21 +01:00
|
|
|
$viewer->formatShortDateTime($log->getEpoch()),
|
2014-05-13 23:00:24 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = id(new AphrontTableView($rows))
|
|
|
|
->setHeaders(
|
|
|
|
array(
|
|
|
|
pht('Push'),
|
|
|
|
pht('Repository'),
|
|
|
|
pht('Pusher'),
|
|
|
|
pht('From'),
|
|
|
|
pht('Via'),
|
2016-04-19 19:10:12 +02:00
|
|
|
pht('Host'),
|
2014-05-13 23:00:24 +02:00
|
|
|
pht('Type'),
|
|
|
|
pht('Name'),
|
|
|
|
pht('Old'),
|
|
|
|
pht('New'),
|
|
|
|
pht('Flags'),
|
|
|
|
pht('Code'),
|
|
|
|
pht('Date'),
|
|
|
|
))
|
|
|
|
->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'',
|
2016-04-19 19:10:12 +02:00
|
|
|
'',
|
2014-05-13 23:00:24 +02:00
|
|
|
'wide',
|
|
|
|
'n',
|
|
|
|
'n',
|
2016-03-18 16:59:21 +01:00
|
|
|
'right',
|
2016-04-19 19:10:12 +02:00
|
|
|
))
|
|
|
|
->setColumnVisibility(
|
|
|
|
array(
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
$any_host,
|
2014-05-13 23:00:24 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
return $table;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|