mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
Add get Releeph Requests conduit method
Summary: Added "getrequests" conduit method Test Plan: Open /conduit/method/differential.getrequests/ and try different inputs. Reviewers: edward, epriestley Reviewed By: edward CC: aran, epriestley, Korvin Maniphest Tasks: T3057 Differential Revision: https://secure.phabricator.com/D5788
This commit is contained in:
parent
eabe3a4d33
commit
af220fddc1
4 changed files with 174 additions and 2 deletions
|
@ -197,6 +197,7 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_releeph_Method' => 'applications/releeph/conduit/ConduitAPI_releeph_Method.php',
|
||||
'ConduitAPI_releeph_getbranches_Method' => 'applications/releeph/conduit/ConduitAPI_releeph_getbranches_Method.php',
|
||||
'ConduitAPI_releeph_projectinfo_Method' => 'applications/releeph/conduit/ConduitAPI_releeph_projectinfo_Method.php',
|
||||
'ConduitAPI_releeph_queryrequests_Method' => 'applications/releeph/conduit/ConduitAPI_releeph_queryrequests_Method.php',
|
||||
'ConduitAPI_releeph_request_Method' => 'applications/releeph/conduit/ConduitAPI_releeph_request_Method.php',
|
||||
'ConduitAPI_releephwork_canpush_Method' => 'applications/releeph/conduit/work/ConduitAPI_releephwork_canpush_Method.php',
|
||||
'ConduitAPI_releephwork_getauthorinfo_Method' => 'applications/releeph/conduit/work/ConduitAPI_releephwork_getauthorinfo_Method.php',
|
||||
|
@ -1750,6 +1751,7 @@ phutil_register_library_map(array(
|
|||
'ReleephRequestHeaderListView' => 'applications/releeph/view/request/header/ReleephRequestHeaderListView.php',
|
||||
'ReleephRequestHeaderView' => 'applications/releeph/view/request/header/ReleephRequestHeaderView.php',
|
||||
'ReleephRequestIntentsView' => 'applications/releeph/view/request/ReleephRequestIntentsView.php',
|
||||
'ReleephRequestQuery' => 'applications/releeph/query/ReleephRequestQuery.php',
|
||||
'ReleephRequestReplyHandler' => 'applications/releeph/mail/ReleephRequestReplyHandler.php',
|
||||
'ReleephRequestStatus' => 'applications/releeph/constants/ReleephRequestStatus.php',
|
||||
'ReleephRequestStatusView' => 'applications/releeph/view/request/ReleephRequestStatusView.php',
|
||||
|
@ -1978,6 +1980,7 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_releeph_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_releeph_getbranches_Method' => 'ConduitAPI_releeph_Method',
|
||||
'ConduitAPI_releeph_projectinfo_Method' => 'ConduitAPI_releeph_Method',
|
||||
'ConduitAPI_releeph_queryrequests_Method' => 'ConduitAPI_releeph_Method',
|
||||
'ConduitAPI_releeph_request_Method' => 'ConduitAPI_releeph_Method',
|
||||
'ConduitAPI_releephwork_canpush_Method' => 'ConduitAPI_releeph_Method',
|
||||
'ConduitAPI_releephwork_getauthorinfo_Method' => 'ConduitAPI_releeph_Method',
|
||||
|
@ -3510,7 +3513,11 @@ phutil_register_library_map(array(
|
|||
'ReleephProjectView' => 'AphrontView',
|
||||
'ReleephProjectViewController' => 'ReleephController',
|
||||
'ReleephReasonFieldSpecification' => 'ReleephFieldSpecification',
|
||||
'ReleephRequest' => 'ReleephDAO',
|
||||
'ReleephRequest' =>
|
||||
array(
|
||||
0 => 'ReleephDAO',
|
||||
1 => 'PhabricatorPolicyInterface',
|
||||
),
|
||||
'ReleephRequestActionController' => 'ReleephController',
|
||||
'ReleephRequestCommentController' => 'ReleephController',
|
||||
'ReleephRequestDifferentialCreateController' => 'ReleephController',
|
||||
|
@ -3520,6 +3527,7 @@ phutil_register_library_map(array(
|
|||
'ReleephRequestHeaderListView' => 'AphrontView',
|
||||
'ReleephRequestHeaderView' => 'AphrontView',
|
||||
'ReleephRequestIntentsView' => 'AphrontView',
|
||||
'ReleephRequestQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'ReleephRequestReplyHandler' => 'PhabricatorMailReplyHandler',
|
||||
'ReleephRequestStatusView' => 'AphrontView',
|
||||
'ReleephRequestTransaction' => 'PhabricatorApplicationTransaction',
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
final class ConduitAPI_releeph_queryrequests_Method
|
||||
extends ConduitAPI_releeph_Method {
|
||||
|
||||
public function getMethodDescription() {
|
||||
return
|
||||
"Return information about all Releeph requests linked to the given ids.";
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'revisionPHIDs' => 'optional list<phid>',
|
||||
'requestedCommitPHIDs' => 'optional list<phid>'
|
||||
);
|
||||
}
|
||||
|
||||
public function defineReturnType() {
|
||||
return 'dict<string, wild>';
|
||||
}
|
||||
|
||||
public function defineErrorTypes() {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $conduit_request) {
|
||||
$revision_phids = $conduit_request->getValue('revisionPHIDs');
|
||||
$requested_commit_phids =
|
||||
$conduit_request->getValue('requestedCommitPHIDs');
|
||||
$result = array();
|
||||
|
||||
if (!$revision_phids && !$requested_commit_phids) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$query = new ReleephRequestQuery();
|
||||
$query->setViewer($conduit_request->getUser());
|
||||
|
||||
if ($revision_phids) {
|
||||
$query->withRevisionPHIDs($revision_phids);
|
||||
} else if ($requested_commit_phids) {
|
||||
$query->withRequestedCommitPHIDs($requested_commit_phids);
|
||||
}
|
||||
|
||||
$releephRequests = $query->execute();
|
||||
|
||||
foreach ($releephRequests as $releephRequest) {
|
||||
$branch = $releephRequest->loadReleephBranch();
|
||||
$request_commit_phid = $releephRequest->getRequestCommitPHID();
|
||||
$revisionPHID =
|
||||
$query->getRevisionPHID($request_commit_phid);
|
||||
$status = $releephRequest->getStatus();
|
||||
$statusName = ReleephRequestStatus::getStatusDescriptionFor($status);
|
||||
$url = PhabricatorEnv::getProductionURI('/RQ'.$releephRequest->getID());
|
||||
|
||||
$result[] = array(
|
||||
'branchBasename' => $branch->getBasename(),
|
||||
'branchSymbolic' => $branch->getSymbolicName(),
|
||||
'requestID' => $releephRequest->getID(),
|
||||
'revisionPHID' => $revisionPHID,
|
||||
'status' => $status,
|
||||
'statusName' => $statusName,
|
||||
'url' => $url,
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
71
src/applications/releeph/query/ReleephRequestQuery.php
Normal file
71
src/applications/releeph/query/ReleephRequestQuery.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
final class ReleephRequestQuery
|
||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||
|
||||
private $requestedCommitPHIDs;
|
||||
private $commitToRevMap;
|
||||
|
||||
public function getRevisionPHID($commit_phid) {
|
||||
if ($this->commitToRevMap) {
|
||||
return idx($this->commitToRevMap, $commit_phid, null);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function withRequestedCommitPHIDs(array $requested_commit_phids) {
|
||||
$this->requestedCommitPHIDs = $requested_commit_phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withRevisionPHIDs(array $revision_phids) {
|
||||
$type = PhabricatorEdgeConfig::TYPE_DREV_HAS_COMMIT;
|
||||
|
||||
$edges = id(new PhabricatorEdgeQuery())
|
||||
->withSourcePHIDs($revision_phids)
|
||||
->withEdgeTypes(array($type))
|
||||
->execute();
|
||||
|
||||
$this->commitToRevMap = array();
|
||||
|
||||
foreach ($edges as $revision_phid => $edge) {
|
||||
foreach ($edge[$type] as $commitPHID => $item) {
|
||||
$this->commitToRevMap[$commitPHID] = $revision_phid;
|
||||
}
|
||||
}
|
||||
|
||||
$this->requestedCommitPHIDs = array_keys($this->commitToRevMap);
|
||||
}
|
||||
|
||||
public function loadPage() {
|
||||
$table = new ReleephRequest();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
||||
$data = queryfx_all(
|
||||
$conn_r,
|
||||
'SELECT * FROM %T %Q %Q %Q',
|
||||
$table->getTableName(),
|
||||
$this->buildWhereClause($conn_r),
|
||||
$this->buildOrderClause($conn_r),
|
||||
$this->buildLimitClause($conn_r));
|
||||
|
||||
return $table->loadAllFromArray($data);
|
||||
}
|
||||
|
||||
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
|
||||
if ($this->requestedCommitPHIDs) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'requestCommitPHID IN (%Ls)',
|
||||
$this->requestedCommitPHIDs);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class ReleephRequest extends ReleephDAO {
|
||||
final class ReleephRequest extends ReleephDAO
|
||||
implements PhabricatorPolicyInterface {
|
||||
|
||||
protected $phid;
|
||||
protected $branchID;
|
||||
|
@ -285,4 +286,26 @@ final class ReleephRequest extends ReleephDAO {
|
|||
throw new Exception('`status` is now deprecated!');
|
||||
}
|
||||
|
||||
/* -( Make magic Lisk methods private )------------------------------------ */
|
||||
|
||||
private function setUserIntents(array $ar) {
|
||||
return parent::setUserIntents($ar);
|
||||
}
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
public function getCapabilities() {
|
||||
return array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
);
|
||||
}
|
||||
|
||||
public function getPolicy($capability) {
|
||||
return PhabricatorPolicies::POLICY_USER;
|
||||
}
|
||||
|
||||
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue