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
This commit is contained in:
@@ -121,7 +121,7 @@ final class PhabricatorDiffusionApplication extends PhabricatorApplication {
|
|||||||
$this->getEditRoutePattern('edit/') =>
|
$this->getEditRoutePattern('edit/') =>
|
||||||
'DiffusionRepositoryEditController',
|
'DiffusionRepositoryEditController',
|
||||||
'pushlog/' => array(
|
'pushlog/' => array(
|
||||||
'(?:query/(?P<queryKey>[^/]+)/)?' => 'DiffusionPushLogListController',
|
$this->getQueryRoutePattern() => 'DiffusionPushLogListController',
|
||||||
'view/(?P<id>\d+)/' => 'DiffusionPushEventViewController',
|
'view/(?P<id>\d+)/' => 'DiffusionPushEventViewController',
|
||||||
),
|
),
|
||||||
'pulllog/' => array(
|
'pulllog/' => array(
|
||||||
|
|||||||
@@ -46,19 +46,12 @@ final class PhabricatorRepositoryPushLogQuery
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function newResultObject() {
|
||||||
|
return new PhabricatorRepositoryPushLog();
|
||||||
|
}
|
||||||
|
|
||||||
protected function loadPage() {
|
protected function loadPage() {
|
||||||
$table = new PhabricatorRepositoryPushLog();
|
return $this->loadStandardPage($this->newResultObject());
|
||||||
$conn_r = $table->establishConnection('r');
|
|
||||||
|
|
||||||
$data = queryfx_all(
|
|
||||||
$conn_r,
|
|
||||||
'SELECT * FROM %T %Q %Q %Q',
|
|
||||||
$table->getTableName(),
|
|
||||||
$this->buildWhereClause($conn_r),
|
|
||||||
$this->buildOrderClause($conn_r),
|
|
||||||
$this->buildLimitClause($conn_r));
|
|
||||||
|
|
||||||
return $table->loadAllFromArray($data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function willFilterPage(array $logs) {
|
protected function willFilterPage(array $logs) {
|
||||||
@@ -82,61 +75,59 @@ final class PhabricatorRepositoryPushLogQuery
|
|||||||
return $logs;
|
return $logs;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||||
$where = array();
|
$where = parent::buildWhereClauseParts($conn);
|
||||||
|
|
||||||
if ($this->ids) {
|
if ($this->ids !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'id IN (%Ld)',
|
'id IN (%Ld)',
|
||||||
$this->ids);
|
$this->ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->phids) {
|
if ($this->phids !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'phid IN (%Ls)',
|
'phid IN (%Ls)',
|
||||||
$this->phids);
|
$this->phids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->repositoryPHIDs) {
|
if ($this->repositoryPHIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'repositoryPHID IN (%Ls)',
|
'repositoryPHID IN (%Ls)',
|
||||||
$this->repositoryPHIDs);
|
$this->repositoryPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->pusherPHIDs) {
|
if ($this->pusherPHIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'pusherPHID in (%Ls)',
|
'pusherPHID in (%Ls)',
|
||||||
$this->pusherPHIDs);
|
$this->pusherPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->pushEventPHIDs) {
|
if ($this->pushEventPHIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'pushEventPHID in (%Ls)',
|
'pushEventPHID in (%Ls)',
|
||||||
$this->pushEventPHIDs);
|
$this->pushEventPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->refTypes) {
|
if ($this->refTypes !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'refType IN (%Ls)',
|
'refType IN (%Ls)',
|
||||||
$this->refTypes);
|
$this->refTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->newRefs) {
|
if ($this->newRefs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'refNew IN (%Ls)',
|
'refNew IN (%Ls)',
|
||||||
$this->newRefs);
|
$this->newRefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
$where[] = $this->buildPagingClause($conn_r);
|
return $where;
|
||||||
|
|
||||||
return $this->formatWhereClause($where);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getQueryApplicationClass() {
|
public function getQueryApplicationClass() {
|
||||||
|
|||||||
@@ -82,4 +82,146 @@ final class PhabricatorRepositoryPushLogSearchEngine
|
|||||||
->setTable($table);
|
->setTable($table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function newExportFields() {
|
||||||
|
$viewer = $this->requireViewer();
|
||||||
|
|
||||||
|
$fields = array(
|
||||||
|
$fields[] = id(new PhabricatorIDExportField())
|
||||||
|
->setKey('pushID')
|
||||||
|
->setLabel(pht('Push ID')),
|
||||||
|
$fields[] = id(new PhabricatorStringExportField())
|
||||||
|
->setKey('protocol')
|
||||||
|
->setLabel(pht('Protocol')),
|
||||||
|
$fields[] = id(new PhabricatorPHIDExportField())
|
||||||
|
->setKey('repositoryPHID')
|
||||||
|
->setLabel(pht('Repository PHID')),
|
||||||
|
$fields[] = id(new PhabricatorStringExportField())
|
||||||
|
->setKey('repository')
|
||||||
|
->setLabel(pht('Repository')),
|
||||||
|
$fields[] = id(new PhabricatorPHIDExportField())
|
||||||
|
->setKey('pusherPHID')
|
||||||
|
->setLabel(pht('Pusher PHID')),
|
||||||
|
$fields[] = id(new PhabricatorStringExportField())
|
||||||
|
->setKey('pusher')
|
||||||
|
->setLabel(pht('Pusher')),
|
||||||
|
$fields[] = id(new PhabricatorPHIDExportField())
|
||||||
|
->setKey('devicePHID')
|
||||||
|
->setLabel(pht('Device PHID')),
|
||||||
|
$fields[] = id(new PhabricatorStringExportField())
|
||||||
|
->setKey('device')
|
||||||
|
->setLabel(pht('Device')),
|
||||||
|
$fields[] = id(new PhabricatorStringExportField())
|
||||||
|
->setKey('type')
|
||||||
|
->setLabel(pht('Ref Type')),
|
||||||
|
$fields[] = id(new PhabricatorStringExportField())
|
||||||
|
->setKey('name')
|
||||||
|
->setLabel(pht('Ref Name')),
|
||||||
|
$fields[] = id(new PhabricatorStringExportField())
|
||||||
|
->setKey('old')
|
||||||
|
->setLabel(pht('Ref Old')),
|
||||||
|
$fields[] = id(new PhabricatorStringExportField())
|
||||||
|
->setKey('new')
|
||||||
|
->setLabel(pht('Ref New')),
|
||||||
|
$fields[] = id(new PhabricatorIntExportField())
|
||||||
|
->setKey('flags')
|
||||||
|
->setLabel(pht('Flags')),
|
||||||
|
$fields[] = id(new PhabricatorStringListExportField())
|
||||||
|
->setKey('flagNames')
|
||||||
|
->setLabel(pht('Flag Names')),
|
||||||
|
$fields[] = id(new PhabricatorIntExportField())
|
||||||
|
->setKey('result')
|
||||||
|
->setLabel(pht('Result')),
|
||||||
|
$fields[] = id(new PhabricatorStringExportField())
|
||||||
|
->setKey('resultName')
|
||||||
|
->setLabel(pht('Result Name')),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($viewer->getIsAdmin()) {
|
||||||
|
$fields[] = id(new PhabricatorStringExportField())
|
||||||
|
->setKey('remoteAddress')
|
||||||
|
->setLabel(pht('Remote Address'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function newExportData(array $logs) {
|
||||||
|
$viewer = $this->requireViewer();
|
||||||
|
|
||||||
|
$phids = array();
|
||||||
|
foreach ($logs as $log) {
|
||||||
|
$phids[] = $log->getPusherPHID();
|
||||||
|
$phids[] = $log->getDevicePHID();
|
||||||
|
$phids[] = $log->getPushEvent()->getRepositoryPHID();
|
||||||
|
}
|
||||||
|
$handles = $viewer->loadHandles($phids);
|
||||||
|
|
||||||
|
$flag_map = PhabricatorRepositoryPushLog::getFlagDisplayNames();
|
||||||
|
$reject_map = PhabricatorRepositoryPushLog::getRejectCodeDisplayNames();
|
||||||
|
|
||||||
|
$export = array();
|
||||||
|
foreach ($logs as $log) {
|
||||||
|
$event = $log->getPushEvent();
|
||||||
|
|
||||||
|
$repository_phid = $event->getRepositoryPHID();
|
||||||
|
if ($repository_phid) {
|
||||||
|
$repository_name = $handles[$repository_phid]->getName();
|
||||||
|
} else {
|
||||||
|
$repository_name = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pusher_phid = $log->getPusherPHID();
|
||||||
|
if ($pusher_phid) {
|
||||||
|
$pusher_name = $handles[$pusher_phid]->getName();
|
||||||
|
} else {
|
||||||
|
$pusher_name = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$device_phid = $log->getDevicePHID();
|
||||||
|
if ($device_phid) {
|
||||||
|
$device_name = $handles[$device_phid]->getName();
|
||||||
|
} else {
|
||||||
|
$device_name = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$flags = $log->getChangeFlags();
|
||||||
|
$flag_names = array();
|
||||||
|
foreach ($flag_map as $flag_key => $flag_name) {
|
||||||
|
if (($flags & $flag_key) === $flag_key) {
|
||||||
|
$flag_names[] = $flag_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $event->getRejectCode();
|
||||||
|
$result_name = idx($reject_map, $result, pht('Unknown ("%s")', $result));
|
||||||
|
|
||||||
|
$map = array(
|
||||||
|
'pushID' => $event->getID(),
|
||||||
|
'protocol' => $event->getRemoteProtocol(),
|
||||||
|
'repositoryPHID' => $repository_phid,
|
||||||
|
'repository' => $repository_name,
|
||||||
|
'pusherPHID' => $pusher_phid,
|
||||||
|
'pusher' => $pusher_name,
|
||||||
|
'devicePHID' => $device_phid,
|
||||||
|
'device' => $device_name,
|
||||||
|
'type' => $log->getRefType(),
|
||||||
|
'name' => $log->getRefName(),
|
||||||
|
'old' => $log->getRefOld(),
|
||||||
|
'new' => $log->getRefNew(),
|
||||||
|
'flags' => $flags,
|
||||||
|
'flagNames' => $flag_names,
|
||||||
|
'result' => $result,
|
||||||
|
'resultName' => $result_name,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($viewer->getIsAdmin()) {
|
||||||
|
$map['remoteAddress'] = $event->getRemoteAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
$export[] = $map;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $export;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,28 @@ final class PhabricatorRepositoryPushLog
|
|||||||
->setPusherPHID($viewer->getPHID());
|
->setPusherPHID($viewer->getPHID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getFlagDisplayNames() {
|
||||||
|
return array(
|
||||||
|
self::CHANGEFLAG_ADD => pht('Create'),
|
||||||
|
self::CHANGEFLAG_DELETE => pht('Delete'),
|
||||||
|
self::CHANGEFLAG_APPEND => pht('Append'),
|
||||||
|
self::CHANGEFLAG_REWRITE => pht('Rewrite'),
|
||||||
|
self::CHANGEFLAG_DANGEROUS => pht('Dangerous'),
|
||||||
|
self::CHANGEFLAG_ENORMOUS => pht('Enormous'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRejectCodeDisplayNames() {
|
||||||
|
return array(
|
||||||
|
self::REJECT_ACCEPT => pht('Accepted'),
|
||||||
|
self::REJECT_DANGEROUS => pht('Rejected: Dangerous'),
|
||||||
|
self::REJECT_HERALD => pht('Rejected: Herald'),
|
||||||
|
self::REJECT_EXTERNAL => pht('Rejected: External Hook'),
|
||||||
|
self::REJECT_BROKEN => pht('Rejected: Broken'),
|
||||||
|
self::REJECT_ENORMOUS => pht('Rejected: Enormous'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static function getHeraldChangeFlagConditionOptions() {
|
public static function getHeraldChangeFlagConditionOptions() {
|
||||||
return array(
|
return array(
|
||||||
self::CHANGEFLAG_ADD =>
|
self::CHANGEFLAG_ADD =>
|
||||||
|
|||||||
Reference in New Issue
Block a user