2013-09-10 15:26:08 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
final class PhabricatorRepositorySearchEngine
|
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
|
2014-06-12 13:22:20 -07:00
|
|
|
public function getResultTypeDescription() {
|
|
|
|
|
return pht('Repositories');
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 15:47:48 -08:00
|
|
|
public function getApplicationClassName() {
|
2014-07-23 10:03:09 +10:00
|
|
|
return 'PhabricatorDiffusionApplication';
|
2014-05-08 10:08:37 -07:00
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:22:47 -07:00
|
|
|
public function newQuery() {
|
|
|
|
|
return id(new PhabricatorRepositoryQuery())
|
2014-01-03 12:24:09 -08:00
|
|
|
->needProjectPHIDs(true)
|
2013-09-10 15:26:08 -07:00
|
|
|
->needCommitCounts(true)
|
|
|
|
|
->needMostRecentCommits(true);
|
2015-06-08 12:22:47 -07:00
|
|
|
}
|
2013-09-10 15:26:08 -07:00
|
|
|
|
2015-06-08 12:22:47 -07:00
|
|
|
protected function buildCustomSearchFields() {
|
|
|
|
|
return array(
|
|
|
|
|
id(new PhabricatorSearchStringListField())
|
|
|
|
|
->setLabel(pht('Callsigns'))
|
|
|
|
|
->setKey('callsigns'),
|
|
|
|
|
id(new PhabricatorSearchTextField())
|
|
|
|
|
->setLabel(pht('Name Contains'))
|
|
|
|
|
->setKey('name'),
|
|
|
|
|
id(new PhabricatorSearchSelectField())
|
|
|
|
|
->setLabel(pht('Status'))
|
|
|
|
|
->setKey('status')
|
|
|
|
|
->setOptions($this->getStatusOptions()),
|
|
|
|
|
id(new PhabricatorSearchSelectField())
|
|
|
|
|
->setLabel(pht('Hosted'))
|
|
|
|
|
->setKey('hosted')
|
|
|
|
|
->setOptions($this->getHostedOptions()),
|
|
|
|
|
id(new PhabricatorSearchCheckboxesField())
|
|
|
|
|
->setLabel(pht('Types'))
|
|
|
|
|
->setKey('types')
|
|
|
|
|
->setOptions(PhabricatorRepositoryType::getAllRepositoryTypes()),
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-09-10 15:26:23 -07:00
|
|
|
|
2015-06-09 07:09:58 +10:00
|
|
|
protected function buildQueryFromParameters(array $map) {
|
2015-06-08 12:22:47 -07:00
|
|
|
$query = $this->newQuery();
|
2013-09-08 11:49:06 -07:00
|
|
|
|
2015-06-08 12:22:47 -07:00
|
|
|
if ($map['callsigns']) {
|
|
|
|
|
$query->withCallsigns($map['callsigns']);
|
2014-01-10 09:12:50 -08:00
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:22:47 -07:00
|
|
|
if ($map['status']) {
|
|
|
|
|
$status = idx($this->getStatusValues(), $map['status']);
|
|
|
|
|
if ($status) {
|
|
|
|
|
$query->withStatus($status);
|
|
|
|
|
}
|
2013-09-19 11:56:48 -07:00
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:22:47 -07:00
|
|
|
if ($map['hosted']) {
|
|
|
|
|
$hosted = idx($this->getHostedValues(), $map['hosted']);
|
|
|
|
|
if ($hosted) {
|
|
|
|
|
$query->withHosted($hosted);
|
|
|
|
|
}
|
2013-12-05 14:26:38 -08:00
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:22:47 -07:00
|
|
|
if ($map['types']) {
|
|
|
|
|
$query->withTypes($map['types']);
|
|
|
|
|
}
|
2013-09-10 15:26:08 -07:00
|
|
|
|
2015-06-08 12:22:47 -07:00
|
|
|
if (strlen($map['name'])) {
|
|
|
|
|
$query->withNameContains($map['name']);
|
2013-09-19 11:56:48 -07:00
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:22:47 -07:00
|
|
|
return $query;
|
2013-09-10 15:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
|
return '/diffusion/'.$path;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 07:34:51 +11:00
|
|
|
protected function getBuiltinQueryNames() {
|
2013-09-10 15:26:08 -07:00
|
|
|
$names = array(
|
2013-09-10 15:26:23 -07:00
|
|
|
'active' => pht('Active Repositories'),
|
2013-09-10 15:26:08 -07:00
|
|
|
'all' => pht('All Repositories'),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $names;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
|
|
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
|
|
switch ($query_key) {
|
2013-09-10 15:26:23 -07:00
|
|
|
case 'active':
|
|
|
|
|
return $query->setParameter('status', 'open');
|
2013-09-10 15:26:08 -07:00
|
|
|
case 'all':
|
|
|
|
|
return $query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 15:26:23 -07:00
|
|
|
private function getStatusOptions() {
|
|
|
|
|
return array(
|
|
|
|
|
'' => pht('Active and Inactive Repositories'),
|
|
|
|
|
'open' => pht('Active Repositories'),
|
|
|
|
|
'closed' => pht('Inactive Repositories'),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getStatusValues() {
|
|
|
|
|
return array(
|
|
|
|
|
'' => PhabricatorRepositoryQuery::STATUS_ALL,
|
|
|
|
|
'open' => PhabricatorRepositoryQuery::STATUS_OPEN,
|
|
|
|
|
'closed' => PhabricatorRepositoryQuery::STATUS_CLOSED,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-10 09:12:50 -08:00
|
|
|
private function getHostedOptions() {
|
|
|
|
|
return array(
|
|
|
|
|
'' => pht('Hosted and Remote Repositories'),
|
|
|
|
|
'phabricator' => pht('Hosted Repositories'),
|
|
|
|
|
'remote' => pht('Remote Repositories'),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getHostedValues() {
|
|
|
|
|
return array(
|
|
|
|
|
'' => PhabricatorRepositoryQuery::HOSTED_ALL,
|
|
|
|
|
'phabricator' => PhabricatorRepositoryQuery::HOSTED_PHABRICATOR,
|
|
|
|
|
'remote' => PhabricatorRepositoryQuery::HOSTED_REMOTE,
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-09-08 11:49:06 -07:00
|
|
|
|
2014-05-08 10:08:37 -07:00
|
|
|
protected function getRequiredHandlePHIDsForResultList(
|
|
|
|
|
array $repositories,
|
|
|
|
|
PhabricatorSavedQuery $query) {
|
|
|
|
|
return array_mergev(mpull($repositories, 'getProjectPHIDs'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function renderResultList(
|
|
|
|
|
array $repositories,
|
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
|
array $handles) {
|
|
|
|
|
assert_instances_of($repositories, 'PhabricatorRepository');
|
|
|
|
|
|
2015-05-14 06:50:28 +10:00
|
|
|
$viewer = $this->requireViewer();
|
2014-05-08 10:08:37 -07:00
|
|
|
|
|
|
|
|
$list = new PHUIObjectItemListView();
|
|
|
|
|
foreach ($repositories as $repository) {
|
|
|
|
|
$id = $repository->getID();
|
|
|
|
|
|
|
|
|
|
$item = id(new PHUIObjectItemView())
|
|
|
|
|
->setUser($viewer)
|
|
|
|
|
->setHeader($repository->getName())
|
|
|
|
|
->setObjectName('r'.$repository->getCallsign())
|
|
|
|
|
->setHref($this->getApplicationURI($repository->getCallsign().'/'));
|
|
|
|
|
|
|
|
|
|
$commit = $repository->getMostRecentCommit();
|
|
|
|
|
if ($commit) {
|
|
|
|
|
$commit_link = DiffusionView::linkCommit(
|
|
|
|
|
$repository,
|
|
|
|
|
$commit->getCommitIdentifier(),
|
|
|
|
|
$commit->getSummary());
|
|
|
|
|
$item->setSubhead($commit_link);
|
|
|
|
|
$item->setEpoch($commit->getEpoch());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$item->addIcon(
|
|
|
|
|
'none',
|
|
|
|
|
PhabricatorRepositoryType::getNameForRepositoryType(
|
|
|
|
|
$repository->getVersionControlSystem()));
|
|
|
|
|
|
|
|
|
|
$size = $repository->getCommitCount();
|
|
|
|
|
if ($size) {
|
|
|
|
|
$history_uri = DiffusionRequest::generateDiffusionURI(
|
|
|
|
|
array(
|
|
|
|
|
'callsign' => $repository->getCallsign(),
|
|
|
|
|
'action' => 'history',
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$item->addAttribute(
|
|
|
|
|
phutil_tag(
|
|
|
|
|
'a',
|
|
|
|
|
array(
|
|
|
|
|
'href' => $history_uri,
|
|
|
|
|
),
|
|
|
|
|
pht('%s Commit(s)', new PhutilNumber($size))));
|
|
|
|
|
} else {
|
|
|
|
|
$item->addAttribute(pht('No Commits'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$project_handles = array_select_keys(
|
|
|
|
|
$handles,
|
|
|
|
|
$repository->getProjectPHIDs());
|
|
|
|
|
if ($project_handles) {
|
|
|
|
|
$item->addAttribute(
|
2014-06-26 08:49:44 -07:00
|
|
|
id(new PHUIHandleTagListView())
|
2014-06-26 15:23:48 -07:00
|
|
|
->setSlim(true)
|
2014-05-08 10:08:37 -07:00
|
|
|
->setHandles($project_handles));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$repository->isTracked()) {
|
|
|
|
|
$item->setDisabled(true);
|
|
|
|
|
$item->addIcon('disable-grey', pht('Inactive'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$list->addItem($item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:22:47 -07:00
|
|
|
protected function willUseSavedQuery(PhabricatorSavedQuery $saved) {
|
|
|
|
|
$project_phids = $saved->getParameter('projectPHIDs', array());
|
|
|
|
|
|
|
|
|
|
$old = $saved->getParameter('projects', array());
|
|
|
|
|
foreach ($old as $phid) {
|
|
|
|
|
$project_phids[] = $phid;
|
|
|
|
|
}
|
2015-04-23 08:25:17 -07:00
|
|
|
|
|
|
|
|
$any = $saved->getParameter('anyProjectPHIDs', array());
|
|
|
|
|
foreach ($any as $project) {
|
2015-06-08 12:22:47 -07:00
|
|
|
$project_phids[] = 'any('.$project.')';
|
2015-04-23 08:25:17 -07:00
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:22:47 -07:00
|
|
|
$saved->setParameter('projectPHIDs', $project_phids);
|
2015-04-23 08:25:17 -07:00
|
|
|
}
|
|
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
}
|