mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-25 23:10:57 +01:00
Add differential.query conduit method
Summary: Created a differential.query conduit method that is built on top of DifferentialRevisionQuery. I also added support for querying by author, ccs, and reviewers to DifferentialRevisionQuery, so feature parity can be brought up to match differential.find and its backing class DifferentialRevisionListData. Test Plan: Tried a few calls to the conduit call using the web interface, and got back reasonable looking data. Reviewers: epriestley, jungejason, btrahan Reviewed By: epriestley CC: aran, nh, epriestley Differential Revision: 1158
This commit is contained in:
parent
519a443eba
commit
8f5e28bf59
4 changed files with 302 additions and 0 deletions
|
@ -107,6 +107,7 @@ phutil_register_library_map(array(
|
||||||
'ConduitAPI_differential_getrevisionfeedback_Method' => 'applications/conduit/method/differential/getrevisionfeedback',
|
'ConduitAPI_differential_getrevisionfeedback_Method' => 'applications/conduit/method/differential/getrevisionfeedback',
|
||||||
'ConduitAPI_differential_markcommitted_Method' => 'applications/conduit/method/differential/markcommitted',
|
'ConduitAPI_differential_markcommitted_Method' => 'applications/conduit/method/differential/markcommitted',
|
||||||
'ConduitAPI_differential_parsecommitmessage_Method' => 'applications/conduit/method/differential/parsecommitmessage',
|
'ConduitAPI_differential_parsecommitmessage_Method' => 'applications/conduit/method/differential/parsecommitmessage',
|
||||||
|
'ConduitAPI_differential_query_Method' => 'applications/conduit/method/differential/query',
|
||||||
'ConduitAPI_differential_setdiffproperty_Method' => 'applications/conduit/method/differential/setdiffproperty',
|
'ConduitAPI_differential_setdiffproperty_Method' => 'applications/conduit/method/differential/setdiffproperty',
|
||||||
'ConduitAPI_differential_updaterevision_Method' => 'applications/conduit/method/differential/updaterevision',
|
'ConduitAPI_differential_updaterevision_Method' => 'applications/conduit/method/differential/updaterevision',
|
||||||
'ConduitAPI_differential_updatetaskrevisionassoc_Method' => 'applications/conduit/method/differential/updatetaskrevisionassoc',
|
'ConduitAPI_differential_updatetaskrevisionassoc_Method' => 'applications/conduit/method/differential/updatetaskrevisionassoc',
|
||||||
|
@ -834,6 +835,7 @@ phutil_register_library_map(array(
|
||||||
'ConduitAPI_differential_getrevisionfeedback_Method' => 'ConduitAPIMethod',
|
'ConduitAPI_differential_getrevisionfeedback_Method' => 'ConduitAPIMethod',
|
||||||
'ConduitAPI_differential_markcommitted_Method' => 'ConduitAPIMethod',
|
'ConduitAPI_differential_markcommitted_Method' => 'ConduitAPIMethod',
|
||||||
'ConduitAPI_differential_parsecommitmessage_Method' => 'ConduitAPIMethod',
|
'ConduitAPI_differential_parsecommitmessage_Method' => 'ConduitAPIMethod',
|
||||||
|
'ConduitAPI_differential_query_Method' => 'ConduitAPIMethod',
|
||||||
'ConduitAPI_differential_setdiffproperty_Method' => 'ConduitAPIMethod',
|
'ConduitAPI_differential_setdiffproperty_Method' => 'ConduitAPIMethod',
|
||||||
'ConduitAPI_differential_updaterevision_Method' => 'ConduitAPIMethod',
|
'ConduitAPI_differential_updaterevision_Method' => 'ConduitAPIMethod',
|
||||||
'ConduitAPI_differential_updatetaskrevisionassoc_Method' => 'ConduitAPIMethod',
|
'ConduitAPI_differential_updatetaskrevisionassoc_Method' => 'ConduitAPIMethod',
|
||||||
|
|
|
@ -0,0 +1,144 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2011 Facebook, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group conduit
|
||||||
|
*/
|
||||||
|
class ConduitAPI_differential_query_Method extends ConduitAPIMethod {
|
||||||
|
|
||||||
|
public function getMethodDescription() {
|
||||||
|
return "Query Differential revisions which match certain criteria.";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineParamTypes() {
|
||||||
|
$status_types = array(
|
||||||
|
DifferentialRevisionQuery::STATUS_ANY,
|
||||||
|
DifferentialRevisionQuery::STATUS_OPEN,
|
||||||
|
);
|
||||||
|
$status_types = implode(', ', $status_types);
|
||||||
|
|
||||||
|
$order_types = array(
|
||||||
|
DifferentialRevisionQuery::ORDER_MODIFIED,
|
||||||
|
DifferentialRevisionQuery::ORDER_CREATED,
|
||||||
|
);
|
||||||
|
$order_types = implode(', ', $order_types);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'author' => 'optional phid',
|
||||||
|
'ccs' => 'optional list<phid>',
|
||||||
|
'reviewers' => 'optional list<phid>',
|
||||||
|
'paths' => 'optional list<string>',
|
||||||
|
'status' => 'optional enum<'.$status_types.'>',
|
||||||
|
'order' => 'optional enum<'.$order_types.'>',
|
||||||
|
'limit' => 'optional uint',
|
||||||
|
'offset' => 'optional uint',
|
||||||
|
'ids' => 'optional list<uint>',
|
||||||
|
'phids' => 'optional list<phid>',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineReturnType() {
|
||||||
|
return 'list<dict>';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineErrorTypes() {
|
||||||
|
return array(
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(ConduitAPIRequest $request) {
|
||||||
|
$author = $request->getValue('author');
|
||||||
|
$ccs = $request->getValue('ccs');
|
||||||
|
$reviewers = $request->getValue('reviewers');
|
||||||
|
$paths = $request->getValue('paths');
|
||||||
|
$status = $request->getValue('status');
|
||||||
|
$order = $request->getValue('order');
|
||||||
|
$limit = $request->getValue('limit');
|
||||||
|
$offset = $request->getValue('offset');
|
||||||
|
$ids = $request->getValue('ids');
|
||||||
|
$phids = $request->getValue('phids');
|
||||||
|
|
||||||
|
$query = new DifferentialRevisionQuery();
|
||||||
|
$query->withAuthor($author);
|
||||||
|
if ($ccs) {
|
||||||
|
$query->withCCs($ccs);
|
||||||
|
}
|
||||||
|
if ($reviewers) {
|
||||||
|
$query->withReviewers($reviewers);
|
||||||
|
}
|
||||||
|
if ($paths) {
|
||||||
|
foreach ($paths as $path) {
|
||||||
|
$query->withPath($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
$revisions = $query->execute();
|
||||||
|
|
||||||
|
$results = array();
|
||||||
|
foreach ($revisions as $revision) {
|
||||||
|
$diff = $revision->loadActiveDiff();
|
||||||
|
if (!$diff) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$revision->loadRelationships();
|
||||||
|
|
||||||
|
$id = $revision->getID();
|
||||||
|
$results[] = array(
|
||||||
|
'id' => $id,
|
||||||
|
'phid' => $revision->getPHID(),
|
||||||
|
'title' => $revision->getTitle(),
|
||||||
|
'uri' => PhabricatorEnv::getProductionURI('/D'.$id),
|
||||||
|
'dateCreated' => $revision->getDateCreated(),
|
||||||
|
'authorPHID' => $revision->getAuthorPHID(),
|
||||||
|
'status' => $revision->getStatus(),
|
||||||
|
'statusName' => DifferentialRevisionStatus::getNameForRevisionStatus(
|
||||||
|
$revision->getStatus()),
|
||||||
|
'sourcePath' => $diff->getSourcePath(),
|
||||||
|
'summary' => $revision->getSummary(),
|
||||||
|
'testPlan' => $revision->getTestPlan(),
|
||||||
|
'lineCount' => $revision->getLineCount(),
|
||||||
|
'diffs' => array_keys($revision->loadDiffs()),
|
||||||
|
'commits' => $revision->loadCommitPHIDs(),
|
||||||
|
'reviewers' => array_values($revision->getReviewers()),
|
||||||
|
'ccs' => array_values($revision->getCCPHIDs()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is automatically generated. Lint this module to rebuild it.
|
||||||
|
* @generated
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_module('phabricator', 'applications/conduit/method/base');
|
||||||
|
phutil_require_module('phabricator', 'applications/differential/constants/revisionstatus');
|
||||||
|
phutil_require_module('phabricator', 'applications/differential/query/revision');
|
||||||
|
phutil_require_module('phabricator', 'infrastructure/env');
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_source('ConduitAPI_differential_query_Method.php');
|
|
@ -38,6 +38,12 @@ final class DifferentialRevisionQuery {
|
||||||
const STATUS_ANY = 'status-any';
|
const STATUS_ANY = 'status-any';
|
||||||
const STATUS_OPEN = 'status-open';
|
const STATUS_OPEN = 'status-open';
|
||||||
|
|
||||||
|
private $author = null;
|
||||||
|
private $ccs = array();
|
||||||
|
private $reviewers = array();
|
||||||
|
private $revIDs = array();
|
||||||
|
private $phids = array();
|
||||||
|
|
||||||
private $order = 'order-modified';
|
private $order = 'order-modified';
|
||||||
const ORDER_MODIFIED = 'order-modified';
|
const ORDER_MODIFIED = 'order-modified';
|
||||||
const ORDER_CREATED = 'order-created';
|
const ORDER_CREATED = 'order-created';
|
||||||
|
@ -77,6 +83,74 @@ final class DifferentialRevisionQuery {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter results to revisions authored by a given PHID. If an invalid PHID is
|
||||||
|
* provided, no results will be returned.
|
||||||
|
*
|
||||||
|
* @param phid Author PHID
|
||||||
|
* @return this
|
||||||
|
* @task config
|
||||||
|
*/
|
||||||
|
public function withAuthor($author_phid) {
|
||||||
|
$this->author = $author_phid;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter results to revisions which CC all of the listed people. Calling this
|
||||||
|
* function will clear anything set by previous calls to withCCs or withCC.
|
||||||
|
*
|
||||||
|
* @param array List of PHIDs of subscribers
|
||||||
|
* @return this
|
||||||
|
* @task config
|
||||||
|
*/
|
||||||
|
public function withCCs(array $cc_phids) {
|
||||||
|
$this->ccs = $cc_phids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a PHID to the list of CCs that must be present on the revision. Calling
|
||||||
|
* this multiple times will continue to add CC PHID constraints, and will not
|
||||||
|
* clear anything set by previous calls to withCCs or withCC.
|
||||||
|
*
|
||||||
|
* @param phid CC PHID
|
||||||
|
* @return this
|
||||||
|
* @task config
|
||||||
|
*/
|
||||||
|
public function withCC($cc) {
|
||||||
|
$this->ccs[] = $cc;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter results to revisions that have all of the provided PHIDs as
|
||||||
|
* reviewers. Calling this function will clear anything set by previous calls
|
||||||
|
* to withReviewers or withReviewer.
|
||||||
|
*
|
||||||
|
* @param array List of PHIDs of reviewers
|
||||||
|
* @return this
|
||||||
|
* @task config
|
||||||
|
*/
|
||||||
|
public function withReviewers(array $reviewer_phids) {
|
||||||
|
$this->reviewers = $reviewer_phids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a PHID to the list of reviewers that must be present on the revision.
|
||||||
|
* Calling this multiple times will continue to add reviewer PHID constraints,
|
||||||
|
* and will not clear anything set by previous calls to withReviewers or
|
||||||
|
* withReviewer.
|
||||||
|
*
|
||||||
|
* @param phid reviewer PHID
|
||||||
|
* @return this
|
||||||
|
* @task config
|
||||||
|
*/
|
||||||
|
public function withReviewer($reviewer) {
|
||||||
|
$this->reviewers[] = $reviewer;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter results to revisions with a given status. Provide a class constant,
|
* Filter results to revisions with a given status. Provide a class constant,
|
||||||
|
@ -92,6 +166,32 @@ final class DifferentialRevisionQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter results to only return revisions whose ids are in the given set.
|
||||||
|
*
|
||||||
|
* @param array List of revision ids
|
||||||
|
* @return this
|
||||||
|
* @task config
|
||||||
|
*/
|
||||||
|
public function withIDs(array $ids) {
|
||||||
|
$this->revIDs = $ids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter results to only return revisions whose PHIDs are in the given set.
|
||||||
|
*
|
||||||
|
* @param array List of revision PHIDs
|
||||||
|
* @return this
|
||||||
|
* @task config
|
||||||
|
*/
|
||||||
|
public function withPHIDs(array $phids) {
|
||||||
|
$this->phids = $phids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set result ordering. Provide a class constant, such as
|
* Set result ordering. Provide a class constant, such as
|
||||||
* ##DifferentialRevisionQuery::ORDER_CREATED##.
|
* ##DifferentialRevisionQuery::ORDER_CREATED##.
|
||||||
|
@ -247,6 +347,47 @@ final class DifferentialRevisionQuery {
|
||||||
$where[] = $path_clauses;
|
$where[] = $path_clauses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->author) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'authorPHID = %s',
|
||||||
|
$this->author);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->ccs as $cc) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'id IN '.
|
||||||
|
'(SELECT revisionID FROM %T WHERE relation = %s AND objectPHID = %s)',
|
||||||
|
DifferentialRevision::RELATIONSHIP_TABLE,
|
||||||
|
DifferentialRevision::RELATION_SUBSCRIBED,
|
||||||
|
$cc);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->reviewers as $reviewer) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'id IN '.
|
||||||
|
'(SELECT revisionID FROM %T WHERE relation = %s AND objectPHID = %s)',
|
||||||
|
DifferentialRevision::RELATIONSHIP_TABLE,
|
||||||
|
DifferentialRevision::RELATION_REVIEWER,
|
||||||
|
$reviewer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->revIDs) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'id IN (%Ld)',
|
||||||
|
$this->revIDs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->phids) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'phid IN (%Ls)',
|
||||||
|
$this->phids);
|
||||||
|
}
|
||||||
|
|
||||||
switch ($this->status) {
|
switch ($this->status) {
|
||||||
case self::STATUS_ANY:
|
case self::STATUS_ANY:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue