diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditproController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditproController.php index 1a8e1a8668..79febc2cb7 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditproController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditproController.php @@ -4,9 +4,66 @@ final class DiffusionRepositoryEditproController extends DiffusionRepositoryEditController { public function handleRequest(AphrontRequest $request) { - return id(new DiffusionRepositoryEditEngine()) - ->setController($this) - ->buildResponse(); + $engine = id(new DiffusionRepositoryEditEngine()) + ->setController($this); + + $id = $request->getURIData('id'); + if (!$id) { + $this->requireApplicationCapability( + DiffusionCreateRepositoriesCapability::CAPABILITY); + + $vcs = $request->getStr('vcs'); + $vcs_types = PhabricatorRepositoryType::getRepositoryTypeMap(); + if (empty($vcs_types[$vcs])) { + return $this->buildVCSTypeResponse(); + } + + $engine + ->addContextParameter('vcs', $vcs) + ->setVersionControlSystem($vcs); + } + + return $engine->buildResponse(); + } + + private function buildVCSTypeResponse() { + $vcs_types = PhabricatorRepositoryType::getRepositoryTypeMap(); + + $request = $this->getRequest(); + $viewer = $this->getViewer(); + + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb(pht('Create Repository')); + $crumbs->setBorder(true); + + $title = pht('Choose Repository Type'); + $header = id(new PHUIHeaderView()) + ->setHeader(pht('Create Repository')) + ->setHeaderIcon('fa-plus-square'); + + $layout = id(new AphrontMultiColumnView()) + ->setFluidLayout(true); + + $create_uri = $request->getRequestURI(); + + foreach ($vcs_types as $vcs_key => $vcs_type) { + $action = id(new PHUIActionPanelView()) + ->setIcon(idx($vcs_type, 'icon')) + ->setHeader(idx($vcs_type, 'create.header')) + ->setHref($create_uri->alter('vcs', $vcs_key)) + ->setSubheader(idx($vcs_type, 'create.subheader')); + + $layout->addColumn($action); + } + + $view = id(new PHUITwoColumnView()) + ->setHeader($header) + ->setFooter($layout); + + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->appendChild($view); } } diff --git a/src/applications/diffusion/editor/DiffusionRepositoryEditEngine.php b/src/applications/diffusion/editor/DiffusionRepositoryEditEngine.php index d4d1bac841..1ebbabe2ed 100644 --- a/src/applications/diffusion/editor/DiffusionRepositoryEditEngine.php +++ b/src/applications/diffusion/editor/DiffusionRepositoryEditEngine.php @@ -5,6 +5,17 @@ final class DiffusionRepositoryEditEngine const ENGINECONST = 'diffusion.repository'; + private $versionControlSystem; + + public function setVersionControlSystem($version_control_system) { + $this->versionControlSystem = $version_control_system; + return $this; + } + + public function getVersionControlSystem() { + return $this->versionControlSystem; + } + public function isEngineConfigurable() { return false; } @@ -27,7 +38,14 @@ final class DiffusionRepositoryEditEngine protected function newEditableObject() { $viewer = $this->getViewer(); - return PhabricatorRepository::initializeNewRepository($viewer); + $repository = PhabricatorRepository::initializeNewRepository($viewer); + + $vcs = $this->getVersionControlSystem(); + if ($vcs) { + $repository->setVersionControlSystem($vcs); + } + + return $repository; } protected function newObjectQuery() { diff --git a/src/applications/diffusion/management/DiffusionRepositoryStatusManagementPanel.php b/src/applications/diffusion/management/DiffusionRepositoryStatusManagementPanel.php index db31e0d71e..1666749980 100644 --- a/src/applications/diffusion/management/DiffusionRepositoryStatusManagementPanel.php +++ b/src/applications/diffusion/management/DiffusionRepositoryStatusManagementPanel.php @@ -46,8 +46,12 @@ final class DiffusionRepositoryStatusManagementPanel pht('Update Frequency'), $this->buildRepositoryUpdateInterval($repository)); + $messages = id(new PhabricatorRepositoryStatusMessage()) + ->loadAllWhere('repositoryID = %d', $repository->getID()); + $messages = mpull($messages, null, 'getStatusType'); - list($status, $raw_error) = $this->buildRepositoryStatus($repository); + $status = $this->buildRepositoryStatus($repository, $messages); + $raw_error = $this->buildRepositoryRawError($repository, $messages); $view->addProperty(pht('Status'), $status); if ($raw_error) { @@ -80,17 +84,14 @@ final class DiffusionRepositoryStatusManagementPanel } private function buildRepositoryStatus( - PhabricatorRepository $repository) { + PhabricatorRepository $repository, + array $messages) { $viewer = $this->getViewer(); $is_cluster = $repository->getAlmanacServicePHID(); $view = new PHUIStatusListView(); - $messages = id(new PhabricatorRepositoryStatusMessage()) - ->loadAllWhere('repositoryID = %d', $repository->getID()); - $messages = mpull($messages, null, 'getStatusType'); - if ($repository->isTracked()) { $view->addItem( id(new PHUIStatusItemView()) @@ -361,8 +362,6 @@ final class DiffusionRepositoryStatusManagementPanel } } - $raw_error = null; - $message = idx($messages, PhabricatorRepositoryStatusMessage::TYPE_FETCH); if ($message) { switch ($message->getStatusCode()) { @@ -377,8 +376,6 @@ final class DiffusionRepositoryStatusManagementPanel 'access the repository.'); } - $raw_error = $message; - $view->addItem( id(new PHUIStatusItemView()) ->setIcon(PHUIStatusItemView::ICON_WARNING, 'red') @@ -432,11 +429,30 @@ final class DiffusionRepositoryStatusManagementPanel ->setNote(pht('This repository will be updated soon!'))); } + return $view; + } + + private function buildRepositoryRawError( + PhabricatorRepository $repository, + array $messages) { + $viewer = $this->getViewer(); + $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $repository, PhabricatorPolicyCapability::CAN_EDIT); + $raw_error = null; + + $message = idx($messages, PhabricatorRepositoryStatusMessage::TYPE_FETCH); + if ($message) { + switch ($message->getStatusCode()) { + case PhabricatorRepositoryStatusMessage::CODE_ERROR: + $raw_error = $message->getParameter('message'); + break; + } + } + if ($raw_error !== null) { if (!$can_edit) { $raw_message = pht( @@ -450,7 +466,7 @@ final class DiffusionRepositoryStatusManagementPanel $raw_message = null; } - return array($view, $raw_message); + return $raw_message; } diff --git a/src/applications/diffusion/management/DiffusionRepositoryURIsManagementPanel.php b/src/applications/diffusion/management/DiffusionRepositoryURIsManagementPanel.php index 3535c64bbc..2eb1991f07 100644 --- a/src/applications/diffusion/management/DiffusionRepositoryURIsManagementPanel.php +++ b/src/applications/diffusion/management/DiffusionRepositoryURIsManagementPanel.php @@ -106,7 +106,7 @@ final class DiffusionRepositoryURIsManagementPanel )); $doc_href = PhabricatorEnv::getDoclink( - 'Diffusion User Guide: Repository URIs'); + 'Diffusion User Guide: URIs'); $header = id(new PHUIHeaderView()) ->setHeader(pht('Repository URIs')) diff --git a/src/applications/repository/constants/PhabricatorRepositoryType.php b/src/applications/repository/constants/PhabricatorRepositoryType.php index 4861641411..998bff0d2e 100644 --- a/src/applications/repository/constants/PhabricatorRepositoryType.php +++ b/src/applications/repository/constants/PhabricatorRepositoryType.php @@ -7,17 +7,41 @@ final class PhabricatorRepositoryType extends Phobject { const REPOSITORY_TYPE_MERCURIAL = 'hg'; public static function getAllRepositoryTypes() { - $map = array( - self::REPOSITORY_TYPE_GIT => pht('Git'), - self::REPOSITORY_TYPE_MERCURIAL => pht('Mercurial'), - self::REPOSITORY_TYPE_SVN => pht('Subversion'), - ); - return $map; + $map = self::getRepositoryTypeMap(); + return ipull($map, 'name'); } public static function getNameForRepositoryType($type) { - $map = self::getAllRepositoryTypes(); - return idx($map, $type, pht('Unknown')); + $spec = self::getRepositoryTypeSpec($type); + return idx($spec, 'name', pht('Unknown ("%s")', $type)); + } + + public static function getRepositoryTypeSpec($type) { + $map = self::getRepositoryTypeMap(); + return idx($map, $type, array()); + } + + public static function getRepositoryTypeMap() { + return array( + self::REPOSITORY_TYPE_GIT => array( + 'name' => pht('Git'), + 'icon' => 'fa-git', + 'create.header' => pht('Create Git Repository'), + 'create.subheader' => pht('Create a new Git repository.'), + ), + self::REPOSITORY_TYPE_MERCURIAL => array( + 'name' => pht('Mercurial'), + 'icon' => 'fa-code-fork', + 'create.header' => pht('Create Mercurial Repository'), + 'create.subheader' => pht('Create a new Mercurial repository.'), + ), + self::REPOSITORY_TYPE_SVN => array( + 'name' => pht('Subversion'), + 'icon' => 'fa-database', + 'create.header' => pht('Create Subversion Repository'), + 'create.subheader' => pht('Create a new Subversion repository.'), + ), + ); } }