1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

When creating a repository in Diffusion, prompt for "Create" or "Import" first

Summary:
Ref T2230. This will need some more refinement, but basically it adds a "Create" vs "Import" step before we go through the paged workflow.

  - If you choose "Create", we skip the remote URI / auth stuff, and then set the "hosted" flag.
  - If you choose "Import", we do what we do now.

Test Plan: Created and imported repos.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2230

Differential Revision: https://secure.phabricator.com/D7475
This commit is contained in:
epriestley 2013-11-01 17:39:35 -07:00
parent 3607bd487c
commit cd674931fc
7 changed files with 252 additions and 96 deletions

View file

@ -527,6 +527,7 @@ phutil_register_library_map(array(
'DiffusionRepositoryEditPolicyController' => 'applications/diffusion/controller/DiffusionRepositoryEditPolicyController.php',
'DiffusionRepositoryEditSubversionController' => 'applications/diffusion/controller/DiffusionRepositoryEditSubversionController.php',
'DiffusionRepositoryListController' => 'applications/diffusion/controller/DiffusionRepositoryListController.php',
'DiffusionRepositoryNewController' => 'applications/diffusion/controller/DiffusionRepositoryNewController.php',
'DiffusionRepositoryPath' => 'applications/diffusion/data/DiffusionRepositoryPath.php',
'DiffusionRepositoryRef' => 'applications/diffusion/data/DiffusionRepositoryRef.php',
'DiffusionRepositoryTag' => 'applications/diffusion/data/DiffusionRepositoryTag.php',
@ -2727,6 +2728,7 @@ phutil_register_library_map(array(
0 => 'DiffusionController',
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
),
'DiffusionRepositoryNewController' => 'DiffusionController',
'DiffusionSSHGitReceivePackWorkflow' => 'DiffusionSSHGitWorkflow',
'DiffusionSSHGitUploadPackWorkflow' => 'DiffusionSSHGitWorkflow',
'DiffusionSSHGitWorkflow' => 'DiffusionSSHWorkflow',

View file

@ -43,7 +43,9 @@ final class PhabricatorApplicationDiffusion extends PhabricatorApplication {
'/diffusion/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'DiffusionRepositoryListController',
'create/' => 'DiffusionRepositoryCreateController',
'new/' => 'DiffusionRepositoryNewController',
'(?P<edit>create)/' => 'DiffusionRepositoryCreateController',
'(?P<edit>import)/' => 'DiffusionRepositoryCreateController',
'(?P<callsign>[A-Z]+)/' => array(
'' => 'DiffusionRepositoryController',

View file

@ -8,34 +8,41 @@ final class DiffusionRepositoryCreateController
public function willProcessRequest(array $data) {
parent::willProcessRequest($data);
$this->edit = idx($data, 'edit');
$this->edit = $data['edit'];
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
// NOTE: We can end up here via either "Create Repository" or via
// "Edit Remote". In the latter case, we show only a few of the pages.
// NOTE: We can end up here via either "Create Repository", or via
// "Import Repository", or via "Edit Remote". In the latter case, we show
// only a few of the pages.
$repository = null;
if ($this->edit) {
$repository = $this->getDiffusionRequest()->getRepository();
switch ($this->edit) {
case 'remote':
$repository = $this->getDiffusionRequest()->getRepository();
// Make sure we have CAN_EDIT.
PhabricatorPolicyFilter::requireCapability(
$viewer,
$repository,
PhabricatorPolicyCapability::CAN_EDIT);
// Make sure we have CAN_EDIT.
PhabricatorPolicyFilter::requireCapability(
$viewer,
$repository,
PhabricatorPolicyCapability::CAN_EDIT);
$this->setRepository($repository);
$this->setRepository($repository);
$cancel_uri = $this->getRepositoryControllerURI($repository, 'edit/');
} else {
$this->requireApplicationCapability(
DiffusionCapabilityCreateRepositories::CAPABILITY);
$cancel_uri = $this->getRepositoryControllerURI($repository, 'edit/');
break;
case 'import':
case 'create':
$this->requireApplicationCapability(
DiffusionCapabilityCreateRepositories::CAPABILITY);
$cancel_uri = $this->getApplicationURI();
$cancel_uri = $this->getApplicationURI('new/');
break;
default:
throw new Exception("Invalid edit operation!");
}
$form = id(new PHUIPagedFormView())
@ -49,7 +56,14 @@ final class DiffusionRepositoryCreateController
->addPage('remote-uri', $this->buildRemoteURIPage())
->addPage('auth', $this->buildAuthPage());
break;
default:
case 'create':
$title = pht('Create Repository');
$form
->addPage('vcs', $this->buildVCSPage())
->addPage('name', $this->buildNamePage())
->addPage('done', $this->buildDonePage());
break;
case 'import':
$title = pht('Import Repository');
$form
->addPage('vcs', $this->buildVCSPage())
@ -63,7 +77,10 @@ final class DiffusionRepositoryCreateController
if ($request->isFormPost()) {
$form->readFromRequest($request);
if ($form->isComplete()) {
$is_create = ($this->edit === null);
$is_create = ($this->edit === 'import' || $this->edit === 'create');
$is_auth = ($this->edit == 'import' || $this->edit == 'remote');
$is_init = ($this->edit == 'create');
if ($is_create) {
$repository = PhabricatorRepository::initializeNewRepository(
@ -82,6 +99,7 @@ final class DiffusionRepositoryCreateController
$type_ssh_keyfile = PhabricatorRepositoryTransaction::TYPE_SSH_KEYFILE;
$type_http_login = PhabricatorRepositoryTransaction::TYPE_HTTP_LOGIN;
$type_http_pass = PhabricatorRepositoryTransaction::TYPE_HTTP_PASS;
$type_hosting = PhabricatorRepositoryTransaction::TYPE_HOSTING;
$xactions = array();
@ -127,35 +145,44 @@ final class DiffusionRepositoryCreateController
->setNewValue($default_local_path);
}
$xactions[] = id(clone $template)
->setTransactionType($type_remote_uri)
->setNewValue(
$form->getPage('remote-uri')->getControl('remoteURI')->getValue());
if ($is_init) {
$xactions[] = id(clone $template)
->setTransactionType($type_hosting)
->setNewValue(true);
}
$xactions[] = id(clone $template)
->setTransactionType($type_ssh_login)
->setNewValue(
$form->getPage('auth')->getControl('ssh-login')->getValue());
if ($is_auth) {
$xactions[] = id(clone $template)
->setTransactionType($type_remote_uri)
->setNewValue(
$form->getPage('remote-uri')->getControl('remoteURI')
->getValue());
$xactions[] = id(clone $template)
->setTransactionType($type_ssh_key)
->setNewValue(
$form->getPage('auth')->getControl('ssh-key')->getValue());
$xactions[] = id(clone $template)
->setTransactionType($type_ssh_login)
->setNewValue(
$form->getPage('auth')->getControl('ssh-login')->getValue());
$xactions[] = id(clone $template)
->setTransactionType($type_ssh_keyfile)
->setNewValue(
$form->getPage('auth')->getControl('ssh-keyfile')->getValue());
$xactions[] = id(clone $template)
->setTransactionType($type_ssh_key)
->setNewValue(
$form->getPage('auth')->getControl('ssh-key')->getValue());
$xactions[] = id(clone $template)
->setTransactionType($type_http_login)
->setNewValue(
$form->getPage('auth')->getControl('http-login')->getValue());
$xactions[] = id(clone $template)
->setTransactionType($type_ssh_keyfile)
->setNewValue(
$form->getPage('auth')->getControl('ssh-keyfile')->getValue());
$xactions[] = id(clone $template)
->setTransactionType($type_http_pass)
->setNewValue(
$form->getPage('auth')->getControl('http-pass')->getValue());
$xactions[] = id(clone $template)
->setTransactionType($type_http_login)
->setNewValue(
$form->getPage('auth')->getControl('http-login')->getValue());
$xactions[] = id(clone $template)
->setTransactionType($type_http_pass)
->setNewValue(
$form->getPage('auth')->getControl('http-pass')->getValue());
}
id(new PhabricatorRepositoryEditor())
->setContinueOnNoEffect(true)
@ -202,46 +229,63 @@ final class DiffusionRepositoryCreateController
private function buildVCSPage() {
$is_import = ($this->edit == 'import');
if ($is_import) {
$git_str = pht(
'Import a Git repository (for example, a repository hosted '.
'on GitHub).');
$hg_str = pht(
'Import a Mercurial repository (for example, a repository '.
'hosted on Bitbucket).');
$svn_str = pht('Import a Subversion repository.');
} else {
$git_str = pht('Create a new, empty Git repository.');
$hg_str = pht('Create a new, empty Mercurial repository.');
$svn_str = pht('Create a new, empty Subversion repository.');
}
$control = id(new AphrontFormRadioButtonControl())
->setName('vcs')
->setLabel(pht('Type'))
->addButton(
PhabricatorRepositoryType::REPOSITORY_TYPE_GIT,
pht('Git'),
$git_str)
->addButton(
PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL,
pht('Mercurial'),
$hg_str)
->addButton(
PhabricatorRepositoryType::REPOSITORY_TYPE_SVN,
pht('Subversion'),
$svn_str);
if ($is_import) {
$control->addButton(
PhabricatorRepositoryType::REPOSITORY_TYPE_PERFORCE,
pht('Perforce'),
pht(
'Perforce is not directly supported, but you can import '.
'a Perforce repository as a Git repository using %s.',
phutil_tag(
'a',
array(
'href' =>
'http://www.perforce.com/product/components/git-fusion',
'target' => '_blank',
),
pht('Perforce Git Fusion'))),
'disabled',
$disabled = true);
}
return id(new PHUIFormPageView())
->setPageName(pht('Repository Type'))
->setUser($this->getRequest()->getUser())
->setValidateFormPageCallback(array($this, 'validateVCSPage'))
->addControl(
id(new AphrontFormRadioButtonControl())
->setName('vcs')
->setLabel(pht('Type'))
->addButton(
PhabricatorRepositoryType::REPOSITORY_TYPE_GIT,
pht('Git'),
pht(
'Import a Git repository (for example, a repository hosted '.
'on GitHub).'))
->addButton(
PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL,
pht('Mercurial'),
pht(
'Import a Mercurial repository (for example, a repository '.
'hosted on Bitbucket).'))
->addButton(
PhabricatorRepositoryType::REPOSITORY_TYPE_SVN,
pht('Subversion'),
pht('Import a Subversion repository.'))
->addButton(
PhabricatorRepositoryType::REPOSITORY_TYPE_PERFORCE,
pht('Perforce'),
pht(
'Perforce is not directly supported, but you can import '.
'a Perforce repository as a Git repository using %s.',
phutil_tag(
'a',
array(
'href' =>
'http://www.perforce.com/product/components/git-fusion',
'target' => '_blank',
),
pht('Perforce Git Fusion'))),
'disabled',
$disabled = true));
->addControl($control);
}
public function validateVCSPage(PHUIFormPageView $page) {
@ -664,6 +708,32 @@ final class DiffusionRepositoryCreateController
private function buildDonePage() {
$is_create = ($this->edit == 'create');
if ($is_create) {
$now_label = pht('Create Repository Now');
$now_caption = pht(
'Create the repository right away. This will create the repository '.
'using default settings.');
$wait_label = pht('Configure More Options First');
$wait_caption = pht(
'Configure more options before creating the repository. '.
'This will let you fine-tune settings. You can create the repository '.
'whenever you are ready.');
} else {
$now_label = pht('Start Import Now');
$now_caption = pht(
'Start importing the repository right away. This will import '.
'the entire repository using default settings.');
$wait_label = pht('Configure More Options First');
$wait_caption = pht(
'Configure more options before beginning the repository '.
'import. This will let you fine-tune settings. You can '.
'start the import whenever you are ready.');
}
return id(new PHUIFormPageView())
->setPageName(pht('Repository Ready!'))
->setValidateFormPageCallback(array($this, 'validateDonePage'))
@ -674,17 +744,12 @@ final class DiffusionRepositoryCreateController
->setLabel(pht('Start Now'))
->addButton(
'start',
pht('Start Import Now'),
pht(
'Start importing the repository right away. This will import '.
'the entire repository using default settings.'))
$now_label,
$now_caption)
->addButton(
'wait',
pht('Configure More Options First'),
pht(
'Configure more options before beginning the repository '.
'import. This will let you fine-tune settings. You can '.
'start the import whenever you are ready.')));
$wait_label,
$wait_caption));
}
public function validateDonePage(PHUIFormPageView $page) {

View file

@ -52,9 +52,12 @@ final class DiffusionRepositoryEditMainController
$policy_properties =
$this->buildPolicyProperties($repository, $policy_actions);
$remote_properties = $this->buildRemoteProperties(
$repository,
$this->buildRemoteActions($repository));
$remote_properties = null;
if (!$repository->isHosted()) {
$remote_properties = $this->buildRemoteProperties(
$repository,
$this->buildRemoteActions($repository));
}
$encoding_actions = $this->buildEncodingActions($repository);
$encoding_properties =
@ -115,8 +118,11 @@ final class DiffusionRepositoryEditMainController
->setHeader($header)
->addPropertyList($basic_properties)
->addPropertyList($policy_properties)
->addPropertyList($hosting_properties)
->addPropertyList($remote_properties);
->addPropertyList($hosting_properties);
if ($remote_properties) {
$obj_box->addPropertyList($remote_properties);
}
if ($local_properties) {
$obj_box->addPropertyList($local_properties);

View file

@ -107,8 +107,8 @@ final class DiffusionRepositoryListController extends DiffusionController
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('Import Repository'))
->setHref($this->getApplicationURI('/create/'))
->setName(pht('New Repository'))
->setHref($this->getApplicationURI('new/'))
->setDisabled(!$can_create)
->setIcon('create'));

View file

@ -0,0 +1,81 @@
<?php
final class DiffusionRepositoryNewController
extends DiffusionController {
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$this->requireApplicationCapability(
DiffusionCapabilityCreateRepositories::CAPABILITY);
if ($request->isFormPost()) {
if ($request->getStr('type')) {
switch ($request->getStr('type')) {
case 'create':
$uri = $this->getApplicationURI('create/');
break;
case 'import':
default:
$uri = $this->getApplicationURI('import/');
break;
}
return id(new AphrontRedirectResponse())->setURI($uri);
}
}
$form = id(new AphrontFormView())
->setUser($viewer)
->appendChild(
id(new AphrontFormRadioButtonControl())
->setName('type')
->addButton(
'create',
pht('Create a New Hosted Repository'),
array(
pht(
'Create a new, empty repository which Phabricator will host.'),
phutil_tag('br'),
pht(
'%s: This feature is very new and barely works. Use it '.
'at your own risk! By choosing this option, you accept great '.
'mortal peril.',
phutil_tag('strong', array(), pht('BEWARE'))),
))
->addButton(
'import',
pht('Import an Existing External Repository'),
pht(
'Import a repository hosted somewhere else, like GitHub, '.
'Bitbucket, or your organization\'s existing servers. '.
'Phabricator will read changes from the repository but will '.
'not host or manage it. The authoritative master version of '.
'the repository will stay where it is now.')))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Continue'))
->addCancelButton($this->getApplicationURI()));
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName(pht('New Repository')));
$form_box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Create or Import Repository'))
->setForm($form);
return $this->buildApplicationPage(
array(
$crumbs,
$form_box,
),
array(
'title' => pht('New Repository'),
'device' => true,
));
}
}

View file

@ -26,7 +26,7 @@ final class PhabricatorRepositoryPullEngine
$is_hg = false;
$is_git = false;
$is_svn = true;
$is_svn = false;
$vcs = $repository->getVersionControlSystem();
$callsign = $repository->getCallsign();