From 39b384041ffc6bc0488d690d1fe33d3e0fcf1336 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 5 Dec 2013 14:26:38 -0800 Subject: [PATCH] Add "r " to jump nav to locate repositories by name Summary: User request. Test Plan: Searched for `r ph`, `r poetry`. Reviewers: btrahan, bigo Reviewed By: bigo CC: aran Differential Revision: https://secure.phabricator.com/D7720 --- .../query/PhabricatorRepositoryQuery.php | 13 +++++++++++++ .../query/PhabricatorRepositorySearchEngine.php | 12 ++++++++++++ .../search/engine/PhabricatorJumpNavHandler.php | 15 +++++++++++++++ src/docs/user/userguide/jump.diviner | 1 + 4 files changed, 41 insertions(+) diff --git a/src/applications/repository/query/PhabricatorRepositoryQuery.php b/src/applications/repository/query/PhabricatorRepositoryQuery.php index 92d8b95adf..327fe36ba8 100644 --- a/src/applications/repository/query/PhabricatorRepositoryQuery.php +++ b/src/applications/repository/query/PhabricatorRepositoryQuery.php @@ -8,6 +8,7 @@ final class PhabricatorRepositoryQuery private $callsigns; private $types; private $uuids; + private $nameContains; const STATUS_OPEN = 'status-open'; const STATUS_CLOSED = 'status-closed'; @@ -53,6 +54,11 @@ final class PhabricatorRepositoryQuery return $this; } + public function withNameContains($contains) { + $this->nameContains = $contains; + return $this; + } + public function needCommitCounts($need_counts) { $this->needCommitCounts = $need_counts; return $this; @@ -312,6 +318,13 @@ final class PhabricatorRepositoryQuery $this->uuids); } + if (strlen($this->nameContains)) { + $where[] = qsprintf( + $conn_r, + 'name LIKE %~', + $this->nameContains); + } + $where[] = $this->buildPagingClause($conn_r); return $this->formatWhereClause($where); diff --git a/src/applications/repository/query/PhabricatorRepositorySearchEngine.php b/src/applications/repository/query/PhabricatorRepositorySearchEngine.php index 5c6595426a..41dff1056e 100644 --- a/src/applications/repository/query/PhabricatorRepositorySearchEngine.php +++ b/src/applications/repository/query/PhabricatorRepositorySearchEngine.php @@ -10,6 +10,7 @@ final class PhabricatorRepositorySearchEngine $saved->setParameter('status', $request->getStr('status')); $saved->setParameter('order', $request->getStr('order')); $saved->setParameter('types', $request->getArr('types')); + $saved->setParameter('name', $request->getStr('name')); return $saved; } @@ -43,6 +44,11 @@ final class PhabricatorRepositorySearchEngine $query->withTypes($types); } + $name = $saved->getParameter('name'); + if (strlen($name)) { + $query->withNameContains($name); + } + return $query; } @@ -53,6 +59,7 @@ final class PhabricatorRepositorySearchEngine $callsigns = $saved_query->getParameter('callsigns', array()); $types = $saved_query->getParameter('types', array()); $types = array_fuse($types); + $name = $saved_query->getParameter('name'); $form ->appendChild( @@ -60,6 +67,11 @@ final class PhabricatorRepositorySearchEngine ->setName('callsigns') ->setLabel(pht('Callsigns')) ->setValue(implode(', ', $callsigns))) + ->appendChild( + id(new AphrontFormTextControl()) + ->setName('name') + ->setLabel(pht('Name Contains')) + ->setValue($name)) ->appendChild( id(new AphrontFormSelectControl()) ->setName('status') diff --git a/src/applications/search/engine/PhabricatorJumpNavHandler.php b/src/applications/search/engine/PhabricatorJumpNavHandler.php index b0e80962f0..e3081dfebd 100644 --- a/src/applications/search/engine/PhabricatorJumpNavHandler.php +++ b/src/applications/search/engine/PhabricatorJumpNavHandler.php @@ -21,6 +21,7 @@ final class PhabricatorJumpNavHandler { '/^@(.+)$/i' => 'user', '/^task:\s*(.+)/i' => 'create-task', '/^(?:s|symbol)\s+(\S+)/i' => 'find-symbol', + '/^r\s+(.+)$/i' => 'find-repository', ); foreach ($patterns as $pattern => $effect) { @@ -53,6 +54,20 @@ final class PhabricatorJumpNavHandler { } return id(new AphrontRedirectResponse()) ->setURI("/diffusion/symbol/$symbol/?jump=true$context"); + case 'find-repository': + $name = $matches[1]; + $repositories = id(new PhabricatorRepositoryQuery()) + ->setViewer($viewer) + ->withNameContains($name) + ->execute(); + if (count($repositories) == 1) { + // Just one match, jump to repository. + $uri = '/diffusion/'.head($repositories)->getCallsign().'/'; + } else { + // More than one match, jump to search. + $uri = urisprintf('/diffusion/?order=name&name=%s', $name); + } + return id(new AphrontRedirectResponse())->setURI($uri); case 'create-task': return id(new AphrontRedirectResponse()) ->setURI('/maniphest/task/create/?title=' diff --git a/src/docs/user/userguide/jump.diviner b/src/docs/user/userguide/jump.diviner index 06b1e4fa9d..5910484760 100644 --- a/src/docs/user/userguide/jump.diviner +++ b/src/docs/user/userguide/jump.diviner @@ -18,6 +18,7 @@ a navigational command into the box and press return. - **r** - Jump to Diffusion. - **rXYZ** - Jump to Diffusion Repository XYZ. - **rXYZabcdef** - Jump to Diffusion Commit rXYZabcdef. + - **r ** - Search for repositories by name. - **u** - Jump to People - **u username** - Jump to username's Profile - **p** - Jump to Project