Differential D9513 Diff 22796 src/applications/diffusion/controller/DiffusionRepositoryCreateController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionRepositoryCreateController.php
Show First 20 Lines • Show All 440 Lines • ▼ Show 20 Lines | if ($is_git) { | ||||
$instructions = pht( | $instructions = pht( | ||||
'Enter the URI to clone this Git repository from. It should usually '. | 'Enter the URI to clone this Git repository from. It should usually '. | ||||
'look like one of these examples:'. | 'look like one of these examples:'. | ||||
"\n\n". | "\n\n". | ||||
"| Example Git Remote URIs |\n". | "| Example Git Remote URIs |\n". | ||||
"| ----------------------- |\n". | "| ----------------------- |\n". | ||||
"| `git@github.com:example/example.git` |\n". | "| `git@github.com:example/example.git` |\n". | ||||
"| `ssh://user@host.com/git/example.git` |\n". | "| `ssh://user@host.com/git/example.git` |\n". | ||||
"| `file:///local/path/to/repo` |\n". | |||||
"| `https://example.com/repository.git` |\n"); | "| `https://example.com/repository.git` |\n"); | ||||
} else if ($is_mercurial) { | } else if ($is_mercurial) { | ||||
$uri_label = pht('Remote URI'); | $uri_label = pht('Remote URI'); | ||||
$instructions = pht( | $instructions = pht( | ||||
'Enter the URI to clone this Mercurial repository from. It should '. | 'Enter the URI to clone this Mercurial repository from. It should '. | ||||
'usually look like one of these examples:'. | 'usually look like one of these examples:'. | ||||
"\n\n". | "\n\n". | ||||
"| Example Mercurial Remote URIs |\n". | "| Example Mercurial Remote URIs |\n". | ||||
"| ----------------------- |\n". | "| ----------------------- |\n". | ||||
"| `ssh://hg@bitbucket.org/example/repository` |\n". | "| `ssh://hg@bitbucket.org/example/repository` |\n". | ||||
"| `file:///local/path/to/repo` |\n"); | "| `https://bitbucket.org/example/repository` |\n"); | ||||
} else if ($is_svn) { | } else if ($is_svn) { | ||||
$uri_label = pht('Repository Root'); | $uri_label = pht('Repository Root'); | ||||
$instructions = pht( | $instructions = pht( | ||||
'Enter the **Repository Root** for this Subversion repository. '. | 'Enter the **Repository Root** for this Subversion repository. '. | ||||
'You can figure this out by running `svn info` in a working copy '. | 'You can figure this out by running `svn info` in a working copy '. | ||||
'and looking at the value in the `Repository Root` field. It '. | 'and looking at the value in the `Repository Root` field. It '. | ||||
'should be a URI and will usually look like these:'. | 'should be a URI and will usually look like these:'. | ||||
"\n\n". | "\n\n". | ||||
"| Example Subversion Repository Root URIs |\n". | "| Example Subversion Repository Root URIs |\n". | ||||
"| ------------------------------ |\n". | "| ------------------------------ |\n". | ||||
"| `http://svn.example.org/svnroot/` |\n". | "| `http://svn.example.org/svnroot/` |\n". | ||||
"| `svn+ssh://svn.example.com/svnroot/` |\n". | "| `svn+ssh://svn.example.com/svnroot/` |\n". | ||||
"| `svn://svn.example.net/svnroot/` |\n". | "| `svn://svn.example.net/svnroot/` |\n". | ||||
"| `file:///local/path/to/svnroot/` |\n". | |||||
"\n\n". | "\n\n". | ||||
"You **MUST** specify the root of the repository, not a ". | "You **MUST** specify the root of the repository, not a ". | ||||
"subdirectory. (If you want to import only part of a Subversion ". | "subdirectory. (If you want to import only part of a Subversion ". | ||||
"repository, use the //Import Only// option at the end of this ". | "repository, use the //Import Only// option at the end of this ". | ||||
"workflow.)"); | "workflow.)"); | ||||
} else { | } else { | ||||
throw new Exception('Unsupported VCS!'); | throw new Exception('Unsupported VCS!'); | ||||
} | } | ||||
$page->addRemarkupInstructions($instructions, 'remoteURI'); | $page->addRemarkupInstructions($instructions, 'remoteURI'); | ||||
$page->getControl('remoteURI')->setLabel($uri_label); | $page->getControl('remoteURI')->setLabel($uri_label); | ||||
} | } | ||||
public function validateRemoteURIPage(PHUIFormPageView $page) { | public function validateRemoteURIPage(PHUIFormPageView $page) { | ||||
$c_remote = $page->getControl('remoteURI'); | $c_remote = $page->getControl('remoteURI'); | ||||
$v_remote = $c_remote->getValue(); | $v_remote = $c_remote->getValue(); | ||||
if (!strlen($v_remote)) { | if (!strlen($v_remote)) { | ||||
$c_remote->setError(pht('Required')); | $c_remote->setError(pht('Required')); | ||||
$page->addPageError( | $page->addPageError( | ||||
pht('You must specify a URI.')); | pht('You must specify a URI.')); | ||||
} else { | } else { | ||||
$proto = $this->getRemoteURIProtocol($v_remote); | try { | ||||
PhabricatorRepository::assertValidRemoteURI($v_remote); | |||||
if ($proto === 'file') { | } catch (Exception $ex) { | ||||
if (!preg_match('@^file:///@', $v_remote)) { | |||||
$c_remote->setError(pht('Invalid')); | |||||
$page->addPageError( | |||||
pht( | |||||
"URIs using the 'file://' protocol should have three slashes ". | |||||
"(e.g., 'file:///absolute/path/to/file'). You only have two. ". | |||||
"Add another one.")); | |||||
} | |||||
} | |||||
// Catch confusion between Git/SCP-style URIs and normal URIs. See T3619 | |||||
// for discussion. This is usually a user adding "ssh://" to an implicit | |||||
// SSH Git URI. | |||||
if ($proto == 'ssh') { | |||||
if (preg_match('(^[^:@]+://[^/:]+:[^\d])', $v_remote)) { | |||||
$c_remote->setError(pht('Invalid')); | |||||
$page->addPageError( | |||||
pht( | |||||
"The Remote URI is not formatted correctly. Remote URIs ". | |||||
"with an explicit protocol should be in the form ". | |||||
"'proto://domain/path', not 'proto://domain:/path'. ". | |||||
"The ':/path' syntax is only valid in SCP-style URIs.")); | |||||
} | |||||
} | |||||
switch ($proto) { | |||||
case 'ssh': | |||||
case 'http': | |||||
case 'https': | |||||
case 'file': | |||||
case 'git': | |||||
case 'svn': | |||||
case 'svn+ssh': | |||||
break; | |||||
default: | |||||
$c_remote->setError(pht('Invalid')); | $c_remote->setError(pht('Invalid')); | ||||
$page->addPageError( | $page->addPageError($ex->getMessage()); | ||||
pht( | |||||
"The URI protocol is unrecognized. It should begin ". | |||||
"'ssh://', 'http://', 'https://', 'file://', 'git://', ". | |||||
"'svn://', 'svn+ssh://', or be in the form ". | |||||
"'git@domain.com:path'.")); | |||||
break; | |||||
} | } | ||||
} | } | ||||
return $c_remote->isValid(); | return $c_remote->isValid(); | ||||
} | } | ||||
/* -( Page: Authentication )----------------------------------------------- */ | /* -( Page: Authentication )----------------------------------------------- */ | ||||
Show All 17 Lines | if ($this->getRepository()) { | ||||
$vcs = $this->getRepository()->getVersionControlSystem(); | $vcs = $this->getRepository()->getVersionControlSystem(); | ||||
} else { | } else { | ||||
$vcs = $form->getPage('vcs')->getControl('vcs')->getValue(); | $vcs = $form->getPage('vcs')->getControl('vcs')->getValue(); | ||||
} | } | ||||
$remote_uri = $form->getPage('remote-uri') | $remote_uri = $form->getPage('remote-uri') | ||||
->getControl('remoteURI') | ->getControl('remoteURI') | ||||
->getValue(); | ->getValue(); | ||||
$proto = $this->getRemoteURIProtocol($remote_uri); | |||||
$proto = PhabricatorRepository::getRemoteURIProtocol($remote_uri); | |||||
$remote_user = $this->getRemoteURIUser($remote_uri); | $remote_user = $this->getRemoteURIUser($remote_uri); | ||||
$c_credential = $page->getControl('credential'); | $c_credential = $page->getControl('credential'); | ||||
$c_credential->setDefaultUsername($remote_user); | $c_credential->setDefaultUsername($remote_user); | ||||
if ($this->isSSHProtocol($proto)) { | if ($this->isSSHProtocol($proto)) { | ||||
$c_credential->setLabel(pht('SSH Key')); | $c_credential->setLabel(pht('SSH Key')); | ||||
$c_credential->setCredentialType( | $c_credential->setCredentialType( | ||||
Show All 23 Lines | if ($this->isSSHProtocol($proto)) { | ||||
"\n\n". | "\n\n". | ||||
" lang=text\n". | " lang=text\n". | ||||
" %s". | " %s". | ||||
"\n\n". | "\n\n". | ||||
"If this repository does not require a username or password, ". | "If this repository does not require a username or password, ". | ||||
"you can continue to the next step.", | "you can continue to the next step.", | ||||
$remote_uri), | $remote_uri), | ||||
'credential'); | 'credential'); | ||||
} else if ($proto == 'file') { | |||||
$c_credential->setHidden(true); | |||||
$provides_type = null; | |||||
$page->addRemarkupInstructions( | |||||
pht( | |||||
'You do not need to configure any credentials for repositories '. | |||||
'accessed over the `file://` protocol. Continue to the next step.'), | |||||
'credential'); | |||||
} else { | } else { | ||||
throw new Exception('Unknown URI protocol!'); | throw new Exception('Unknown URI protocol!'); | ||||
} | } | ||||
if ($provides_type) { | if ($provides_type) { | ||||
$viewer = $this->getRequest()->getUser(); | $viewer = $this->getRequest()->getUser(); | ||||
$options = id(new PassphraseCredentialQuery()) | $options = id(new PassphraseCredentialQuery()) | ||||
▲ Show 20 Lines • Show All 232 Lines • ▼ Show 20 Lines | public function validateDonePage(PHUIFormPageView $page) { | ||||
} | } | ||||
return $c_activate->isValid(); | return $c_activate->isValid(); | ||||
} | } | ||||
/* -( Internal )----------------------------------------------------------- */ | /* -( Internal )----------------------------------------------------------- */ | ||||
private 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; | |||||
} | |||||
private function getRemoteURIUser($raw_uri) { | private function getRemoteURIUser($raw_uri) { | ||||
$uri = new PhutilURI($raw_uri); | $uri = new PhutilURI($raw_uri); | ||||
if ($uri->getUser()) { | if ($uri->getUser()) { | ||||
return $uri->getUser(); | return $uri->getUser(); | ||||
} | } | ||||
$git_uri = new PhutilGitURI($raw_uri); | $git_uri = new PhutilGitURI($raw_uri); | ||||
if (strlen($git_uri->getDomain()) && strlen($git_uri->getPath())) { | if (strlen($git_uri->getDomain()) && strlen($git_uri->getPath())) { | ||||
Show All 25 Lines |