mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +01:00
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
This commit is contained in:
parent
5a723bff91
commit
a06715ccdd
1 changed files with 51 additions and 10 deletions
|
@ -17,6 +17,7 @@ final class PhabricatorRepositoryQuery
|
||||||
private $callsignIdentifiers;
|
private $callsignIdentifiers;
|
||||||
private $phidIdentifiers;
|
private $phidIdentifiers;
|
||||||
private $monogramIdentifiers;
|
private $monogramIdentifiers;
|
||||||
|
private $slugIdentifiers;
|
||||||
|
|
||||||
private $identifierMap;
|
private $identifierMap;
|
||||||
|
|
||||||
|
@ -56,26 +57,38 @@ final class PhabricatorRepositoryQuery
|
||||||
$callsigns = array();
|
$callsigns = array();
|
||||||
$phids = array();
|
$phids = array();
|
||||||
$monograms = array();
|
$monograms = array();
|
||||||
|
$slugs = array();
|
||||||
|
|
||||||
foreach ($identifiers as $identifier) {
|
foreach ($identifiers as $identifier) {
|
||||||
if (ctype_digit((string)$identifier)) {
|
if (ctype_digit((string)$identifier)) {
|
||||||
$ids[$identifier] = $identifier;
|
$ids[$identifier] = $identifier;
|
||||||
} else if (preg_match('/^(r[A-Z]+)|(R[1-9]\d*)\z/', $identifier)) {
|
continue;
|
||||||
$monograms[$identifier] = $identifier;
|
|
||||||
} else {
|
|
||||||
$repository_type = PhabricatorRepositoryRepositoryPHIDType::TYPECONST;
|
|
||||||
if (phid_get_type($identifier) === $repository_type) {
|
|
||||||
$phids[$identifier] = $identifier;
|
|
||||||
} else {
|
|
||||||
$callsigns[$identifier] = $identifier;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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->numericIdentifiers = $ids;
|
||||||
$this->callsignIdentifiers = $callsigns;
|
$this->callsignIdentifiers = $callsigns;
|
||||||
$this->phidIdentifiers = $phids;
|
$this->phidIdentifiers = $phids;
|
||||||
$this->monogramIdentifiers = $monograms;
|
$this->monogramIdentifiers = $monograms;
|
||||||
|
$this->slugIdentifiers = $slugs;
|
||||||
|
|
||||||
return $this;
|
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;
|
return $repositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,7 +513,8 @@ final class PhabricatorRepositoryQuery
|
||||||
if ($this->numericIdentifiers ||
|
if ($this->numericIdentifiers ||
|
||||||
$this->callsignIdentifiers ||
|
$this->callsignIdentifiers ||
|
||||||
$this->phidIdentifiers ||
|
$this->phidIdentifiers ||
|
||||||
$this->monogramIdentifiers) {
|
$this->monogramIdentifiers ||
|
||||||
|
$this->slugIdentifiers) {
|
||||||
$identifier_clause = array();
|
$identifier_clause = array();
|
||||||
|
|
||||||
if ($this->numericIdentifiers) {
|
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).')');
|
$where = array('('.implode(' OR ', $identifier_clause).')');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue