2013-05-01 23:44:28 +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
|
|
|
abstract class DiffusionQueryConduitAPIMethod
|
|
|
|
extends DiffusionConduitAPIMethod {
|
2013-05-01 23:44:28 +02:00
|
|
|
|
2013-10-22 22:47:52 +02:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-07 23:57:08 +02:00
|
|
|
public function getMethodStatus() {
|
|
|
|
return self::METHOD_STATUS_UNSTABLE;
|
|
|
|
}
|
2013-10-22 22:47:52 +02:00
|
|
|
|
2013-05-07 23:57:08 +02:00
|
|
|
public function getMethodStatusDescription() {
|
|
|
|
return pht(
|
|
|
|
'See T2784 - migrating diffusion working copy calls to conduit methods. '.
|
|
|
|
'Until that task is completed (and possibly after) these methods are '.
|
|
|
|
'unstable.');
|
|
|
|
}
|
|
|
|
|
2013-05-01 23:44:28 +02:00
|
|
|
private $diffusionRequest;
|
2013-05-15 00:32:19 +02:00
|
|
|
private $repository;
|
|
|
|
|
2013-05-01 23:44:28 +02:00
|
|
|
protected function setDiffusionRequest(DiffusionRequest $request) {
|
|
|
|
$this->diffusionRequest = $request;
|
|
|
|
return $this;
|
|
|
|
}
|
2014-05-13 22:51:33 +02:00
|
|
|
|
2013-05-01 23:44:28 +02:00
|
|
|
protected function getDiffusionRequest() {
|
|
|
|
return $this->diffusionRequest;
|
|
|
|
}
|
|
|
|
|
2013-05-15 00:32:19 +02:00
|
|
|
protected function getRepository(ConduitAPIRequest $request) {
|
2014-05-13 22:51:33 +02:00
|
|
|
return $this->getDiffusionRequest()->getRepository();
|
2013-05-15 00:32:19 +02:00
|
|
|
}
|
|
|
|
|
2013-05-01 23:44:28 +02:00
|
|
|
final public function defineErrorTypes() {
|
|
|
|
return $this->defineCustomErrorTypes() +
|
|
|
|
array(
|
2013-05-15 00:32:19 +02:00
|
|
|
'ERR-UNKNOWN-REPOSITORY' =>
|
|
|
|
pht('There is no repository with that callsign.'),
|
|
|
|
'ERR-UNKNOWN-VCS-TYPE' =>
|
2013-05-01 23:44:28 +02:00
|
|
|
pht('Unknown repository VCS type.'),
|
|
|
|
'ERR-UNSUPPORTED-VCS' =>
|
2014-10-07 15:01:04 +02:00
|
|
|
pht('VCS is not supported for this method.'),
|
|
|
|
);
|
2013-05-01 23:44:28 +02:00
|
|
|
}
|
2014-07-10 00:12:48 +02:00
|
|
|
|
2013-05-01 23:44:28 +02:00
|
|
|
/**
|
|
|
|
* Subclasses should override this to specify custom error types.
|
|
|
|
*/
|
|
|
|
protected function defineCustomErrorTypes() {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function defineParamTypes() {
|
|
|
|
return $this->defineCustomParamTypes() +
|
|
|
|
array(
|
2013-08-13 19:11:15 +02:00
|
|
|
'callsign' => 'required string',
|
|
|
|
'branch' => 'optional string',
|
|
|
|
);
|
2013-05-01 23:44:28 +02:00
|
|
|
}
|
2014-07-10 00:12:48 +02:00
|
|
|
|
2013-05-01 23:44:28 +02:00
|
|
|
/**
|
|
|
|
* Subclasses should override this to specify custom param types.
|
|
|
|
*/
|
|
|
|
protected function defineCustomParamTypes() {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subclasses should override these methods with the proper result for the
|
|
|
|
* pertinent version control system, e.g. getGitResult for Git.
|
|
|
|
*
|
|
|
|
* If the result is not supported for that VCS, do not implement it. e.g.
|
|
|
|
* Subversion (SVN) does not support branches.
|
|
|
|
*/
|
|
|
|
protected function getGitResult(ConduitAPIRequest $request) {
|
|
|
|
throw new ConduitException('ERR-UNSUPPORTED-VCS');
|
|
|
|
}
|
|
|
|
protected function getSVNResult(ConduitAPIRequest $request) {
|
|
|
|
throw new ConduitException('ERR-UNSUPPORTED-VCS');
|
|
|
|
}
|
|
|
|
protected function getMercurialResult(ConduitAPIRequest $request) {
|
|
|
|
throw new ConduitException('ERR-UNSUPPORTED-VCS');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-15 00:32:19 +02:00
|
|
|
* This method is final because most queries will need to construct a
|
2013-05-01 23:44:28 +02:00
|
|
|
* @{class:DiffusionRequest} and use it. Consolidating this codepath and
|
|
|
|
* enforcing @{method:getDiffusionRequest} works when we need it is good.
|
|
|
|
*
|
|
|
|
* @{method:getResult} should be overridden by subclasses as necessary, e.g.
|
|
|
|
* there is a common operation across all version control systems that
|
|
|
|
* should occur after @{method:getResult}, like formatting a timestamp.
|
|
|
|
*/
|
|
|
|
final protected function execute(ConduitAPIRequest $request) {
|
2014-05-13 22:51:33 +02:00
|
|
|
$drequest = DiffusionRequest::newFromDictionary(
|
|
|
|
array(
|
|
|
|
'user' => $request->getUser(),
|
|
|
|
'callsign' => $request->getValue('callsign'),
|
|
|
|
'branch' => $request->getValue('branch'),
|
|
|
|
'path' => $request->getValue('path'),
|
|
|
|
'commit' => $request->getValue('commit'),
|
|
|
|
'initFromConduit' => false,
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->setDiffusionRequest($drequest);
|
2013-05-01 23:44:28 +02:00
|
|
|
|
|
|
|
return $this->getResult($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getResult(ConduitAPIRequest $request) {
|
2013-05-15 00:32:19 +02:00
|
|
|
$repository = $this->getRepository($request);
|
2013-05-01 23:44:28 +02:00
|
|
|
$result = null;
|
|
|
|
switch ($repository->getVersionControlSystem()) {
|
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
|
|
|
$result = $this->getGitResult($request);
|
|
|
|
break;
|
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
|
|
|
|
$result = $this->getMercurialResult($request);
|
|
|
|
break;
|
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
|
|
|
$result = $this->getSVNResult($request);
|
|
|
|
break;
|
|
|
|
default:
|
2013-05-15 00:32:19 +02:00
|
|
|
throw new ConduitException('ERR-UNKNOWN-VCS-TYPE');
|
2013-05-01 23:44:28 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2014-07-10 00:12:48 +02:00
|
|
|
|
2013-05-01 23:44:28 +02:00
|
|
|
}
|