[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
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 'Repository methods are new and subject to change.'; 16 } 17 18 public function getMethodDescription() { 19 return 'Create a new repository (Admin Only).'; 20 } 21 22 public 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 public function defineReturnType() { 46 return 'nonempty dict'; 47 } 48 49 public function defineErrorTypes() { 50 return array( 51 'ERR-PERMISSIONS' => 52 'You do not have the authority to call this method.', 53 'ERR-DUPLICATE' => 54 'Duplicate repository callsign.', 55 'ERR-BAD-CALLSIGN' => 56 'Callsign is required and must be ALL UPPERCASE LETTERS.', 57 'ERR-UNKNOWN-REPOSITORY-VCS' => 58 'Unknown repository VCS type.', 59 ); 60 } 61 62 protected function execute(ConduitAPIRequest $request) { 63 $application = id(new PhabricatorApplicationQuery()) 64 ->setViewer($request->getUser()) 65 ->withClasses(array('PhabricatorDiffusionApplication')) 66 ->executeOne(); 67 68 PhabricatorPolicyFilter::requireCapability( 69 $request->getUser(), 70 $application, 71 DiffusionCreateRepositoriesCapability::CAPABILITY); 72 73 // TODO: This has some duplication with (and lacks some of the validation 74 // of) the web workflow; refactor things so they can share more code as this 75 // stabilizes. Specifically, this should move to transactions since they 76 // work properly now. 77 78 $repository = PhabricatorRepository::initializeNewRepository( 79 $request->getUser()); 80 81 $repository->setName($request->getValue('name')); 82 83 $callsign = $request->getValue('callsign'); 84 if (!preg_match('/^[A-Z]+\z/', $callsign)) { 85 throw new ConduitException('ERR-BAD-CALLSIGN'); 86 } 87 $repository->setCallsign($callsign); 88 89 $local_path = PhabricatorEnv::getEnvConfig( 90 'repository.default-local-path'); 91 92 $local_path = rtrim($local_path, '/'); 93 $local_path = $local_path.'/'.$callsign.'/'; 94 95 $vcs = $request->getValue('vcs'); 96 97 $map = array( 98 'git' => PhabricatorRepositoryType::REPOSITORY_TYPE_GIT, 99 'hg' => PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL, 100 'svn' => PhabricatorRepositoryType::REPOSITORY_TYPE_SVN, 101 ); 102 if (empty($map[$vcs])) { 103 throw new ConduitException('ERR-UNKNOWN-REPOSITORY-VCS'); 104 } 105 $repository->setVersionControlSystem($map[$vcs]); 106 107 $repository->setCredentialPHID($request->getValue('credentialPHID')); 108 109 $remote_uri = $request->getValue('uri'); 110 PhabricatorRepository::assertValidRemoteURI($remote_uri); 111 112 $details = array( 113 'encoding' => $request->getValue('encoding'), 114 'description' => $request->getValue('description'), 115 'tracking-enabled' => (bool)$request->getValue('tracking', true), 116 'remote-uri' => $remote_uri, 117 'local-path' => $local_path, 118 'branch-filter' => array_fill_keys( 119 $request->getValue('branchFilter', array()), 120 true), 121 'close-commits-filter' => array_fill_keys( 122 $request->getValue('closeCommitsFilter', array()), 123 true), 124 'pull-frequency' => $request->getValue('pullFrequency'), 125 'default-branch' => $request->getValue('defaultBranch'), 126 'herald-disabled' => !$request->getValue('heraldEnabled', true), 127 'svn-subpath' => $request->getValue('svnSubpath'), 128 'disable-autoclose' => !$request->getValue('autocloseEnabled', true), 129 ); 130 131 foreach ($details as $key => $value) { 132 $repository->setDetail($key, $value); 133 } 134 135 try { 136 $repository->save(); 137 } catch (AphrontDuplicateKeyQueryException $ex) { 138 throw new ConduitException('ERR-DUPLICATE'); 139 } 140 141 return $repository->toDictionary(); 142 } 143 144 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |