1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-11 15:21:03 +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:
epriestley 2014-04-20 11:54:22 -07:00
parent f5cc5c122a
commit 6e6ad2cfcf
11 changed files with 224 additions and 29 deletions

View file

@ -230,6 +230,8 @@ phutil_register_library_map(array(
'ConduitAPI_releeph_Method' => 'applications/releeph/conduit/ConduitAPI_releeph_Method.php', 'ConduitAPI_releeph_Method' => 'applications/releeph/conduit/ConduitAPI_releeph_Method.php',
'ConduitAPI_releeph_getbranches_Method' => 'applications/releeph/conduit/ConduitAPI_releeph_getbranches_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_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_queryrequests_Method' => 'applications/releeph/conduit/ConduitAPI_releeph_queryrequests_Method.php',
'ConduitAPI_releeph_request_Method' => 'applications/releeph/conduit/ConduitAPI_releeph_request_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_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_Method' => 'ConduitAPIMethod',
'ConduitAPI_releeph_getbranches_Method' => 'ConduitAPI_releeph_Method', 'ConduitAPI_releeph_getbranches_Method' => 'ConduitAPI_releeph_Method',
'ConduitAPI_releeph_projectinfo_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_queryrequests_Method' => 'ConduitAPI_releeph_Method',
'ConduitAPI_releeph_request_Method' => 'ConduitAPI_releeph_Method', 'ConduitAPI_releeph_request_Method' => 'ConduitAPI_releeph_Method',
'ConduitAPI_releephwork_canpush_Method' => 'ConduitAPI_releeph_Method', 'ConduitAPI_releephwork_canpush_Method' => 'ConduitAPI_releeph_Method',

View file

@ -40,7 +40,7 @@ final class PhabricatorApplicationReleeph extends PhabricatorApplication {
'/releeph/' => array( '/releeph/' => array(
'' => 'ReleephProductListController', '' => 'ReleephProductListController',
'project/' => array( '(?:product|project)/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?' => 'ReleephProductListController', '(?:query/(?P<queryKey>[^/]+)/)?' => 'ReleephProductListController',
'create/' => 'ReleephProductCreateController', 'create/' => 'ReleephProductCreateController',
'(?P<projectID>[1-9]\d*)/' => array( '(?P<projectID>[1-9]\d*)/' => array(

View file

@ -2,6 +2,14 @@
abstract class ConduitAPI_releeph_Method extends ConduitAPIMethod { 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() { public function getApplication() {
return PhabricatorApplication::getByClass('PhabricatorApplicationReleeph'); return PhabricatorApplication::getByClass('PhabricatorApplicationReleeph');
} }

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -203,7 +203,7 @@ final class ReleephProductEditController extends ReleephProductController {
$form $form
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->addCancelButton('/releeph/project/') ->addCancelButton('/releeph/product/')
->setValue(pht('Save'))); ->setValue(pht('Save')));
$box = id(new PHUIObjectBoxView()) $box = id(new PHUIObjectBoxView())

View file

@ -37,7 +37,7 @@ final class ReleephProductListController extends ReleephController
$item = id(new PHUIObjectItemView()) $item = id(new PHUIObjectItemView())
->setHeader($product->getName()) ->setHeader($product->getName())
->setHref($this->getApplicationURI("project/{$id}/")); ->setHref($this->getApplicationURI("product/{$id}/"));
if (!$product->getIsActive()) { if (!$product->getIsActive()) {
$item->setDisabled(true); $item->setDisabled(true);
@ -70,7 +70,7 @@ final class ReleephProductListController extends ReleephController
$crumbs->addAction( $crumbs->addAction(
id(new PHUIListItemView()) id(new PHUIListItemView())
->setName(pht('Create Product')) ->setName(pht('Create Product'))
->setHref($this->getApplicationURI('project/create/')) ->setHref($this->getApplicationURI('product/create/'))
->setIcon('create')); ->setIcon('create'));
return $crumbs; return $crumbs;

View file

@ -33,7 +33,7 @@ final class ReleephProductViewController extends ReleephProductController
->setPreface($this->renderPreface()) ->setPreface($this->renderPreface())
->setSearchEngine( ->setSearchEngine(
id(new ReleephBranchSearchEngine()) id(new ReleephBranchSearchEngine())
->setProjectID($product->getID())) ->setProduct($product))
->setNavigation($this->buildSideNavView()); ->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller); return $this->delegateToController($controller);
@ -46,7 +46,7 @@ final class ReleephProductViewController extends ReleephProductController
$viewer = $this->getRequest()->getUser(); $viewer = $this->getRequest()->getUser();
$products = mpull($branches, 'getProject'); $products = mpull($branches, 'getProduct');
$repo_phids = mpull($products, 'getRepositoryPHID'); $repo_phids = mpull($products, 'getRepositoryPHID');
$repos = id(new PhabricatorRepositoryQuery()) $repos = id(new PhabricatorRepositoryQuery())
@ -72,7 +72,7 @@ final class ReleephProductViewController extends ReleephProductController
->setUser($viewer); ->setUser($viewer);
foreach ($branches as $branch) { foreach ($branches as $branch) {
$diffusion_href = null; $diffusion_href = null;
$repo = idx($repos, $branch->getProject()->getRepositoryPHID()); $repo = idx($repos, $branch->getProduct()->getRepositoryPHID());
if ($repo) { if ($repo) {
$drequest = DiffusionRequest::newFromDictionary( $drequest = DiffusionRequest::newFromDictionary(
array( array(
@ -135,11 +135,11 @@ final class ReleephProductViewController extends ReleephProductController
$nav->setBaseURI(new PhutilURI($this->getApplicationURI())); $nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
if ($for_app) { if ($for_app) {
$nav->addFilter('project/create/', pht('Create Product')); $nav->addFilter('product/create/', pht('Create Product'));
} }
id(new ReleephBranchSearchEngine()) id(new ReleephBranchSearchEngine())
->setProjectID($product->getID()) ->setProduct($product)
->setViewer($viewer) ->setViewer($viewer)
->addNavigationItems($nav->getMenu()); ->addNavigationItems($nav->getMenu());
@ -190,8 +190,8 @@ final class ReleephProductViewController extends ReleephProductController
$product, $product,
PhabricatorPolicyCapability::CAN_EDIT); PhabricatorPolicyCapability::CAN_EDIT);
$edit_uri = $this->getApplicationURI("project/{$id}/edit/"); $edit_uri = $this->getApplicationURI("product/{$id}/edit/");
$history_uri = $this->getApplicationURI("project/{$id}/history/"); $history_uri = $this->getApplicationURI("product/{$id}/history/");
$actions->addAction( $actions->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())
@ -203,11 +203,11 @@ final class ReleephProductViewController extends ReleephProductController
if ($product->getIsActive()) { if ($product->getIsActive()) {
$status_name = pht('Deactivate Product'); $status_name = pht('Deactivate Product');
$status_href = "project/{$id}/action/deactivate/"; $status_href = "product/{$id}/action/deactivate/";
$status_icon = 'delete'; $status_icon = 'delete';
} else { } else {
$status_name = pht('Reactivate Product'); $status_name = pht('Reactivate Product');
$status_href = "project/{$id}/action/activate/"; $status_href = "product/{$id}/action/activate/";
$status_icon = 'new'; $status_icon = 'new';
} }

View file

@ -5,7 +5,8 @@ final class ReleephBranchQuery
private $ids; private $ids;
private $phids; private $phids;
private $projectIDs; private $productPHIDs;
private $productIDs;
const STATUS_ALL = 'status-all'; const STATUS_ALL = 'status-all';
const STATUS_OPEN = 'status-open'; const STATUS_OPEN = 'status-open';
@ -33,8 +34,8 @@ final class ReleephBranchQuery
return $this; return $this;
} }
public function withProjectIDs(array $ids) { public function withProductPHIDs($product_phids) {
$this->projectIDs = $ids; $this->productPHIDs = $product_phids;
return $this; return $this;
} }
@ -53,6 +54,22 @@ final class ReleephBranchQuery
return $table->loadAllFromArray($data); 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) { public function willFilterPage(array $branches) {
$project_ids = mpull($branches, 'getReleephProjectID'); $project_ids = mpull($branches, 'getReleephProjectID');
@ -90,25 +107,25 @@ final class ReleephBranchQuery
private function buildWhereClause(AphrontDatabaseConnection $conn_r) { private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array(); $where = array();
if ($this->ids) { if ($this->ids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'id IN (%Ld)', 'id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids) { if ($this->phids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'phid IN (%Ls)', 'phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->projectIDs) { if ($this->productIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'releephProjectID IN (%Ld)', 'releephProjectID IN (%Ld)',
$this->projectIDs); $this->productIDs);
} }
$status = $this->status; $status = $this->status;

View file

@ -3,15 +3,15 @@
final class ReleephBranchSearchEngine final class ReleephBranchSearchEngine
extends PhabricatorApplicationSearchEngine { extends PhabricatorApplicationSearchEngine {
private $projectID; private $product;
public function setProjectID($project_id) { public function setProduct(ReleephProject $product) {
$this->projectID = $project_id; $this->product = $product;
return $this; return $this;
} }
public function getProjectID() { public function getProduct() {
return $this->projectID; return $this->product;
} }
public function buildSavedQueryFromRequest(AphrontRequest $request) { public function buildSavedQueryFromRequest(AphrontRequest $request) {
@ -25,7 +25,7 @@ final class ReleephBranchSearchEngine
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new ReleephBranchQuery()) $query = id(new ReleephBranchQuery())
->needCutPointCommits(true) ->needCutPointCommits(true)
->withProjectIDs(array($this->getProjectID())); ->withProductPHIDs(array($this->getProduct()->getPHID()));
$active = $saved->getParameter('active'); $active = $saved->getParameter('active');
$value = idx($this->getActiveValues(), $active); $value = idx($this->getActiveValues(), $active);
@ -49,7 +49,7 @@ final class ReleephBranchSearchEngine
} }
protected function getURI($path) { protected function getURI($path) {
return '/releeph/project/'.$this->getProjectID().'/'.$path; return '/releeph/product/'.$this->getProduct()->getID().'/'.$path;
} }
public function getBuiltinQueryNames() { public function getBuiltinQueryNames() {

View file

@ -6,6 +6,7 @@ final class ReleephProductQuery
private $active; private $active;
private $ids; private $ids;
private $phids; private $phids;
private $repositoryPHIDs;
private $needArcanistProjects; private $needArcanistProjects;
@ -33,6 +34,11 @@ final class ReleephProductQuery
return $this; return $this;
} }
public function withRepositoryPHIDs(array $repository_phids) {
$this->repositoryPHIDs = $repository_phids;
return $this;
}
public function needArcanistProjects($need) { public function needArcanistProjects($need) {
$this->needArcanistProjects = $need; $this->needArcanistProjects = $need;
return $this; return $this;
@ -109,20 +115,27 @@ final class ReleephProductQuery
(int)$this->active); (int)$this->active);
} }
if ($this->ids) { if ($this->ids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'id IN (%Ls)', 'id IN (%Ls)',
$this->ids); $this->ids);
} }
if ($this->phids) { if ($this->phids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'phid IN (%Ls)', 'phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->repositoryPHIDs !== null) {
$where[] = qsprintf(
$conn_r,
'repositoryPHID IN (%Ls)',
$this->repositoryPHIDs);
}
$where[] = $this->buildPagingClause($conn_r); $where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where); return $this->formatWhereClause($where);