@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow repository lookup by remote URI

Summary: This helps us move away from arcanist projects in normal use, by allowing us to identify repositories based on the remote URI.

Test Plan: Used `repository.query` to query some repos by remote URI.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D8069

+77
+6
src/applications/repository/conduit/ConduitAPI_repository_query_Method.php
··· 21 21 'phids' => 'optional list<phid>', 22 22 'callsigns' => 'optional list<string>', 23 23 'vcsTypes' => 'optional list<string>', 24 + 'remoteURIs' => 'optional list<string>', 24 25 ); 25 26 } 26 27 ··· 55 56 $vcs_types = $request->getValue('vcsTypes', array()); 56 57 if ($vcs_types) { 57 58 $query->withTypes($vcs_types); 59 + } 60 + 61 + $remote_uris = $request->getValue('remoteURIs', array()); 62 + if ($remote_uris) { 63 + $query->withRemoteURIs($remote_uris); 58 64 } 59 65 60 66 $repositories = $query->execute();
+4
src/applications/repository/data/PhabricatorRepositoryURINormalizer.php
··· 40 40 41 41 const TYPE_GIT = 'git'; 42 42 const TYPE_SVN = 'svn'; 43 + const TYPE_MERCURIAL = 'hg'; 43 44 44 45 private $type; 45 46 private $uri; ··· 48 49 switch ($type) { 49 50 case self::TYPE_GIT: 50 51 case self::TYPE_SVN: 52 + case self::TYPE_MERCURIAL: 51 53 break; 52 54 default: 53 55 throw new Exception(pht('Unknown URI type "%s"!')); ··· 79 81 80 82 return $this->uri; 81 83 case self::TYPE_SVN: 84 + case self::TYPE_MERCURIAL: 82 85 $uri = new PhutilURI($this->uri); 83 86 if ($uri->getProtocol()) { 84 87 return $uri->getPath(); ··· 101 104 $path = preg_replace('/\.git$/', '', $path); 102 105 break; 103 106 case self::TYPE_SVN: 107 + case self::TYPE_MERCURIAL: 104 108 break; 105 109 } 106 110
+43
src/applications/repository/query/PhabricatorRepositoryQuery.php
··· 9 9 private $types; 10 10 private $uuids; 11 11 private $nameContains; 12 + private $remoteURIs; 12 13 13 14 const STATUS_OPEN = 'status-open'; 14 15 const STATUS_CLOSED = 'status-closed'; ··· 70 71 return $this; 71 72 } 72 73 74 + public function withRemoteURIs(array $uris) { 75 + $this->remoteURIs = $uris; 76 + return $this; 77 + } 78 + 73 79 public function needCommitCounts($need_counts) { 74 80 $this->needCommitCounts = $need_counts; 75 81 return $this; ··· 89 95 $this->order = $order; 90 96 return $this; 91 97 } 98 + 92 99 93 100 protected function loadPage() { 94 101 $table = new PhabricatorRepository(); ··· 159 166 throw new Exception("Unknown status '{$status}'!"); 160 167 } 161 168 169 + // TODO: This should also be denormalized. 162 170 $hosted = $this->hosted; 163 171 switch ($hosted) { 164 172 case self::HOSTED_PHABRICATOR: ··· 175 183 break; 176 184 default: 177 185 throw new Exception("Uknown hosted failed '${hosted}'!"); 186 + } 187 + } 188 + 189 + // TODO: Denormalize this, too. 190 + if ($this->remoteURIs) { 191 + $try_uris = $this->getNormalizedPaths(); 192 + $try_uris = array_fuse($try_uris); 193 + foreach ($repositories as $key => $repository) { 194 + if (!isset($try_uris[$repository->getNormalizedPath()])) { 195 + unset($repositories[$key]); 196 + } 178 197 } 179 198 } 180 199 ··· 387 406 388 407 public function getQueryApplicationClass() { 389 408 return 'PhabricatorApplicationDiffusion'; 409 + } 410 + 411 + private function getNormalizedPaths() { 412 + $normalized_uris = array(); 413 + 414 + // Since we don't know which type of repository this URI is in the general 415 + // case, just generate all the normalizations. We could refine this in some 416 + // cases: if the query specifies VCS types, or the URI is a git-style URI 417 + // or an `svn+ssh` URI, we could deduce how to normalize it. However, this 418 + // would be more complicated and it's not clear if it matters in practice. 419 + 420 + foreach ($this->remoteURIs as $uri) { 421 + $normalized_uris[] = new PhabricatorRepositoryURINormalizer( 422 + PhabricatorRepositoryURINormalizer::TYPE_GIT, 423 + $uri); 424 + $normalized_uris[] = new PhabricatorRepositoryURINormalizer( 425 + PhabricatorRepositoryURINormalizer::TYPE_SVN, 426 + $uri); 427 + $normalized_uris[] = new PhabricatorRepositoryURINormalizer( 428 + PhabricatorRepositoryURINormalizer::TYPE_MERCURIAL, 429 + $uri); 430 + } 431 + 432 + return array_unique(mpull($normalized_uris, 'getNormalizedPath')); 390 433 } 391 434 392 435 }
+24
src/applications/repository/storage/PhabricatorRepository.php
··· 485 485 return '/diffusion/'.$this->getCallsign().'/'; 486 486 } 487 487 488 + public function getNormalizedPath() { 489 + switch ($this->getVersionControlSystem()) { 490 + case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: 491 + $normalized_uri = new PhabricatorRepositoryURINormalizer( 492 + PhabricatorRepositoryURINormalizer::TYPE_GIT, 493 + $this->getURI()); 494 + break; 495 + case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 496 + $normalized_uri = new PhabricatorRepositoryURINormalizer( 497 + PhabricatorRepositoryURINormalizer::TYPE_SVN, 498 + $this->getURI()); 499 + break; 500 + case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: 501 + $normalized_uri = new PhabricatorRepositoryURINormalizer( 502 + PhabricatorRepositoryURINormalizer::TYPE_MERCURIAL, 503 + $this->getURI()); 504 + break; 505 + default: 506 + throw new Exception("Unrecognized version control system."); 507 + } 508 + 509 + return $normalized_uri->getNormalizedPath(); 510 + } 511 + 488 512 public function isTracked() { 489 513 return $this->getDetail('tracking-enabled', false); 490 514 }