mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Add modern releeph.queryproducts and releeph.querybranches
Summary: Ref T3662. Ref T3549. These methods are pretty conservative for now, but get the structure in place. Also do a bunch more project -> product stuff. Test Plan: Made calls to both methods, browsed around the UI a fair amount. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T3549, T3662 Differential Revision: https://secure.phabricator.com/D8816
This commit is contained in:
parent
f5cc5c122a
commit
6e6ad2cfcf
11 changed files with 224 additions and 29 deletions
|
@ -230,6 +230,8 @@ 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_querybranches_Method' => 'applications/releeph/conduit/ConduitAPI_releeph_querybranches_Method.php',
|
||||
'ConduitAPI_releeph_queryproducts_Method' => 'applications/releeph/conduit/ConduitAPI_releeph_queryproducts_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',
|
||||
|
@ -2816,6 +2818,8 @@ 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_querybranches_Method' => 'ConduitAPI_releeph_Method',
|
||||
'ConduitAPI_releeph_queryproducts_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',
|
||||
|
|
|
@ -40,7 +40,7 @@ final class PhabricatorApplicationReleeph extends PhabricatorApplication {
|
|||
|
||||
'/releeph/' => array(
|
||||
'' => 'ReleephProductListController',
|
||||
'project/' => array(
|
||||
'(?:product|project)/' => array(
|
||||
'(?:query/(?P<queryKey>[^/]+)/)?' => 'ReleephProductListController',
|
||||
'create/' => 'ReleephProductCreateController',
|
||||
'(?P<projectID>[1-9]\d*)/' => array(
|
||||
|
|
|
@ -2,6 +2,14 @@
|
|||
|
||||
abstract class ConduitAPI_releeph_Method extends ConduitAPIMethod {
|
||||
|
||||
public function getMethodStatus() {
|
||||
return self::METHOD_STATUS_UNSTABLE;
|
||||
}
|
||||
|
||||
public function getMethodStatusDescription() {
|
||||
return pht('All Releeph methods are subject to abrupt change.');
|
||||
}
|
||||
|
||||
public function getApplication() {
|
||||
return PhabricatorApplication::getByClass('PhabricatorApplicationReleeph');
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
final class ConduitAPI_releeph_querybranches_Method
|
||||
extends ConduitAPI_releeph_Method {
|
||||
|
||||
public function getMethodDescription() {
|
||||
return pht('Query information about Releeph branches.');
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'ids' => 'optional list<id>',
|
||||
'phids' => 'optional list<phid>',
|
||||
'productPHIDs' => 'optional list<phid>',
|
||||
) + $this->getPagerParamTypes();
|
||||
}
|
||||
|
||||
public function defineReturnType() {
|
||||
return 'query-results';
|
||||
}
|
||||
|
||||
public function defineErrorTypes() {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
$viewer = $request->getUser();
|
||||
|
||||
$query = id(new ReleephBranchQuery())
|
||||
->setViewer($viewer);
|
||||
|
||||
$ids = $request->getValue('ids');
|
||||
if ($ids !== null) {
|
||||
$query->withIDs($ids);
|
||||
}
|
||||
|
||||
$phids = $request->getValue('phids');
|
||||
if ($phids !== null) {
|
||||
$query->withPHIDs($phids);
|
||||
}
|
||||
|
||||
$product_phids = $request->getValue('productPHIDs');
|
||||
if ($product_phids !== null) {
|
||||
$query->withProductPHIDs($product_phids);
|
||||
}
|
||||
|
||||
$pager = $this->newPager($request);
|
||||
$branches = $query->executeWithCursorPager($pager);
|
||||
|
||||
$data = array();
|
||||
foreach ($branches as $branch) {
|
||||
$id = $branch->getID();
|
||||
|
||||
$uri = '/releeph/branch/'.$id.'/';
|
||||
$uri = PhabricatorEnv::getProductionURI($uri);
|
||||
|
||||
$data[] = array(
|
||||
'id' => $id,
|
||||
'phid' => $branch->getPHID(),
|
||||
'uri' => $uri,
|
||||
'name' => $branch->getName(),
|
||||
'productPHID' => $branch->getProduct()->getPHID(),
|
||||
);
|
||||
}
|
||||
|
||||
return $this->addPagerResults(
|
||||
array(
|
||||
'data' => $data,
|
||||
),
|
||||
$pager);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
final class ConduitAPI_releeph_queryproducts_Method
|
||||
extends ConduitAPI_releeph_Method {
|
||||
|
||||
public function getMethodDescription() {
|
||||
return pht('Query information about Releeph products.');
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'ids' => 'optional list<id>',
|
||||
'phids' => 'optional list<phid>',
|
||||
'repositoryPHIDs' => 'optional list<phid>',
|
||||
'isActive' => 'optional bool',
|
||||
) + $this->getPagerParamTypes();
|
||||
}
|
||||
|
||||
public function defineReturnType() {
|
||||
return 'query-results';
|
||||
}
|
||||
|
||||
public function defineErrorTypes() {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
$viewer = $request->getUser();
|
||||
|
||||
$query = id(new ReleephProductQuery())
|
||||
->setViewer($viewer);
|
||||
|
||||
$ids = $request->getValue('ids');
|
||||
if ($ids !== null) {
|
||||
$query->withIDs($ids);
|
||||
}
|
||||
|
||||
$phids = $request->getValue('phids');
|
||||
if ($phids !== null) {
|
||||
$query->withPHIDs($phids);
|
||||
}
|
||||
|
||||
$repository_phids = $request->getValue('repositoryPHIDs');
|
||||
if ($repository_phids !== null) {
|
||||
$query->withRepositoryPHIDs($repository_phids);
|
||||
}
|
||||
|
||||
$is_active = $request->getValue('isActive');
|
||||
if ($is_active !== null) {
|
||||
$query->withActive($is_active);
|
||||
}
|
||||
|
||||
$pager = $this->newPager($request);
|
||||
$products = $query->executeWithCursorPager($pager);
|
||||
|
||||
$data = array();
|
||||
foreach ($products as $product) {
|
||||
$id = $product->getID();
|
||||
|
||||
$uri = '/releeph/product/'.$id.'/';
|
||||
$uri = PhabricatorEnv::getProductionURI($uri);
|
||||
|
||||
$data[] = array(
|
||||
'id' => $id,
|
||||
'phid' => $product->getPHID(),
|
||||
'uri' => $uri,
|
||||
'name' => $product->getName(),
|
||||
'isActive' => (bool)$product->getIsActive(),
|
||||
'repositoryPHID' => $product->getRepositoryPHID(),
|
||||
);
|
||||
}
|
||||
|
||||
return $this->addPagerResults(
|
||||
array(
|
||||
'data' => $data,
|
||||
),
|
||||
$pager);
|
||||
}
|
||||
|
||||
}
|
|
@ -203,7 +203,7 @@ final class ReleephProductEditController extends ReleephProductController {
|
|||
$form
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->addCancelButton('/releeph/project/')
|
||||
->addCancelButton('/releeph/product/')
|
||||
->setValue(pht('Save')));
|
||||
|
||||
$box = id(new PHUIObjectBoxView())
|
||||
|
|
|
@ -37,7 +37,7 @@ final class ReleephProductListController extends ReleephController
|
|||
|
||||
$item = id(new PHUIObjectItemView())
|
||||
->setHeader($product->getName())
|
||||
->setHref($this->getApplicationURI("project/{$id}/"));
|
||||
->setHref($this->getApplicationURI("product/{$id}/"));
|
||||
|
||||
if (!$product->getIsActive()) {
|
||||
$item->setDisabled(true);
|
||||
|
@ -70,7 +70,7 @@ final class ReleephProductListController extends ReleephController
|
|||
$crumbs->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->setName(pht('Create Product'))
|
||||
->setHref($this->getApplicationURI('project/create/'))
|
||||
->setHref($this->getApplicationURI('product/create/'))
|
||||
->setIcon('create'));
|
||||
|
||||
return $crumbs;
|
||||
|
|
|
@ -33,7 +33,7 @@ final class ReleephProductViewController extends ReleephProductController
|
|||
->setPreface($this->renderPreface())
|
||||
->setSearchEngine(
|
||||
id(new ReleephBranchSearchEngine())
|
||||
->setProjectID($product->getID()))
|
||||
->setProduct($product))
|
||||
->setNavigation($this->buildSideNavView());
|
||||
|
||||
return $this->delegateToController($controller);
|
||||
|
@ -46,7 +46,7 @@ final class ReleephProductViewController extends ReleephProductController
|
|||
|
||||
$viewer = $this->getRequest()->getUser();
|
||||
|
||||
$products = mpull($branches, 'getProject');
|
||||
$products = mpull($branches, 'getProduct');
|
||||
$repo_phids = mpull($products, 'getRepositoryPHID');
|
||||
|
||||
$repos = id(new PhabricatorRepositoryQuery())
|
||||
|
@ -72,7 +72,7 @@ final class ReleephProductViewController extends ReleephProductController
|
|||
->setUser($viewer);
|
||||
foreach ($branches as $branch) {
|
||||
$diffusion_href = null;
|
||||
$repo = idx($repos, $branch->getProject()->getRepositoryPHID());
|
||||
$repo = idx($repos, $branch->getProduct()->getRepositoryPHID());
|
||||
if ($repo) {
|
||||
$drequest = DiffusionRequest::newFromDictionary(
|
||||
array(
|
||||
|
@ -135,11 +135,11 @@ final class ReleephProductViewController extends ReleephProductController
|
|||
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
||||
|
||||
if ($for_app) {
|
||||
$nav->addFilter('project/create/', pht('Create Product'));
|
||||
$nav->addFilter('product/create/', pht('Create Product'));
|
||||
}
|
||||
|
||||
id(new ReleephBranchSearchEngine())
|
||||
->setProjectID($product->getID())
|
||||
->setProduct($product)
|
||||
->setViewer($viewer)
|
||||
->addNavigationItems($nav->getMenu());
|
||||
|
||||
|
@ -190,8 +190,8 @@ final class ReleephProductViewController extends ReleephProductController
|
|||
$product,
|
||||
PhabricatorPolicyCapability::CAN_EDIT);
|
||||
|
||||
$edit_uri = $this->getApplicationURI("project/{$id}/edit/");
|
||||
$history_uri = $this->getApplicationURI("project/{$id}/history/");
|
||||
$edit_uri = $this->getApplicationURI("product/{$id}/edit/");
|
||||
$history_uri = $this->getApplicationURI("product/{$id}/history/");
|
||||
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
|
@ -203,11 +203,11 @@ final class ReleephProductViewController extends ReleephProductController
|
|||
|
||||
if ($product->getIsActive()) {
|
||||
$status_name = pht('Deactivate Product');
|
||||
$status_href = "project/{$id}/action/deactivate/";
|
||||
$status_href = "product/{$id}/action/deactivate/";
|
||||
$status_icon = 'delete';
|
||||
} else {
|
||||
$status_name = pht('Reactivate Product');
|
||||
$status_href = "project/{$id}/action/activate/";
|
||||
$status_href = "product/{$id}/action/activate/";
|
||||
$status_icon = 'new';
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@ final class ReleephBranchQuery
|
|||
|
||||
private $ids;
|
||||
private $phids;
|
||||
private $projectIDs;
|
||||
private $productPHIDs;
|
||||
private $productIDs;
|
||||
|
||||
const STATUS_ALL = 'status-all';
|
||||
const STATUS_OPEN = 'status-open';
|
||||
|
@ -33,8 +34,8 @@ final class ReleephBranchQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withProjectIDs(array $ids) {
|
||||
$this->projectIDs = $ids;
|
||||
public function withProductPHIDs($product_phids) {
|
||||
$this->productPHIDs = $product_phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -53,6 +54,22 @@ final class ReleephBranchQuery
|
|||
return $table->loadAllFromArray($data);
|
||||
}
|
||||
|
||||
public function willExecute() {
|
||||
if ($this->productPHIDs !== null) {
|
||||
$products = id(new ReleephProductQuery())
|
||||
->setViewer($this->getViewer())
|
||||
->withPHIDs($this->productPHIDs)
|
||||
->execute();
|
||||
|
||||
if (!$products) {
|
||||
throw new PhabricatorEmptyQueryException();
|
||||
}
|
||||
|
||||
$this->productIDs = mpull($products, 'getID');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function willFilterPage(array $branches) {
|
||||
$project_ids = mpull($branches, 'getReleephProjectID');
|
||||
|
||||
|
@ -90,25 +107,25 @@ final class ReleephBranchQuery
|
|||
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
|
||||
if ($this->ids) {
|
||||
if ($this->ids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->phids) {
|
||||
if ($this->phids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'phid IN (%Ls)',
|
||||
$this->phids);
|
||||
}
|
||||
|
||||
if ($this->projectIDs) {
|
||||
if ($this->productIDs !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'releephProjectID IN (%Ld)',
|
||||
$this->projectIDs);
|
||||
$this->productIDs);
|
||||
}
|
||||
|
||||
$status = $this->status;
|
||||
|
|
|
@ -3,15 +3,15 @@
|
|||
final class ReleephBranchSearchEngine
|
||||
extends PhabricatorApplicationSearchEngine {
|
||||
|
||||
private $projectID;
|
||||
private $product;
|
||||
|
||||
public function setProjectID($project_id) {
|
||||
$this->projectID = $project_id;
|
||||
public function setProduct(ReleephProject $product) {
|
||||
$this->product = $product;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProjectID() {
|
||||
return $this->projectID;
|
||||
public function getProduct() {
|
||||
return $this->product;
|
||||
}
|
||||
|
||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
|
@ -25,7 +25,7 @@ final class ReleephBranchSearchEngine
|
|||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
$query = id(new ReleephBranchQuery())
|
||||
->needCutPointCommits(true)
|
||||
->withProjectIDs(array($this->getProjectID()));
|
||||
->withProductPHIDs(array($this->getProduct()->getPHID()));
|
||||
|
||||
$active = $saved->getParameter('active');
|
||||
$value = idx($this->getActiveValues(), $active);
|
||||
|
@ -49,7 +49,7 @@ final class ReleephBranchSearchEngine
|
|||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
return '/releeph/project/'.$this->getProjectID().'/'.$path;
|
||||
return '/releeph/product/'.$this->getProduct()->getID().'/'.$path;
|
||||
}
|
||||
|
||||
public function getBuiltinQueryNames() {
|
||||
|
|
|
@ -6,6 +6,7 @@ final class ReleephProductQuery
|
|||
private $active;
|
||||
private $ids;
|
||||
private $phids;
|
||||
private $repositoryPHIDs;
|
||||
|
||||
private $needArcanistProjects;
|
||||
|
||||
|
@ -33,6 +34,11 @@ final class ReleephProductQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withRepositoryPHIDs(array $repository_phids) {
|
||||
$this->repositoryPHIDs = $repository_phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function needArcanistProjects($need) {
|
||||
$this->needArcanistProjects = $need;
|
||||
return $this;
|
||||
|
@ -109,20 +115,27 @@ final class ReleephProductQuery
|
|||
(int)$this->active);
|
||||
}
|
||||
|
||||
if ($this->ids) {
|
||||
if ($this->ids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'id IN (%Ls)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->phids) {
|
||||
if ($this->phids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'phid IN (%Ls)',
|
||||
$this->phids);
|
||||
}
|
||||
|
||||
if ($this->repositoryPHIDs !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'repositoryPHID IN (%Ls)',
|
||||
$this->repositoryPHIDs);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
|
|
Loading…
Reference in a new issue