@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

-143
-2
src/__phutil_library_map__.php
··· 4105 4105 'ReleephWorkRecordPickStatusConduitAPIMethod' => 'applications/releeph/conduit/work/ReleephWorkRecordPickStatusConduitAPIMethod.php', 4106 4106 'RemarkupProcessConduitAPIMethod' => 'applications/remarkup/conduit/RemarkupProcessConduitAPIMethod.php', 4107 4107 'RepositoryConduitAPIMethod' => 'applications/repository/conduit/RepositoryConduitAPIMethod.php', 4108 - 'RepositoryCreateConduitAPIMethod' => 'applications/repository/conduit/RepositoryCreateConduitAPIMethod.php', 4109 4108 'RepositoryQueryConduitAPIMethod' => 'applications/repository/conduit/RepositoryQueryConduitAPIMethod.php', 4110 4109 'ShellLogView' => 'applications/harbormaster/view/ShellLogView.php', 4111 4110 'SlowvoteConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteConduitAPIMethod.php', ··· 8988 8987 'ReleephWorkRecordPickStatusConduitAPIMethod' => 'ReleephConduitAPIMethod', 8989 8988 'RemarkupProcessConduitAPIMethod' => 'ConduitAPIMethod', 8990 8989 'RepositoryConduitAPIMethod' => 'ConduitAPIMethod', 8991 - 'RepositoryCreateConduitAPIMethod' => 'RepositoryConduitAPIMethod', 8992 8990 'RepositoryQueryConduitAPIMethod' => 'RepositoryConduitAPIMethod', 8993 8991 'ShellLogView' => 'AphrontView', 8994 8992 'SlowvoteConduitAPIMethod' => 'ConduitAPIMethod',
-141
src/applications/repository/conduit/RepositoryCreateConduitAPIMethod.php
··· 1 - <?php 2 - 3 - final class RepositoryCreateConduitAPIMethod 4 - extends RepositoryConduitAPIMethod { 5 - 6 - public function getAPIMethodName() { 7 - return 'repository.create'; 8 - } 9 - 10 - public function getMethodStatus() { 11 - return self::METHOD_STATUS_UNSTABLE; 12 - } 13 - 14 - public function getMethodStatusDescription() { 15 - return pht('Repository methods are new and subject to change.'); 16 - } 17 - 18 - public function getMethodDescription() { 19 - return pht('Create a new repository.'); 20 - } 21 - 22 - protected function defineParamTypes() { 23 - $vcs_const = $this->formatStringConstants(array('git', 'hg', 'svn')); 24 - 25 - return array( 26 - 'name' => 'required string', 27 - 'vcs' => 'required '.$vcs_const, 28 - 'callsign' => 'required string', 29 - 'description' => 'optional string', 30 - 'encoding' => 'optional string', 31 - 'tracking' => 'optional bool', 32 - 'uri' => 'required string', 33 - 'credentialPHID' => 'optional string', 34 - 'svnSubpath' => 'optional string', 35 - 'branchFilter' => 'optional list<string>', 36 - 'closeCommitsFilter' => 'optional list<string>', 37 - 'pullFrequency' => 'optional int', 38 - 'defaultBranch' => 'optional string', 39 - 'heraldEnabled' => 'optional bool, default = true', 40 - 'autocloseEnabled' => 'optional bool, default = true', 41 - 'svnUUID' => 'optional string', 42 - ); 43 - } 44 - 45 - protected function defineReturnType() { 46 - return 'nonempty dict'; 47 - } 48 - 49 - protected function defineErrorTypes() { 50 - return array( 51 - 'ERR-DUPLICATE' => pht('Duplicate repository callsign.'), 52 - 'ERR-BAD-CALLSIGN' => pht( 53 - 'Callsign is required and must be ALL UPPERCASE LETTERS.'), 54 - 'ERR-UNKNOWN-REPOSITORY-VCS' => pht('Unknown repository VCS type.'), 55 - ); 56 - } 57 - 58 - protected function execute(ConduitAPIRequest $request) { 59 - $application = id(new PhabricatorApplicationQuery()) 60 - ->setViewer($request->getUser()) 61 - ->withClasses(array('PhabricatorDiffusionApplication')) 62 - ->executeOne(); 63 - 64 - PhabricatorPolicyFilter::requireCapability( 65 - $request->getUser(), 66 - $application, 67 - DiffusionCreateRepositoriesCapability::CAPABILITY); 68 - 69 - // TODO: This has some duplication with (and lacks some of the validation 70 - // of) the web workflow; refactor things so they can share more code as this 71 - // stabilizes. Specifically, this should move to transactions since they 72 - // work properly now. 73 - 74 - $repository = PhabricatorRepository::initializeNewRepository( 75 - $request->getUser()); 76 - 77 - $repository->setName($request->getValue('name')); 78 - 79 - $callsign = $request->getValue('callsign'); 80 - if (!preg_match('/^[A-Z]+\z/', $callsign)) { 81 - throw new ConduitException('ERR-BAD-CALLSIGN'); 82 - } 83 - $repository->setCallsign($callsign); 84 - 85 - $local_path = PhabricatorEnv::getEnvConfig( 86 - 'repository.default-local-path'); 87 - 88 - $local_path = rtrim($local_path, '/'); 89 - $local_path = $local_path.'/'.$callsign.'/'; 90 - 91 - $vcs = $request->getValue('vcs'); 92 - 93 - $map = array( 94 - 'git' => PhabricatorRepositoryType::REPOSITORY_TYPE_GIT, 95 - 'hg' => PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL, 96 - 'svn' => PhabricatorRepositoryType::REPOSITORY_TYPE_SVN, 97 - ); 98 - if (empty($map[$vcs])) { 99 - throw new ConduitException('ERR-UNKNOWN-REPOSITORY-VCS'); 100 - } 101 - $repository->setVersionControlSystem($map[$vcs]); 102 - 103 - $repository->setCredentialPHID($request->getValue('credentialPHID')); 104 - 105 - $remote_uri = $request->getValue('uri'); 106 - PhabricatorRepository::assertValidRemoteURI($remote_uri); 107 - 108 - $details = array( 109 - 'encoding' => $request->getValue('encoding'), 110 - 'description' => $request->getValue('description'), 111 - 'tracking-enabled' => (bool)$request->getValue('tracking', true), 112 - 'remote-uri' => $remote_uri, 113 - 'branch-filter' => array_fill_keys( 114 - $request->getValue('branchFilter', array()), 115 - true), 116 - 'close-commits-filter' => array_fill_keys( 117 - $request->getValue('closeCommitsFilter', array()), 118 - true), 119 - 'pull-frequency' => $request->getValue('pullFrequency'), 120 - 'default-branch' => $request->getValue('defaultBranch'), 121 - 'herald-disabled' => !$request->getValue('heraldEnabled', true), 122 - 'svn-subpath' => $request->getValue('svnSubpath'), 123 - 'disable-autoclose' => !$request->getValue('autocloseEnabled', true), 124 - ); 125 - 126 - foreach ($details as $key => $value) { 127 - $repository->setDetail($key, $value); 128 - } 129 - 130 - $repository->setLocalPath($local_path); 131 - 132 - try { 133 - $repository->save(); 134 - } catch (AphrontDuplicateKeyQueryException $ex) { 135 - throw new ConduitException('ERR-DUPLICATE'); 136 - } 137 - 138 - return $repository->toDictionary(); 139 - } 140 - 141 - }