1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 22:40:55 +01:00

Show external build links in applications

Summary: Fixes T8659. This isn't //explicitly// documented but I'm going to wait for a bit until the "Harbormaster" doc splits into internal/external builds to add docs for it. There's other similar stuff coming soon anyway.

Test Plan:
{F716439}

{F716440}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T8659

Differential Revision: https://secure.phabricator.com/D13903
This commit is contained in:
epriestley 2015-08-15 07:29:26 -07:00
parent 57b0353034
commit 74bf0d6ec6
5 changed files with 118 additions and 66 deletions

View file

@ -46,6 +46,15 @@ final class HarbormasterURIArtifact extends HarbormasterArtifact {
}
public function renderArtifactSummary(PhabricatorUser $viewer) {
return $this->renderLink();
}
public function isExternalLink() {
$artifact = $this->getBuildArtifact();
return (bool)$artifact->getProperty('ui.external', false);
}
public function renderLink() {
$artifact = $this->getBuildArtifact();
$uri = $artifact->getProperty('uri');

View file

@ -67,6 +67,18 @@ final class HarbormasterBuildViewController
$messages = array();
}
if ($build_targets) {
$artifacts = id(new HarbormasterBuildArtifactQuery())
->setViewer($viewer)
->withBuildTargetPHIDs(mpull($build_targets, 'getPHID'))
->execute();
$artifacts = msort($artifacts, 'getArtifactKey');
$artifacts = mgroup($artifacts, 'getBuildTargetPHID');
} else {
$artifacts = array();
}
$targets = array();
foreach ($build_targets as $build_target) {
$header = id(new PHUIHeaderView())
@ -77,6 +89,27 @@ final class HarbormasterBuildViewController
->setHeader($header);
$properties = new PHUIPropertyListView();
$target_artifacts = idx($artifacts, $build_target->getPHID(), array());
$links = array();
$type_uri = HarbormasterURIArtifact::ARTIFACTCONST;
foreach ($target_artifacts as $artifact) {
if ($artifact->getArtifactType() == $type_uri) {
$impl = $artifact->getArtifactImplementation();
if ($impl->isExternalLink()) {
$links[] = $impl->renderLink();
}
}
}
if ($links) {
$links = phutil_implode_html(phutil_tag('br'), $links);
$properties->addProperty(
pht('External Link'),
$links);
}
$status_view = new PHUIStatusListView();
$item = new PHUIStatusItemView();
@ -177,9 +210,9 @@ final class HarbormasterBuildViewController
$properties->addRawContent($this->buildProperties($variables));
$target_box->addPropertyList($properties, pht('Variables'));
$artifacts = $this->buildArtifacts($build_target);
$artifacts_tab = $this->buildArtifacts($build_target, $target_artifacts);
$properties = new PHUIPropertyListView();
$properties->addRawContent($artifacts);
$properties->addRawContent($artifacts_tab);
$target_box->addPropertyList($properties, pht('Artifacts'));
$build_messages = idx($messages, $build_target->getPHID(), array());
@ -218,16 +251,11 @@ final class HarbormasterBuildViewController
));
}
private function buildArtifacts(HarbormasterBuildTarget $build_target) {
private function buildArtifacts(
HarbormasterBuildTarget $build_target,
array $artifacts) {
$viewer = $this->getViewer();
$artifacts = id(new HarbormasterBuildArtifactQuery())
->setViewer($viewer)
->withBuildTargetPHIDs(array($build_target->getPHID()))
->execute();
$artifacts = msort($artifacts, 'getArtifactKey');
$rows = array();
foreach ($artifacts as $artifact) {
$impl = $artifact->getArtifactImplementation();

View file

@ -16,7 +16,7 @@ final class HarbormasterUIEventListener
}
private function handlePropertyEvent($ui_event) {
$user = $ui_event->getUser();
$viewer = $ui_event->getUser();
$object = $ui_event->getValue('object');
if (!$object || !$object->getPHID()) {
@ -52,10 +52,11 @@ final class HarbormasterUIEventListener
}
$buildable = id(new HarbormasterBuildableQuery())
->setViewer($user)
->setViewer($viewer)
->withManualBuildables(false)
->withBuildablePHIDs(array($buildable_phid))
->needBuilds(true)
->needTargets(true)
->executeOne();
if (!$buildable) {
return;
@ -63,10 +64,26 @@ final class HarbormasterUIEventListener
$builds = $buildable->getBuilds();
$build_handles = id(new PhabricatorHandleQuery())
->setViewer($user)
->withPHIDs(mpull($builds, 'getPHID'))
$targets = array();
foreach ($builds as $build) {
foreach ($build->getBuildTargets() as $target) {
$targets[] = $target;
}
}
if ($targets) {
$artifacts = id(new HarbormasterBuildArtifactQuery())
->setViewer($viewer)
->withBuildTargetPHIDs(mpull($targets, 'getPHID'))
->withArtifactTypes(
array(
HarbormasterURIArtifact::ARTIFACTCONST,
))
->execute();
$artifacts = mgroup($artifacts, 'getBuildTargetPHID');
} else {
$artifacts = array();
}
$status_view = new PHUIStatusListView();
@ -87,6 +104,7 @@ final class HarbormasterUIEventListener
$target = phutil_tag('strong', array(), $target);
$status_view
->addItem(
id(new PHUIStatusItemView())
@ -95,7 +113,23 @@ final class HarbormasterUIEventListener
foreach ($builds as $build) {
$item = new PHUIStatusItemView();
$item->setTarget($build_handles[$build->getPHID()]->renderLink());
$item->setTarget($viewer->renderHandle($build->getPHID()));
$links = array();
foreach ($build->getBuildTargets() as $build_target) {
$uris = idx($artifacts, $build_target->getPHID(), array());
foreach ($uris as $uri) {
$impl = $uri->getArtifactImplementation();
if ($impl->isExternalLink()) {
$links[] = $impl->renderLink();
}
}
}
if ($links) {
$links = phutil_implode_html(" \xC2\xB7 ", $links);
$item->setNote($links);
}
$status = $build->getBuildStatus();
$status_name = HarbormasterBuild::getBuildStatusName($status);
@ -104,7 +138,6 @@ final class HarbormasterUIEventListener
$item->setIcon($icon, $color, $status_name);
$status_view->addItem($item);
}

View file

@ -40,19 +40,12 @@ final class HarbormasterBuildQuery
return $this;
}
public function newResultObject() {
return new HarbormasterBuild();
}
protected function loadPage() {
$table = new HarbormasterBuild();
$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);
return $this->loadStandardPage($this->newResultObject());
}
protected function willFilterPage(array $page) {
@ -136,47 +129,45 @@ final class HarbormasterBuildQuery
return $page;
}
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn_r,
$conn,
'id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn_r,
$conn,
'phid in (%Ls)',
$this->phids);
}
if ($this->buildStatuses !== null) {
$where[] = qsprintf(
$conn_r,
$conn,
'buildStatus in (%Ls)',
$this->buildStatuses);
}
if ($this->buildablePHIDs !== null) {
$where[] = qsprintf(
$conn_r,
$conn,
'buildablePHID IN (%Ls)',
$this->buildablePHIDs);
}
if ($this->buildPlanPHIDs !== null) {
$where[] = qsprintf(
$conn_r,
$conn,
'buildPlanPHID IN (%Ls)',
$this->buildPlanPHIDs);
}
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
return $where;
}
public function getQueryApplicationClass() {

View file

@ -34,55 +34,46 @@ final class HarbormasterBuildTargetQuery
return $this;
}
protected function loadPage() {
$table = new HarbormasterBuildTarget();
$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);
public function newResultObject() {
return new HarbormasterBuildTarget();
}
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
protected function loadPage() {
return $this->loadStandardPage($this->newResultObject());
}
if ($this->ids) {
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn_r,
$conn,
'id IN (%Ld)',
$this->ids);
}
if ($this->phids) {
if ($this->phids !== null) {
$where[] = qsprintf(
$conn_r,
$conn,
'phid in (%Ls)',
$this->phids);
}
if ($this->buildPHIDs) {
if ($this->buildPHIDs !== null) {
$where[] = qsprintf(
$conn_r,
$conn,
'buildPHID in (%Ls)',
$this->buildPHIDs);
}
if ($this->buildGenerations) {
if ($this->buildGenerations !== null) {
$where[] = qsprintf(
$conn_r,
$conn,
'buildGeneration in (%Ld)',
$this->buildGenerations);
}
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
return $where;
}
protected function didFilterPage(array $page) {