@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.

Add "repository.create" and "repository.query" methods to Conduit

Summary: Primarily for @csilvers who has 92 million repositories or something. This is a touch hacky, but movitated by pragmatism.

Test Plan:
- Ran "repository.create" to create repositories, "repository.query" to list them.
- Tested most or maybe all of the error conditions, probably.

Reviewers: btrahan, vrana, csilvers

Reviewed By: csilvers

CC: aran

Differential Revision: https://secure.phabricator.com/D2396

+290
+6
src/__phutil_library_map__.php
··· 176 176 'ConduitAPI_project_Method' => 'applications/conduit/method/project/base', 177 177 'ConduitAPI_project_query_Method' => 'applications/conduit/method/project/query', 178 178 'ConduitAPI_remarkup_process_Method' => 'applications/conduit/method/remarkup/process', 179 + 'ConduitAPI_repository_Method' => 'applications/conduit/method/repository/base', 180 + 'ConduitAPI_repository_create_Method' => 'applications/conduit/method/repository/create', 181 + 'ConduitAPI_repository_query_Method' => 'applications/conduit/method/repository/query', 179 182 'ConduitAPI_slowvote_info_Method' => 'applications/conduit/method/slowvote/info', 180 183 'ConduitAPI_user_Method' => 'applications/conduit/method/user/base', 181 184 'ConduitAPI_user_addstatus_Method' => 'applications/conduit/method/user/addstatus', ··· 1198 1201 'ConduitAPI_project_Method' => 'ConduitAPIMethod', 1199 1202 'ConduitAPI_project_query_Method' => 'ConduitAPI_project_Method', 1200 1203 'ConduitAPI_remarkup_process_Method' => 'ConduitAPIMethod', 1204 + 'ConduitAPI_repository_Method' => 'ConduitAPIMethod', 1205 + 'ConduitAPI_repository_create_Method' => 'ConduitAPI_repository_Method', 1206 + 'ConduitAPI_repository_query_Method' => 'ConduitAPI_repository_Method', 1201 1207 'ConduitAPI_slowvote_info_Method' => 'ConduitAPIMethod', 1202 1208 'ConduitAPI_user_Method' => 'ConduitAPIMethod', 1203 1209 'ConduitAPI_user_addstatus_Method' => 'ConduitAPI_user_Method',
+35
src/applications/conduit/method/repository/base/ConduitAPI_repository_Method.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + /** 20 + * @group conduit 21 + */ 22 + abstract class ConduitAPI_repository_Method extends ConduitAPIMethod { 23 + 24 + protected function buildDictForRepository(PhabricatorRepository $repository) { 25 + return array( 26 + 'name' => $repository->getName(), 27 + 'callsign' => $repository->getCallsign(), 28 + 'vcs' => $repository->getVersionControlSystem(), 29 + 'uri' => PhabricatorEnv::getProductionURI($repository->getURI()), 30 + 'remoteURI' => $repository->getPublicRemoteURI(), 31 + 'tracking' => $repository->getDetail('tracking-enabled'), 32 + ); 33 + } 34 + 35 + }
+13
src/applications/conduit/method/repository/base/__init__.php
··· 1 + <?php 2 + /** 3 + * This file is automatically generated. Lint this module to rebuild it. 4 + * @generated 5 + */ 6 + 7 + 8 + 9 + phutil_require_module('phabricator', 'applications/conduit/method/base'); 10 + phutil_require_module('phabricator', 'infrastructure/env'); 11 + 12 + 13 + phutil_require_source('ConduitAPI_repository_Method.php');
+138
src/applications/conduit/method/repository/create/ConduitAPI_repository_create_Method.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + /** 20 + * @group conduit 21 + */ 22 + final class ConduitAPI_repository_create_Method 23 + extends ConduitAPI_repository_Method { 24 + 25 + public function getMethodStatus() { 26 + return self::METHOD_STATUS_UNSTABLE; 27 + } 28 + 29 + public function getMethodStatusDescription() { 30 + return "Repository methods are new and subject to change."; 31 + } 32 + 33 + public function getMethodDescription() { 34 + return "Create a new repository (Admin Only)."; 35 + } 36 + 37 + public function defineParamTypes() { 38 + return array( 39 + 'name' => 'required string', 40 + 'vcs' => 'required enum<git, hg, svn>', 41 + 'callsign' => 'required string', 42 + 'encoding' => 'optional string', 43 + 'tracking' => 'optional bool', 44 + 'uri' => 'optional string', 45 + 'sshUser' => 'optional string', 46 + 'sshKey' => 'optional string', 47 + 'sshKeyFile' => 'optional string', 48 + 'httpUser' => 'optional string', 49 + 'httpPassword' => 'optional string', 50 + 'localPath' => 'optional string', 51 + 'svnSubpath' => 'optional string', 52 + 'branchFilter' => 'optional list<string>', 53 + 'pullFrequency' => 'optional int', 54 + 'defaultBranch' => 'optional string', 55 + 'heraldEnabled' => 'optional bool', 56 + 'svnUUID' => 'optional string', 57 + ); 58 + } 59 + 60 + public function defineReturnType() { 61 + return 'nonempty dict'; 62 + } 63 + 64 + public function defineErrorTypes() { 65 + return array( 66 + 'ERR-PERMISSIONS' => 67 + 'You do not have the authority to call this method.', 68 + 'ERR-DUPLICATE' => 69 + 'Duplicate repository callsign.', 70 + 'ERR-BAD-CALLSIGN' => 71 + 'Callsign is required and must be ALL UPPERCASE LETTERS.', 72 + 'ERR-UNKNOWN-REPOSITORY-VCS' => 73 + 'Unknown repository VCS type.', 74 + ); 75 + } 76 + 77 + protected function execute(ConduitAPIRequest $request) { 78 + if (!$request->getUser()->getIsAdmin()) { 79 + throw new ConduitException('ERR-PERMISSIONS'); 80 + } 81 + 82 + // TODO: This has some duplication with (and lacks some of the validation 83 + // of) the web workflow; refactor things so they can share more code as this 84 + // stabilizes. 85 + 86 + $repository = new PhabricatorRepository(); 87 + $repository->setName($request->getValue('name')); 88 + 89 + $callsign = $request->getValue('callsign'); 90 + if (!preg_match('/[A-Z]+$/', $callsign)) { 91 + throw new ConduitException('ERR-BAD-CALLSIGN'); 92 + } 93 + $repository->setCallsign($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 + $details = array( 108 + 'encoding' => $request->getValue('encoding'), 109 + 'tracking-enabled' => (bool)$request->getValue('tracking', true), 110 + 'remote-uri' => $request->getValue('uri'), 111 + 'local-path' => $request->getValue('localPath'), 112 + 'branch-filter' => array_fill_keys( 113 + $request->getValue('branchFilter', array()), 114 + true), 115 + 'pull-frequency' => $request->getValue('pullFrequency'), 116 + 'default-branch' => $request->getValue('defaultBranch'), 117 + 'ssh-login' => $request->getValue('sshUser'), 118 + 'ssh-key' => $request->getValue('sshKey'), 119 + 'ssh-keyfile' => $request->getValue('sshKeyFile'), 120 + 'herald-disabled' => !$request->getValue('heraldEnabled', true), 121 + 'svn-subpath' => $request->getValue('svnSubpath'), 122 + ); 123 + 124 + foreach ($details as $key => $value) { 125 + $repository->setDetail($key, $value); 126 + } 127 + 128 + try { 129 + $repository->save(); 130 + } catch (AphrontQueryDuplicateKeyException $ex) { 131 + throw new ConduitException('ERR-DUPLICATE'); 132 + } 133 + 134 + return $this->buildDictForRepository($repository); 135 + } 136 + 137 + 138 + }
+15
src/applications/conduit/method/repository/create/__init__.php
··· 1 + <?php 2 + /** 3 + * This file is automatically generated. Lint this module to rebuild it. 4 + * @generated 5 + */ 6 + 7 + 8 + 9 + phutil_require_module('phabricator', 'applications/conduit/method/repository/base'); 10 + phutil_require_module('phabricator', 'applications/conduit/protocol/exception'); 11 + phutil_require_module('phabricator', 'applications/repository/constants/repositorytype'); 12 + phutil_require_module('phabricator', 'applications/repository/storage/repository'); 13 + 14 + 15 + phutil_require_source('ConduitAPI_repository_create_Method.php');
+61
src/applications/conduit/method/repository/query/ConduitAPI_repository_query_Method.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + /** 20 + * @group conduit 21 + */ 22 + final class ConduitAPI_repository_query_Method 23 + extends ConduitAPI_repository_Method { 24 + 25 + public function getMethodStatus() { 26 + return self::METHOD_STATUS_UNSTABLE; 27 + } 28 + 29 + public function getMethodStatusDescription() { 30 + return "Repository methods are new and subject to change."; 31 + } 32 + 33 + public function getMethodDescription() { 34 + return "Query repositories."; 35 + } 36 + 37 + public function defineParamTypes() { 38 + return array( 39 + ); 40 + } 41 + 42 + public function defineReturnType() { 43 + return 'list<dict>'; 44 + } 45 + 46 + public function defineErrorTypes() { 47 + return array( 48 + ); 49 + } 50 + 51 + protected function execute(ConduitAPIRequest $request) { 52 + $repositories = id(new PhabricatorRepository())->loadAll(); 53 + 54 + $results = array(); 55 + foreach ($repositories as $repository) { 56 + $results[] = $this->buildDictForRepository($repository); 57 + } 58 + 59 + return $results; 60 + } 61 + }
+15
src/applications/conduit/method/repository/query/__init__.php
··· 1 + <?php 2 + /** 3 + * This file is automatically generated. Lint this module to rebuild it. 4 + * @generated 5 + */ 6 + 7 + 8 + 9 + phutil_require_module('phabricator', 'applications/conduit/method/repository/base'); 10 + phutil_require_module('phabricator', 'applications/repository/storage/repository'); 11 + 12 + phutil_require_module('phutil', 'utils'); 13 + 14 + 15 + phutil_require_source('ConduitAPI_repository_query_Method.php');
+7
src/applications/repository/storage/repository/PhabricatorRepository.php
··· 94 94 95 95 public function getRemoteURI() { 96 96 $raw_uri = $this->getDetail('remote-uri'); 97 + if (!$raw_uri) { 98 + return null; 99 + } 97 100 98 101 $vcs = $this->getVersionControlSystem(); 99 102 $is_git = ($vcs == PhabricatorRepositoryType::REPOSITORY_TYPE_GIT); ··· 326 329 $uri->setPass(null); 327 330 328 331 return $uri; 332 + } 333 + 334 + public function getURI() { 335 + return '/diffusion/'.$this->getCallsign().'/'; 329 336 } 330 337 331 338 private function isSSHProtocol($protocol) {