2014-01-28 02:14:21 +01: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 DiffusionQueryCommitsConduitAPIMethod
|
|
|
|
extends DiffusionConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'diffusion.querycommits';
|
|
|
|
}
|
2014-01-28 02:14:21 +01:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
|
|
|
return pht('Retrieve information about commits.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineReturnType() {
|
|
|
|
return 'map<string, dict>';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineParamTypes() {
|
|
|
|
return array(
|
|
|
|
'ids' => 'optional list<int>',
|
|
|
|
'phids' => 'optional list<phid>',
|
|
|
|
'names' => 'optional list<string>',
|
|
|
|
'repositoryPHID' => 'optional phid',
|
2014-04-20 20:55:29 +02:00
|
|
|
'needMessages' => 'optional bool',
|
2014-09-03 14:49:44 +02:00
|
|
|
'bypassCache' => 'optional bool',
|
2014-01-28 02:14:21 +01:00
|
|
|
) + $this->getPagerParamTypes();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineErrorTypes() {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
2014-04-20 20:55:29 +02:00
|
|
|
$need_messages = $request->getValue('needMessages');
|
2014-09-03 14:49:44 +02:00
|
|
|
$bypass_cache = $request->getValue('bypassCache');
|
2014-04-20 20:55:29 +02:00
|
|
|
|
2014-01-28 02:14:21 +01:00
|
|
|
$query = id(new DiffusionCommitQuery())
|
2014-09-05 21:27:55 +02:00
|
|
|
->setViewer($request->getUser())
|
|
|
|
->needCommitData(true);
|
2014-04-20 20:55:29 +02:00
|
|
|
|
2014-01-28 02:14:21 +01:00
|
|
|
$repository_phid = $request->getValue('repositoryPHID');
|
|
|
|
if ($repository_phid) {
|
|
|
|
$repository = id(new PhabricatorRepositoryQuery())
|
|
|
|
->setViewer($request->getUser())
|
|
|
|
->withPHIDs(array($repository_phid))
|
|
|
|
->executeOne();
|
|
|
|
if ($repository) {
|
|
|
|
$query->withRepository($repository);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$names = $request->getValue('names');
|
|
|
|
if ($names) {
|
|
|
|
$query->withIdentifiers($names);
|
|
|
|
}
|
|
|
|
|
|
|
|
$ids = $request->getValue('ids');
|
|
|
|
if ($ids) {
|
|
|
|
$query->withIDs($ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
$phids = $request->getValue('phids');
|
|
|
|
if ($phids) {
|
|
|
|
$query->withPHIDs($phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
$pager = $this->newPager($request);
|
|
|
|
$commits = $query->executeWithCursorPager($pager);
|
|
|
|
|
|
|
|
$map = $query->getIdentifierMap();
|
|
|
|
$map = mpull($map, 'getPHID');
|
|
|
|
|
|
|
|
$data = array();
|
|
|
|
foreach ($commits as $commit) {
|
2014-09-05 21:27:55 +02:00
|
|
|
$commit_data = $commit->getCommitData();
|
|
|
|
|
2014-02-09 01:32:20 +01:00
|
|
|
$callsign = $commit->getRepository()->getCallsign();
|
|
|
|
$identifier = $commit->getCommitIdentifier();
|
|
|
|
$uri = '/r'.$callsign.$identifier;
|
|
|
|
$uri = PhabricatorEnv::getProductionURI($uri);
|
|
|
|
|
2014-04-20 20:55:29 +02:00
|
|
|
$dict = array(
|
2014-01-28 02:14:21 +01:00
|
|
|
'id' => $commit->getID(),
|
|
|
|
'phid' => $commit->getPHID(),
|
|
|
|
'repositoryPHID' => $commit->getRepository()->getPHID(),
|
2014-02-09 01:32:20 +01:00
|
|
|
'identifier' => $identifier,
|
2014-01-28 02:14:21 +01:00
|
|
|
'epoch' => $commit->getEpoch(),
|
2014-02-09 01:32:20 +01:00
|
|
|
'uri' => $uri,
|
2014-01-28 02:14:21 +01:00
|
|
|
'isImporting' => !$commit->isImported(),
|
2014-04-20 20:55:29 +02:00
|
|
|
'summary' => $commit->getSummary(),
|
2014-09-05 21:27:55 +02:00
|
|
|
'authorPHID' => $commit->getAuthorPHID(),
|
|
|
|
'committerPHID' => $commit_data->getCommitDetail('committerPHID'),
|
|
|
|
'author' => $commit_data->getAuthorName(),
|
|
|
|
'authorName' => $commit_data->getCommitDetail('authorName'),
|
|
|
|
'authorEmail' => $commit_data->getCommitDetail('authorEmail'),
|
|
|
|
'committer' => $commit_data->getCommitDetail('committer'),
|
|
|
|
'committerName' => $commit_data->getCommitDetail('committerName'),
|
|
|
|
'committerEmail' => $commit_data->getCommitDetail('committerEmail'),
|
2014-09-03 14:49:44 +02:00
|
|
|
'hashes' => array(),
|
2014-01-28 02:14:21 +01:00
|
|
|
);
|
2014-04-20 20:55:29 +02:00
|
|
|
|
2014-09-03 14:49:44 +02:00
|
|
|
if ($bypass_cache) {
|
|
|
|
$lowlevel_commitref = id(new DiffusionLowLevelCommitQuery())
|
|
|
|
->setRepository($commit->getRepository())
|
|
|
|
->withIdentifier($commit->getCommitIdentifier())
|
|
|
|
->execute();
|
|
|
|
|
2014-09-05 21:27:55 +02:00
|
|
|
$dict['author'] = $lowlevel_commitref->getAuthor();
|
2014-09-03 14:49:44 +02:00
|
|
|
$dict['authorName'] = $lowlevel_commitref->getAuthorName();
|
|
|
|
$dict['authorEmail'] = $lowlevel_commitref->getAuthorEmail();
|
2014-09-05 21:27:55 +02:00
|
|
|
$dict['committer'] = $lowlevel_commitref->getCommitter();
|
2014-09-03 14:49:44 +02:00
|
|
|
$dict['committerName'] = $lowlevel_commitref->getCommitterName();
|
|
|
|
$dict['committerEmail'] = $lowlevel_commitref->getCommitterEmail();
|
|
|
|
|
|
|
|
if ($need_messages) {
|
|
|
|
$dict['message'] = $lowlevel_commitref->getMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($lowlevel_commitref->getHashes() as $hash) {
|
|
|
|
$dict['hashes'][] = array(
|
|
|
|
'type' => $hash->getHashType(),
|
2014-10-07 15:01:04 +02:00
|
|
|
'value' => $hash->getHashValue(),
|
|
|
|
);
|
2014-09-03 14:49:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-05 21:27:55 +02:00
|
|
|
if ($need_messages && !$bypass_cache) {
|
|
|
|
$dict['message'] = $commit_data->getCommitMessage();
|
2014-04-20 20:55:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$data[$commit->getPHID()] = $dict;
|
2014-01-28 02:14:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$result = array(
|
|
|
|
'data' => $data,
|
|
|
|
'identifierMap' => nonempty($map, (object)array()),
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->addPagerResults($result, $pager);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|