diff --git a/src/applications/repository/query/PhabricatorRepositoryQuery.php b/src/applications/repository/query/PhabricatorRepositoryQuery.php index dad3595745..56a03ca181 100644 --- a/src/applications/repository/query/PhabricatorRepositoryQuery.php +++ b/src/applications/repository/query/PhabricatorRepositoryQuery.php @@ -21,6 +21,11 @@ final class PhabricatorRepositoryQuery const ORDER_NAME = 'order-name'; private $order = self::ORDER_CREATED; + const HOSTED_PHABRICATOR = 'hosted-phab'; + const HOSTED_REMOTE = 'hosted-remote'; + const HOSTED_ALL = 'hosted-all'; + private $hosted = self::HOSTED_ALL; + private $needMostRecentCommits; private $needCommitCounts; private $needProjectPHIDs; @@ -45,6 +50,11 @@ final class PhabricatorRepositoryQuery return $this; } + public function withHosted($hosted) { + $this->hosted = $hosted; + return $this; + } + public function withTypes(array $types) { $this->types = $types; return $this; @@ -148,6 +158,24 @@ final class PhabricatorRepositoryQuery default: throw new Exception("Unknown status '{$status}'!"); } + + $hosted = $this->hosted; + switch ($hosted) { + case self::HOSTED_PHABRICATOR: + if (!$repo->isHosted()) { + unset($repositories[$key]); + } + break; + case self::HOSTED_REMOTE: + if ($repo->isHosted()) { + unset($repositories[$key]); + } + break; + case self::HOSTED_ALL: + break; + default: + throw new Exception("Uknown hosted failed '${hosted}'!"); + } } return $repositories; diff --git a/src/applications/repository/query/PhabricatorRepositorySearchEngine.php b/src/applications/repository/query/PhabricatorRepositorySearchEngine.php index 98fb1af778..3d6a422778 100644 --- a/src/applications/repository/query/PhabricatorRepositorySearchEngine.php +++ b/src/applications/repository/query/PhabricatorRepositorySearchEngine.php @@ -9,6 +9,7 @@ final class PhabricatorRepositorySearchEngine $saved->setParameter('callsigns', $request->getStrList('callsigns')); $saved->setParameter('status', $request->getStr('status')); $saved->setParameter('order', $request->getStr('order')); + $saved->setParameter('hosted', $request->getStr('hosted')); $saved->setParameter('types', $request->getArr('types')); $saved->setParameter('name', $request->getStr('name')); @@ -40,6 +41,12 @@ final class PhabricatorRepositorySearchEngine $query->setOrder(head($this->getOrderValues())); } + $hosted = $saved->getParameter('hosted'); + $hosted = idx($this->getHostedValues(), $hosted); + if ($hosted) { + $query->withHosted($hosted); + } + $types = $saved->getParameter('types'); if ($types) { $query->withTypes($types); @@ -78,7 +85,13 @@ final class PhabricatorRepositorySearchEngine ->setName('status') ->setLabel(pht('Status')) ->setValue($saved_query->getParameter('status')) - ->setOptions($this->getStatusOptions())); + ->setOptions($this->getStatusOptions())) + ->appendChild( + id(new AphrontFormSelectControl()) + ->setName('hosted') + ->setLabel(pht('Hosted')) + ->setValue($saved_query->getParameter('hosted')) + ->setOptions($this->getHostedOptions())); $type_control = id(new AphrontFormCheckboxControl()) ->setLabel(pht('Types')); @@ -164,5 +177,20 @@ final class PhabricatorRepositorySearchEngine ); } + 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, + ); + } }