2012-05-05 01:16:22 +02:00
|
|
|
<?php
|
|
|
|
|
Rename Conduit classes
Summary: Ref T5655. Rename Conduit classes and provide a `getAPIMethodName` method to declare the API method.
Test Plan:
```
> echo '{}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit user.whoami
Waiting for JSON parameters on stdin...
{"error":null,"errorMessage":null,"response":{"phid":"PHID-USER-lioqffnwn6y475mu5ndb","userName":"josh","realName":"Joshua Spence","image":"http:\/\/phabricator.joshuaspence.com\/res\/1404425321T\/phabricator\/3eb28cd9\/rsrc\/image\/avatar.png","uri":"http:\/\/phabricator.joshuaspence.com\/p\/josh\/","roles":["admin","verified","approved","activated"]}}
```
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin, hach-que
Maniphest Tasks: T5655
Differential Revision: https://secure.phabricator.com/D9991
2014-07-25 02:54:15 +02:00
|
|
|
final class RepositoryCreateConduitAPIMethod
|
|
|
|
extends RepositoryConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'repository.create';
|
|
|
|
}
|
2012-05-05 01:16:22 +02:00
|
|
|
|
|
|
|
public function getMethodStatus() {
|
|
|
|
return self::METHOD_STATUS_UNSTABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMethodStatusDescription() {
|
2014-06-09 20:36:49 +02:00
|
|
|
return 'Repository methods are new and subject to change.';
|
2012-05-05 01:16:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getMethodDescription() {
|
2014-06-09 20:36:49 +02:00
|
|
|
return 'Create a new repository (Admin Only).';
|
2012-05-05 01:16:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function defineParamTypes() {
|
2014-05-15 06:59:03 +02:00
|
|
|
$vcs_const = $this->formatStringConstants(array('git', 'hg', 'svn'));
|
|
|
|
|
2012-05-05 01:16:22 +02:00
|
|
|
return array(
|
2012-06-14 21:32:22 +02:00
|
|
|
'name' => 'required string',
|
2014-05-15 06:59:03 +02:00
|
|
|
'vcs' => 'required '.$vcs_const,
|
2012-06-14 21:32:22 +02:00
|
|
|
'callsign' => 'required string',
|
2012-06-28 18:54:48 +02:00
|
|
|
'description' => 'optional string',
|
2012-06-14 21:32:22 +02:00
|
|
|
'encoding' => 'optional string',
|
|
|
|
'tracking' => 'optional bool',
|
2014-07-10 00:35:24 +02:00
|
|
|
'uri' => 'required string',
|
2013-11-23 00:23:33 +01:00
|
|
|
'credentialPHID' => 'optional string',
|
2012-06-14 21:32:22 +02:00
|
|
|
'svnSubpath' => 'optional string',
|
|
|
|
'branchFilter' => 'optional list<string>',
|
|
|
|
'closeCommitsFilter' => 'optional list<string>',
|
|
|
|
'pullFrequency' => 'optional int',
|
|
|
|
'defaultBranch' => 'optional string',
|
2012-06-28 18:54:48 +02:00
|
|
|
'heraldEnabled' => 'optional bool, default = true',
|
|
|
|
'autocloseEnabled' => 'optional bool, default = true',
|
2012-06-14 21:32:22 +02:00
|
|
|
'svnUUID' => 'optional string',
|
2012-05-05 01:16:22 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineReturnType() {
|
|
|
|
return 'nonempty dict';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineErrorTypes() {
|
|
|
|
return array(
|
|
|
|
'ERR-PERMISSIONS' =>
|
|
|
|
'You do not have the authority to call this method.',
|
|
|
|
'ERR-DUPLICATE' =>
|
|
|
|
'Duplicate repository callsign.',
|
|
|
|
'ERR-BAD-CALLSIGN' =>
|
|
|
|
'Callsign is required and must be ALL UPPERCASE LETTERS.',
|
|
|
|
'ERR-UNKNOWN-REPOSITORY-VCS' =>
|
|
|
|
'Unknown repository VCS type.',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
2013-10-26 02:46:08 +02:00
|
|
|
$application = id(new PhabricatorApplicationQuery())
|
|
|
|
->setViewer($request->getUser())
|
2014-07-23 02:03:09 +02:00
|
|
|
->withClasses(array('PhabricatorDiffusionApplication'))
|
2013-10-26 02:46:08 +02:00
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
PhabricatorPolicyFilter::requireCapability(
|
|
|
|
$request->getUser(),
|
|
|
|
$application,
|
2014-07-25 00:20:39 +02:00
|
|
|
DiffusionCreateRepositoriesCapability::CAPABILITY);
|
2012-05-05 01:16:22 +02:00
|
|
|
|
|
|
|
// 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
|
2013-10-26 02:46:08 +02:00
|
|
|
// stabilizes. Specifically, this should move to transactions since they
|
|
|
|
// work properly now.
|
|
|
|
|
|
|
|
$repository = PhabricatorRepository::initializeNewRepository(
|
|
|
|
$request->getUser());
|
2012-05-05 01:16:22 +02:00
|
|
|
|
|
|
|
$repository->setName($request->getValue('name'));
|
|
|
|
|
|
|
|
$callsign = $request->getValue('callsign');
|
2014-03-13 20:42:41 +01:00
|
|
|
if (!preg_match('/^[A-Z]+\z/', $callsign)) {
|
2012-05-05 01:16:22 +02:00
|
|
|
throw new ConduitException('ERR-BAD-CALLSIGN');
|
|
|
|
}
|
|
|
|
$repository->setCallsign($callsign);
|
|
|
|
|
2014-07-10 00:35:24 +02:00
|
|
|
$local_path = PhabricatorEnv::getEnvConfig(
|
|
|
|
'repository.default-local-path');
|
|
|
|
|
|
|
|
$local_path = rtrim($local_path, '/');
|
|
|
|
$local_path = $local_path.'/'.$callsign.'/';
|
|
|
|
|
2012-05-05 01:16:22 +02:00
|
|
|
$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]);
|
|
|
|
|
2013-11-23 00:23:33 +01:00
|
|
|
$repository->setCredentialPHID($request->getValue('credentialPHID'));
|
|
|
|
|
2014-06-13 16:07:00 +02:00
|
|
|
$remote_uri = $request->getValue('uri');
|
|
|
|
PhabricatorRepository::assertValidRemoteURI($remote_uri);
|
|
|
|
|
2012-05-05 01:16:22 +02:00
|
|
|
$details = array(
|
|
|
|
'encoding' => $request->getValue('encoding'),
|
2012-06-28 18:54:48 +02:00
|
|
|
'description' => $request->getValue('description'),
|
2012-05-05 01:16:22 +02:00
|
|
|
'tracking-enabled' => (bool)$request->getValue('tracking', true),
|
2014-06-13 16:07:00 +02:00
|
|
|
'remote-uri' => $remote_uri,
|
2014-07-10 00:35:24 +02:00
|
|
|
'local-path' => $local_path,
|
2012-05-05 01:16:22 +02:00
|
|
|
'branch-filter' => array_fill_keys(
|
|
|
|
$request->getValue('branchFilter', array()),
|
|
|
|
true),
|
2012-06-14 21:32:22 +02:00
|
|
|
'close-commits-filter' => array_fill_keys(
|
|
|
|
$request->getValue('closeCommitsFilter', array()),
|
|
|
|
true),
|
2012-05-05 01:16:22 +02:00
|
|
|
'pull-frequency' => $request->getValue('pullFrequency'),
|
|
|
|
'default-branch' => $request->getValue('defaultBranch'),
|
|
|
|
'herald-disabled' => !$request->getValue('heraldEnabled', true),
|
|
|
|
'svn-subpath' => $request->getValue('svnSubpath'),
|
2012-06-28 18:54:48 +02:00
|
|
|
'disable-autoclose' => !$request->getValue('autocloseEnabled', true),
|
2012-05-05 01:16:22 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($details as $key => $value) {
|
|
|
|
$repository->setDetail($key, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$repository->save();
|
2014-08-05 23:51:21 +02:00
|
|
|
} catch (AphrontDuplicateKeyQueryException $ex) {
|
2012-05-05 01:16:22 +02:00
|
|
|
throw new ConduitException('ERR-DUPLICATE');
|
|
|
|
}
|
|
|
|
|
2013-01-11 00:37:38 +01:00
|
|
|
return $repository->toDictionary();
|
2012-05-05 01:16:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|