From b8b700c179dbd6b76e0faa9b08f66e03936bd315 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 3 May 2016 13:05:26 -0700 Subject: [PATCH] Remove "repository.create" Conduit API method Summary: Ref T10748. This has had many problems for a long time, can't create hosted repositories, can't create cluster repositories, etc. It is obsoleted by `diffusion.repository.edit`. Remove it. (Right now `diffusion.repository.edit` isn't a strict replacement, but it will be as soon as the URI stuff cuts over.) Test Plan: Grepped for `repository.create`. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10748 Differential Revision: https://secure.phabricator.com/D15838 --- src/__phutil_library_map__.php | 2 - .../RepositoryCreateConduitAPIMethod.php | 141 ------------------ 2 files changed, 143 deletions(-) delete mode 100644 src/applications/repository/conduit/RepositoryCreateConduitAPIMethod.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ea12d54c1d..72e734da87 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -4105,7 +4105,6 @@ phutil_register_library_map(array( 'ReleephWorkRecordPickStatusConduitAPIMethod' => 'applications/releeph/conduit/work/ReleephWorkRecordPickStatusConduitAPIMethod.php', 'RemarkupProcessConduitAPIMethod' => 'applications/remarkup/conduit/RemarkupProcessConduitAPIMethod.php', 'RepositoryConduitAPIMethod' => 'applications/repository/conduit/RepositoryConduitAPIMethod.php', - 'RepositoryCreateConduitAPIMethod' => 'applications/repository/conduit/RepositoryCreateConduitAPIMethod.php', 'RepositoryQueryConduitAPIMethod' => 'applications/repository/conduit/RepositoryQueryConduitAPIMethod.php', 'ShellLogView' => 'applications/harbormaster/view/ShellLogView.php', 'SlowvoteConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteConduitAPIMethod.php', @@ -8988,7 +8987,6 @@ phutil_register_library_map(array( 'ReleephWorkRecordPickStatusConduitAPIMethod' => 'ReleephConduitAPIMethod', 'RemarkupProcessConduitAPIMethod' => 'ConduitAPIMethod', 'RepositoryConduitAPIMethod' => 'ConduitAPIMethod', - 'RepositoryCreateConduitAPIMethod' => 'RepositoryConduitAPIMethod', 'RepositoryQueryConduitAPIMethod' => 'RepositoryConduitAPIMethod', 'ShellLogView' => 'AphrontView', 'SlowvoteConduitAPIMethod' => 'ConduitAPIMethod', diff --git a/src/applications/repository/conduit/RepositoryCreateConduitAPIMethod.php b/src/applications/repository/conduit/RepositoryCreateConduitAPIMethod.php deleted file mode 100644 index bec9b3b9a3..0000000000 --- a/src/applications/repository/conduit/RepositoryCreateConduitAPIMethod.php +++ /dev/null @@ -1,141 +0,0 @@ -formatStringConstants(array('git', 'hg', 'svn')); - - return array( - 'name' => 'required string', - 'vcs' => 'required '.$vcs_const, - 'callsign' => 'required string', - 'description' => 'optional string', - 'encoding' => 'optional string', - 'tracking' => 'optional bool', - 'uri' => 'required string', - 'credentialPHID' => 'optional string', - 'svnSubpath' => 'optional string', - 'branchFilter' => 'optional list', - 'closeCommitsFilter' => 'optional list', - 'pullFrequency' => 'optional int', - 'defaultBranch' => 'optional string', - 'heraldEnabled' => 'optional bool, default = true', - 'autocloseEnabled' => 'optional bool, default = true', - 'svnUUID' => 'optional string', - ); - } - - protected function defineReturnType() { - return 'nonempty dict'; - } - - protected function defineErrorTypes() { - return array( - 'ERR-DUPLICATE' => pht('Duplicate repository callsign.'), - 'ERR-BAD-CALLSIGN' => pht( - 'Callsign is required and must be ALL UPPERCASE LETTERS.'), - 'ERR-UNKNOWN-REPOSITORY-VCS' => pht('Unknown repository VCS type.'), - ); - } - - protected function execute(ConduitAPIRequest $request) { - $application = id(new PhabricatorApplicationQuery()) - ->setViewer($request->getUser()) - ->withClasses(array('PhabricatorDiffusionApplication')) - ->executeOne(); - - PhabricatorPolicyFilter::requireCapability( - $request->getUser(), - $application, - DiffusionCreateRepositoriesCapability::CAPABILITY); - - // TODO: This has some duplication with (and lacks some of the validation - // of) the web workflow; refactor things so they can share more code as this - // stabilizes. Specifically, this should move to transactions since they - // work properly now. - - $repository = PhabricatorRepository::initializeNewRepository( - $request->getUser()); - - $repository->setName($request->getValue('name')); - - $callsign = $request->getValue('callsign'); - if (!preg_match('/^[A-Z]+\z/', $callsign)) { - throw new ConduitException('ERR-BAD-CALLSIGN'); - } - $repository->setCallsign($callsign); - - $local_path = PhabricatorEnv::getEnvConfig( - 'repository.default-local-path'); - - $local_path = rtrim($local_path, '/'); - $local_path = $local_path.'/'.$callsign.'/'; - - $vcs = $request->getValue('vcs'); - - $map = array( - 'git' => PhabricatorRepositoryType::REPOSITORY_TYPE_GIT, - 'hg' => PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL, - 'svn' => PhabricatorRepositoryType::REPOSITORY_TYPE_SVN, - ); - if (empty($map[$vcs])) { - throw new ConduitException('ERR-UNKNOWN-REPOSITORY-VCS'); - } - $repository->setVersionControlSystem($map[$vcs]); - - $repository->setCredentialPHID($request->getValue('credentialPHID')); - - $remote_uri = $request->getValue('uri'); - PhabricatorRepository::assertValidRemoteURI($remote_uri); - - $details = array( - 'encoding' => $request->getValue('encoding'), - 'description' => $request->getValue('description'), - 'tracking-enabled' => (bool)$request->getValue('tracking', true), - 'remote-uri' => $remote_uri, - 'branch-filter' => array_fill_keys( - $request->getValue('branchFilter', array()), - true), - 'close-commits-filter' => array_fill_keys( - $request->getValue('closeCommitsFilter', array()), - true), - 'pull-frequency' => $request->getValue('pullFrequency'), - 'default-branch' => $request->getValue('defaultBranch'), - 'herald-disabled' => !$request->getValue('heraldEnabled', true), - 'svn-subpath' => $request->getValue('svnSubpath'), - 'disable-autoclose' => !$request->getValue('autocloseEnabled', true), - ); - - foreach ($details as $key => $value) { - $repository->setDetail($key, $value); - } - - $repository->setLocalPath($local_path); - - try { - $repository->save(); - } catch (AphrontDuplicateKeyQueryException $ex) { - throw new ConduitException('ERR-DUPLICATE'); - } - - return $repository->toDictionary(); - } - -}