2011-12-02 01:57:06 +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 DifferentialQueryConduitAPIMethod
|
|
|
|
extends DifferentialConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'differential.query';
|
|
|
|
}
|
2011-12-02 01:57:06 +01:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
2014-06-09 20:36:49 +02:00
|
|
|
return 'Query Differential revisions which match certain criteria.';
|
2011-12-02 01:57:06 +01:00
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineParamTypes() {
|
2012-01-10 20:39:11 +01:00
|
|
|
$hash_types = ArcanistDifferentialRevisionHash::getTypes();
|
2014-05-15 06:59:03 +02:00
|
|
|
$hash_const = $this->formatStringConstants($hash_types);
|
2012-01-04 06:08:12 +01:00
|
|
|
|
2011-12-02 01:57:06 +01:00
|
|
|
$status_types = array(
|
|
|
|
DifferentialRevisionQuery::STATUS_ANY,
|
|
|
|
DifferentialRevisionQuery::STATUS_OPEN,
|
2012-01-25 23:50:34 +01:00
|
|
|
DifferentialRevisionQuery::STATUS_ACCEPTED,
|
2012-04-24 02:40:57 +02:00
|
|
|
DifferentialRevisionQuery::STATUS_CLOSED,
|
2011-12-02 01:57:06 +01:00
|
|
|
);
|
2014-05-15 06:59:03 +02:00
|
|
|
$status_const = $this->formatStringConstants($status_types);
|
2011-12-02 01:57:06 +01:00
|
|
|
|
|
|
|
$order_types = array(
|
|
|
|
DifferentialRevisionQuery::ORDER_MODIFIED,
|
|
|
|
DifferentialRevisionQuery::ORDER_CREATED,
|
|
|
|
);
|
2014-05-15 06:59:03 +02:00
|
|
|
$order_const = $this->formatStringConstants($order_types);
|
2011-12-02 01:57:06 +01:00
|
|
|
|
|
|
|
return array(
|
2011-12-07 17:30:49 +01:00
|
|
|
'authors' => 'optional list<phid>',
|
|
|
|
'ccs' => 'optional list<phid>',
|
|
|
|
'reviewers' => 'optional list<phid>',
|
2012-06-19 02:43:22 +02:00
|
|
|
'paths' => 'optional list<pair<callsign, path>>',
|
2014-05-15 06:59:03 +02:00
|
|
|
'commitHashes' => 'optional list<pair<'.$hash_const.', string>>',
|
|
|
|
'status' => 'optional '.$status_const,
|
|
|
|
'order' => 'optional '.$order_const,
|
2011-12-07 17:30:49 +01:00
|
|
|
'limit' => 'optional uint',
|
|
|
|
'offset' => 'optional uint',
|
|
|
|
'ids' => 'optional list<uint>',
|
|
|
|
'phids' => 'optional list<phid>',
|
|
|
|
'subscribers' => 'optional list<phid>',
|
|
|
|
'responsibleUsers' => 'optional list<phid>',
|
2012-01-24 17:31:45 +01:00
|
|
|
'branches' => 'optional list<string>',
|
2011-12-02 01:57:06 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineReturnType() {
|
2011-12-02 01:57:06 +01:00
|
|
|
return 'list<dict>';
|
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineErrorTypes() {
|
2011-12-02 01:57:06 +01:00
|
|
|
return array(
|
2012-01-04 06:08:12 +01:00
|
|
|
'ERR-INVALID-PARAMETER' => 'Missing or malformed parameter.',
|
2011-12-02 01:57:06 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
2011-12-07 17:30:49 +01:00
|
|
|
$authors = $request->getValue('authors');
|
|
|
|
$ccs = $request->getValue('ccs');
|
|
|
|
$reviewers = $request->getValue('reviewers');
|
|
|
|
$status = $request->getValue('status');
|
|
|
|
$order = $request->getValue('order');
|
2012-06-19 02:43:22 +02:00
|
|
|
$path_pairs = $request->getValue('paths');
|
2012-01-04 06:08:12 +01:00
|
|
|
$commit_hashes = $request->getValue('commitHashes');
|
2011-12-07 17:30:49 +01:00
|
|
|
$limit = $request->getValue('limit');
|
|
|
|
$offset = $request->getValue('offset');
|
|
|
|
$ids = $request->getValue('ids');
|
|
|
|
$phids = $request->getValue('phids');
|
|
|
|
$subscribers = $request->getValue('subscribers');
|
|
|
|
$responsible_users = $request->getValue('responsibleUsers');
|
2012-01-24 17:31:45 +01:00
|
|
|
$branches = $request->getValue('branches');
|
2011-12-02 01:57:06 +01:00
|
|
|
|
2013-07-01 21:38:27 +02:00
|
|
|
$query = id(new DifferentialRevisionQuery())
|
|
|
|
->setViewer($request->getUser());
|
|
|
|
|
2011-12-07 17:30:49 +01:00
|
|
|
if ($authors) {
|
|
|
|
$query->withAuthors($authors);
|
|
|
|
}
|
2011-12-02 01:57:06 +01:00
|
|
|
if ($ccs) {
|
|
|
|
$query->withCCs($ccs);
|
|
|
|
}
|
|
|
|
if ($reviewers) {
|
|
|
|
$query->withReviewers($reviewers);
|
|
|
|
}
|
2011-12-07 17:30:49 +01:00
|
|
|
|
2012-06-19 02:43:22 +02:00
|
|
|
if ($path_pairs) {
|
|
|
|
$paths = array();
|
|
|
|
foreach ($path_pairs as $pair) {
|
|
|
|
list($callsign, $path) = $pair;
|
|
|
|
$paths[] = $path;
|
|
|
|
}
|
2011-12-07 17:30:49 +01:00
|
|
|
|
2012-06-19 02:43:22 +02:00
|
|
|
$path_map = id(new DiffusionPathIDQuery($paths))->loadPathIDs();
|
|
|
|
if (count($path_map) != count($paths)) {
|
|
|
|
$unknown_paths = array();
|
|
|
|
foreach ($paths as $p) {
|
|
|
|
if (!idx($path_map, $p)) {
|
|
|
|
$unknown_paths[] = $p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw id(new ConduitException('ERR-INVALID-PARAMETER'))
|
|
|
|
->setErrorDescription(
|
|
|
|
'Unknown paths: '.implode(', ', $unknown_paths));
|
|
|
|
}
|
|
|
|
|
|
|
|
$repos = array();
|
|
|
|
foreach ($path_pairs as $pair) {
|
|
|
|
list($callsign, $path) = $pair;
|
|
|
|
if (!idx($repos, $callsign)) {
|
2013-09-26 01:54:48 +02:00
|
|
|
$repos[$callsign] = id(new PhabricatorRepositoryQuery())
|
|
|
|
->setViewer($request->getUser())
|
|
|
|
->withCallsigns(array($callsign))
|
|
|
|
->executeOne();
|
2012-06-19 02:43:22 +02:00
|
|
|
|
|
|
|
if (!$repos[$callsign]) {
|
|
|
|
throw id(new ConduitException('ERR-INVALID-PARAMETER'))
|
|
|
|
->setErrorDescription(
|
|
|
|
'Unknown repo callsign: '.$callsign);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$repo = $repos[$callsign];
|
|
|
|
|
|
|
|
$query->withPath($repo->getID(), idx($path_map, $path));
|
2011-12-02 01:57:06 +01:00
|
|
|
}
|
|
|
|
}
|
2012-06-19 02:43:22 +02:00
|
|
|
|
2012-01-04 06:08:12 +01:00
|
|
|
if ($commit_hashes) {
|
2012-01-10 20:39:11 +01:00
|
|
|
$hash_types = ArcanistDifferentialRevisionHash::getTypes();
|
2012-01-04 06:08:12 +01:00
|
|
|
foreach ($commit_hashes as $info) {
|
|
|
|
list($type, $hash) = $info;
|
|
|
|
if (empty($type) ||
|
|
|
|
!in_array($type, $hash_types) ||
|
|
|
|
empty($hash)) {
|
|
|
|
throw new ConduitException('ERR-INVALID-PARAMETER');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$query->withCommitHashes($commit_hashes);
|
|
|
|
}
|
|
|
|
|
2011-12-02 01:57:06 +01:00
|
|
|
if ($status) {
|
|
|
|
$query->withStatus($status);
|
|
|
|
}
|
|
|
|
if ($order) {
|
|
|
|
$query->setOrder($order);
|
|
|
|
}
|
|
|
|
if ($limit) {
|
|
|
|
$query->setLimit($limit);
|
|
|
|
}
|
|
|
|
if ($offset) {
|
|
|
|
$query->setOffset($offset);
|
|
|
|
}
|
|
|
|
if ($ids) {
|
|
|
|
$query->withIDs($ids);
|
|
|
|
}
|
|
|
|
if ($phids) {
|
|
|
|
$query->withPHIDs($phids);
|
|
|
|
}
|
2011-12-07 17:30:49 +01:00
|
|
|
if ($responsible_users) {
|
|
|
|
$query->withResponsibleUsers($responsible_users);
|
|
|
|
}
|
|
|
|
if ($subscribers) {
|
2014-02-12 17:53:40 +01:00
|
|
|
$query->withCCs($subscribers);
|
2011-12-07 17:30:49 +01:00
|
|
|
}
|
2012-01-24 17:31:45 +01:00
|
|
|
if ($branches) {
|
|
|
|
$query->withBranches($branches);
|
|
|
|
}
|
2011-12-02 01:57:06 +01:00
|
|
|
|
2011-12-21 02:05:52 +01:00
|
|
|
$query->needRelationships(true);
|
|
|
|
$query->needCommitPHIDs(true);
|
|
|
|
$query->needDiffIDs(true);
|
|
|
|
$query->needActiveDiffs(true);
|
2012-06-26 18:07:52 +02:00
|
|
|
$query->needHashes(true);
|
2011-12-21 02:05:52 +01:00
|
|
|
|
2011-12-02 01:57:06 +01:00
|
|
|
$revisions = $query->execute();
|
|
|
|
|
2014-03-09 19:23:55 +01:00
|
|
|
$field_data = $this->loadCustomFieldsForRevisions(
|
|
|
|
$request->getUser(),
|
|
|
|
$revisions);
|
|
|
|
|
2011-12-02 01:57:06 +01:00
|
|
|
$results = array();
|
|
|
|
foreach ($revisions as $revision) {
|
2011-12-21 02:05:52 +01:00
|
|
|
$diff = $revision->getActiveDiff();
|
2011-12-02 01:57:06 +01:00
|
|
|
if (!$diff) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = $revision->getID();
|
2014-03-09 19:23:55 +01:00
|
|
|
$phid = $revision->getPHID();
|
|
|
|
|
2012-02-06 21:14:07 +01:00
|
|
|
$result = array(
|
2013-11-12 00:01:21 +01:00
|
|
|
'id' => $id,
|
2014-03-09 19:23:55 +01:00
|
|
|
'phid' => $phid,
|
2013-11-12 00:01:21 +01:00
|
|
|
'title' => $revision->getTitle(),
|
|
|
|
'uri' => PhabricatorEnv::getProductionURI('/D'.$id),
|
|
|
|
'dateCreated' => $revision->getDateCreated(),
|
|
|
|
'dateModified' => $revision->getDateModified(),
|
|
|
|
'authorPHID' => $revision->getAuthorPHID(),
|
|
|
|
'status' => $revision->getStatus(),
|
|
|
|
'statusName' =>
|
2012-01-10 20:39:11 +01:00
|
|
|
ArcanistDifferentialRevisionStatus::getNameForRevisionStatus(
|
|
|
|
$revision->getStatus()),
|
2013-11-12 00:01:21 +01:00
|
|
|
'branch' => $diff->getBranch(),
|
|
|
|
'summary' => $revision->getSummary(),
|
|
|
|
'testPlan' => $revision->getTestPlan(),
|
|
|
|
'lineCount' => $revision->getLineCount(),
|
2014-04-18 01:01:27 +02:00
|
|
|
'activeDiffPHID' => $diff->getPHID(),
|
2013-11-12 00:01:21 +01:00
|
|
|
'diffs' => $revision->getDiffIDs(),
|
|
|
|
'commits' => $revision->getCommitPHIDs(),
|
|
|
|
'reviewers' => array_values($revision->getReviewers()),
|
|
|
|
'ccs' => array_values($revision->getCCPHIDs()),
|
|
|
|
'hashes' => $revision->getHashes(),
|
2014-03-09 19:23:55 +01:00
|
|
|
'auxiliary' => idx($field_data, $phid, array()),
|
2014-07-15 00:00:02 +02:00
|
|
|
'repositoryPHID' => $diff->getRepositoryPHID(),
|
2011-12-02 01:57:06 +01:00
|
|
|
);
|
2012-02-06 21:14:07 +01:00
|
|
|
|
|
|
|
// TODO: This is a hacky way to put permissions on this field until we
|
|
|
|
// have first-class support, see T838.
|
|
|
|
if ($revision->getAuthorPHID() == $request->getUser()->getPHID()) {
|
|
|
|
$result['sourcePath'] = $diff->getSourcePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
$results[] = $result;
|
2011-12-02 01:57:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
2013-03-05 14:58:04 +01:00
|
|
|
|
2011-12-02 01:57:06 +01:00
|
|
|
}
|