public function getRemoteURI() { $raw_uri = $this->getDetail('remote-uri'); if (!$raw_uri) { return null; } if (strpos($raw_uri, '/') === 0) { // If the URI starts with a '/', it's an implicit file:// URI on the // local disk. $uri = new PhutilURI('file://' . $raw_uri); return (string) $uri; } $uri = new PhutilURI($raw_uri); if ($uri->getProtocol()) { if ($this->isSSHProtocol($uri->getProtocol())) { if ($this->getSSHLogin()) { $uri->setUser($this->getSSHLogin()); } } return (string) $uri; } $uri = new PhutilGitURI($raw_uri); if ($uri->getDomain()) { if ($this->getSSHLogin()) { $uri->setUser($this->getSSHLogin()); } return (string) $uri; } throw new Exception("Repository remote URI '{$raw_uri}' could not be parsed!"); }
public function testGitURIParsing() { $uri = new PhutilGitURI('git@host.com:path/to/something'); $this->assertEqual('git', $uri->getUser()); $this->assertEqual('host.com', $uri->getDomain()); $this->assertEqual('path/to/something', $uri->getPath()); $this->assertEqual('git@host.com:path/to/something', (string) $uri); $uri = new PhutilGitURI('host.com:path/to/something'); $this->assertEqual('', $uri->getUser()); $this->assertEqual('host.com', $uri->getDomain()); $this->assertEqual('path/to/something', $uri->getPath()); $this->assertEqual('host.com:path/to/something', (string) $uri); }
/** * @task normal */ public function getPath() { switch ($this->type) { case self::TYPE_GIT: $uri = new PhutilURI($this->uri); if ($uri->getProtocol()) { return $uri->getPath(); } $uri = new PhutilGitURI($this->uri); if ($uri->getDomain()) { return $uri->getPath(); } return $this->uri; case self::TYPE_SVN: case self::TYPE_MERCURIAL: $uri = new PhutilURI($this->uri); if ($uri->getProtocol()) { return $uri->getPath(); } return $this->uri; } }
public static function getRemoteURIProtocol($raw_uri) { $uri = new PhutilURI($raw_uri); if ($uri->getProtocol()) { return strtolower($uri->getProtocol()); } $git_uri = new PhutilGitURI($raw_uri); if (strlen($git_uri->getDomain()) && strlen($git_uri->getPath())) { return 'ssh'; } return null; }
/** * Get a parsed object representation of the repository's remote URI. This * may be a normal URI (returned as a @{class:PhutilURI}) or a git URI * (returned as a @{class:PhutilGitURI}). * * @return wild A @{class:PhutilURI} or @{class:PhutilGitURI}. * @task uri */ private function getRemoteURIObject() { $raw_uri = $this->getDetail('remote-uri'); if (!$raw_uri) { return new PhutilURI(''); } if (!strncmp($raw_uri, '/', 1)) { return new PhutilURI('file://' . $raw_uri); } $uri = new PhutilURI($raw_uri); if ($uri->getProtocol()) { if ($this->isSSHProtocol($uri->getProtocol())) { if ($this->getSSHLogin()) { $uri->setUser($this->getSSHLogin()); } } return $uri; } $uri = new PhutilGitURI($raw_uri); if ($uri->getDomain()) { if ($this->getSSHLogin()) { $uri->setUser($this->getSSHLogin()); } return $uri; } throw new Exception("Remote URI '{$raw_uri}' could not be parsed!"); }
private function getRemoteURIUser($raw_uri) { $uri = new PhutilURI($raw_uri); if ($uri->getUser()) { return $uri->getUser(); } $git_uri = new PhutilGitURI($raw_uri); if (strlen($git_uri->getDomain()) && strlen($git_uri->getPath())) { return $git_uri->getUser(); } return null; }
private static function getPathFromGitURI($raw_uri) { $uri = new PhutilURI($raw_uri); if ($uri->getProtocol()) { return $uri->getPath(); } $uri = new PhutilGitURI($raw_uri); if ($uri->getDomain()) { return $uri->getPath(); } return $raw_uri; }
} $uri = new PhutilURI($raw_uri); $proto = strtolower($uri->getProtocol()); if ($proto == 'http' || $proto == 'https' || $proto == 'svn') { $username = $repository->getDetail('http-login'); $secret = $repository->getDetail('http-pass'); $type = PassphrasePasswordCredentialType::CREDENTIAL_TYPE; } else { $username = $repository->getDetail('ssh-login'); if (!$username) { // If there's no explicit username, check for one in the URI. This is // possible with older repositories. $username = $uri->getUser(); if (!$username) { // Also check for a Git/SCP-style URI. $git_uri = new PhutilGitURI($raw_uri); $username = $git_uri->getUser(); } } $file = $repository->getDetail('ssh-keyfile'); if ($file) { $secret = $file; $type = PassphraseSSHPrivateKeyFileCredentialType::CREDENTIAL_TYPE; } else { $secret = $repository->getDetail('ssh-key'); $type = PassphraseSSHPrivateKeyTextCredentialType::CREDENTIAL_TYPE; } } if (!$username || !$secret) { echo pht('...no credentials set.') . "\n"; continue;