From a06715ccdddcc226535b406c8ac5926e8ac9a9de Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 11 Jan 2016 02:12:09 -0800 Subject: [PATCH] Allow repository short names to be used as identifiers Summary: Ref T4245. This allows `bin/repository update bread` to work, in addition to `rBREAD`, `R123`, `123`, `BREAD`, etc., if a repository has a short name set. This primarily affects CLI commands (like `bin/repository`) and Conduit API calls. It has no normal user-facing impact. Test Plan: Ran `bin/repository update bread` and such. Reviewers: chad Reviewed By: chad Maniphest Tasks: T4245 Differential Revision: https://secure.phabricator.com/D14988 --- .../query/PhabricatorRepositoryQuery.php | 61 ++++++++++++++++--- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/src/applications/repository/query/PhabricatorRepositoryQuery.php b/src/applications/repository/query/PhabricatorRepositoryQuery.php index d87fdaa9ce..a794fafa8c 100644 --- a/src/applications/repository/query/PhabricatorRepositoryQuery.php +++ b/src/applications/repository/query/PhabricatorRepositoryQuery.php @@ -17,6 +17,7 @@ final class PhabricatorRepositoryQuery private $callsignIdentifiers; private $phidIdentifiers; private $monogramIdentifiers; + private $slugIdentifiers; private $identifierMap; @@ -56,26 +57,38 @@ final class PhabricatorRepositoryQuery $callsigns = array(); $phids = array(); $monograms = array(); + $slugs = array(); foreach ($identifiers as $identifier) { if (ctype_digit((string)$identifier)) { $ids[$identifier] = $identifier; - } else if (preg_match('/^(r[A-Z]+)|(R[1-9]\d*)\z/', $identifier)) { - $monograms[$identifier] = $identifier; - } else { - $repository_type = PhabricatorRepositoryRepositoryPHIDType::TYPECONST; - if (phid_get_type($identifier) === $repository_type) { - $phids[$identifier] = $identifier; - } else { - $callsigns[$identifier] = $identifier; - } + continue; } + + if (preg_match('/^(r[A-Z]+)|(R[1-9]\d*)\z/', $identifier)) { + $monograms[$identifier] = $identifier; + continue; + } + + $repository_type = PhabricatorRepositoryRepositoryPHIDType::TYPECONST; + if (phid_get_type($identifier) === $repository_type) { + $phids[$identifier] = $identifier; + continue; + } + + if (preg_match('/^[A-Z]+\z/', $identifier)) { + $callsigns[$identifier] = $identifier; + continue; + } + + $slugs[$identifier] = $identifier; } $this->numericIdentifiers = $ids; $this->callsignIdentifiers = $callsigns; $this->phidIdentifiers = $phids; $this->monogramIdentifiers = $monograms; + $this->slugIdentifiers = $slugs; return $this; } @@ -305,6 +318,26 @@ final class PhabricatorRepositoryQuery } } + if ($this->slugIdentifiers) { + $slug_map = array(); + foreach ($repositories as $repository) { + $slug = $repository->getRepositorySlug(); + if ($slug === null) { + continue; + } + + $normal = phutil_utf8_strtolower($slug); + $slug_map[$normal] = $repository; + } + + foreach ($this->slugIdentifiers as $slug) { + $normal = phutil_utf8_strtolower($slug); + if (isset($slug_map[$normal])) { + $this->identifierMap[$slug] = $slug_map[$normal]; + } + } + } + return $repositories; } @@ -480,7 +513,8 @@ final class PhabricatorRepositoryQuery if ($this->numericIdentifiers || $this->callsignIdentifiers || $this->phidIdentifiers || - $this->monogramIdentifiers) { + $this->monogramIdentifiers || + $this->slugIdentifiers) { $identifier_clause = array(); if ($this->numericIdentifiers) { @@ -531,6 +565,13 @@ final class PhabricatorRepositoryQuery } } + if ($this->slugIdentifiers) { + $identifier_clause[] = qsprintf( + $conn, + 'r.repositorySlug IN (%Ls)', + $this->slugIdentifiers); + } + $where = array('('.implode(' OR ', $identifier_clause).')'); }