mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-30 01:10:58 +01:00
Allow repository push logs to be filtered by pusher and repository
Summary: Ref T4195. Add UI options to filter push logs by pusher and repository. Add a link from the repository view page to the push logs. Test Plan: Viewed a hosted repository, clicked logs link, saw logs. Filtered lgos by repo/pusher. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4195 Differential Revision: https://secure.phabricator.com/D7713
This commit is contained in:
parent
e28b848ab2
commit
3f50460149
4 changed files with 132 additions and 0 deletions
|
@ -399,6 +399,18 @@ final class DiffusionRepositoryController extends DiffusionController {
|
|||
->setWorkflow(!$can_edit)
|
||||
->setDisabled(!$can_edit));
|
||||
|
||||
if ($repository->isHosted()) {
|
||||
$callsign = $repository->getCallsign();
|
||||
$push_uri = $this->getApplicationURI(
|
||||
'pushlog/?repositories=r'.$callsign);
|
||||
|
||||
$view->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName(pht('View Push Logs'))
|
||||
->setIcon('transcript')
|
||||
->setHref($push_uri));
|
||||
}
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ final class PhabricatorRepositoryPushLogQuery
|
|||
|
||||
private $ids;
|
||||
private $repositoryPHIDs;
|
||||
private $pusherPHIDs;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
|
@ -16,6 +17,11 @@ final class PhabricatorRepositoryPushLogQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withPusherPHIDs(array $pusher_phids) {
|
||||
$this->pusherPHIDs = $pusher_phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
$table = new PhabricatorRepositoryPushLog();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
@ -73,6 +79,13 @@ final class PhabricatorRepositoryPushLogQuery
|
|||
$this->repositoryPHIDs);
|
||||
}
|
||||
|
||||
if ($this->pusherPHIDs) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'pusherPHID in (%Ls)',
|
||||
$this->pusherPHIDs);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
|
|
|
@ -6,12 +6,37 @@ final class PhabricatorRepositoryPushLogSearchEngine
|
|||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
$saved = new PhabricatorSavedQuery();
|
||||
|
||||
$saved->setParameter(
|
||||
'repositoryPHIDs',
|
||||
$this->readPHIDsFromRequest(
|
||||
$request,
|
||||
'repositories',
|
||||
array(
|
||||
PhabricatorRepositoryPHIDTypeRepository::TYPECONST,
|
||||
)));
|
||||
|
||||
$saved->setParameter(
|
||||
'pusherPHIDs',
|
||||
$this->readUsersFromRequest(
|
||||
$request,
|
||||
'pushers'));
|
||||
|
||||
return $saved;
|
||||
}
|
||||
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
$query = id(new PhabricatorRepositoryPushLogQuery());
|
||||
|
||||
$repository_phids = $saved->getParameter('repositoryPHIDs');
|
||||
if ($repository_phids) {
|
||||
$query->withRepositoryPHIDs($repository_phids);
|
||||
}
|
||||
|
||||
$pusher_phids = $saved->getParameter('pusherPHIDs');
|
||||
if ($pusher_phids) {
|
||||
$query->withPusherPHIDs($pusher_phids);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
@ -19,6 +44,38 @@ final class PhabricatorRepositoryPushLogSearchEngine
|
|||
AphrontFormView $form,
|
||||
PhabricatorSavedQuery $saved_query) {
|
||||
|
||||
$repository_phids = $saved_query->getParameter('repositoryPHIDs', array());
|
||||
$pusher_phids = $saved_query->getParameter('pusherPHIDs', array());
|
||||
|
||||
$all_phids = array_merge(
|
||||
$repository_phids,
|
||||
$pusher_phids);
|
||||
|
||||
if ($all_phids) {
|
||||
$handles = id(new PhabricatorHandleQuery())
|
||||
->setViewer($this->requireViewer())
|
||||
->withPHIDs($all_phids)
|
||||
->execute();
|
||||
} else {
|
||||
$handles = array();
|
||||
}
|
||||
|
||||
$repository_handles = array_select_keys($handles, $repository_phids);
|
||||
$pusher_handles = array_select_keys($handles, $pusher_phids);
|
||||
|
||||
$form
|
||||
->appendChild(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setDatasource('/typeahead/common/repositories/')
|
||||
->setName('repositories')
|
||||
->setLabel(pht('Repositories'))
|
||||
->setValue($repository_handles))
|
||||
->appendChild(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setDatasource('/typeahead/common/accounts/')
|
||||
->setName('pushers')
|
||||
->setLabel(pht('Pushers'))
|
||||
->setValue($pusher_handles));
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
|
|
|
@ -299,6 +299,56 @@ abstract class PhabricatorApplicationSearchEngine {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read a list of generic PHIDs from a request in a flexible way. Like
|
||||
* @{method:readUsersFromRequest}, this method supports either array or
|
||||
* comma-delimited forms. Objects can be specified either by PHID or by
|
||||
* object name.
|
||||
*
|
||||
* @param AphrontRequest Request to read PHIDs from.
|
||||
* @param string Key to read in the request.
|
||||
* @param list<const> Optional, list of permitted PHID types.
|
||||
* @return list<phid> List of object PHIDs.
|
||||
*
|
||||
* @task read
|
||||
*/
|
||||
protected function readPHIDsFromRequest(
|
||||
AphrontRequest $request,
|
||||
$key,
|
||||
array $allow_types = array()) {
|
||||
|
||||
$list = $request->getArr($key, null);
|
||||
if ($list === null) {
|
||||
$list = $request->getStrList($key);
|
||||
}
|
||||
|
||||
if (!$list) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$objects = id(new PhabricatorObjectQuery())
|
||||
->setViewer($this->requireViewer())
|
||||
->withNames($list)
|
||||
->execute();
|
||||
$list = mpull($objects, 'getPHID');
|
||||
|
||||
if (!$list) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// If only certain PHID types are allowed, filter out all the others.
|
||||
if ($allow_types) {
|
||||
$allow_types = array_fuse($allow_types);
|
||||
foreach ($list as $key => $phid) {
|
||||
if (empty($allow_types[phid_get_type($phid)])) {
|
||||
unset($list[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
protected function readBoolFromRequest(
|
||||
AphrontRequest $request,
|
||||
$key) {
|
||||
|
|
Loading…
Reference in a new issue