diff --git a/src/applications/harbormaster/artifact/HarbormasterURIArtifact.php b/src/applications/harbormaster/artifact/HarbormasterURIArtifact.php --- a/src/applications/harbormaster/artifact/HarbormasterURIArtifact.php +++ b/src/applications/harbormaster/artifact/HarbormasterURIArtifact.php @@ -46,6 +46,15 @@ } 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'); diff --git a/src/applications/harbormaster/controller/HarbormasterBuildViewController.php b/src/applications/harbormaster/controller/HarbormasterBuildViewController.php --- a/src/applications/harbormaster/controller/HarbormasterBuildViewController.php +++ b/src/applications/harbormaster/controller/HarbormasterBuildViewController.php @@ -67,6 +67,18 @@ $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 @@ ->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 @@ $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 @@ )); } - 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(); diff --git a/src/applications/harbormaster/event/HarbormasterUIEventListener.php b/src/applications/harbormaster/event/HarbormasterUIEventListener.php --- a/src/applications/harbormaster/event/HarbormasterUIEventListener.php +++ b/src/applications/harbormaster/event/HarbormasterUIEventListener.php @@ -16,7 +16,7 @@ } 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 @@ } $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 @@ $builds = $buildable->getBuilds(); - $build_handles = id(new PhabricatorHandleQuery()) - ->setViewer($user) - ->withPHIDs(mpull($builds, 'getPHID')) - ->execute(); + $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 @@ $target = phutil_tag('strong', array(), $target); + $status_view ->addItem( id(new PHUIStatusItemView()) @@ -95,7 +113,23 @@ 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 @@ $item->setIcon($icon, $color, $status_name); - $status_view->addItem($item); } diff --git a/src/applications/harbormaster/query/HarbormasterBuildQuery.php b/src/applications/harbormaster/query/HarbormasterBuildQuery.php --- a/src/applications/harbormaster/query/HarbormasterBuildQuery.php +++ b/src/applications/harbormaster/query/HarbormasterBuildQuery.php @@ -40,19 +40,12 @@ 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 @@ 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() { diff --git a/src/applications/harbormaster/query/HarbormasterBuildTargetQuery.php b/src/applications/harbormaster/query/HarbormasterBuildTargetQuery.php --- a/src/applications/harbormaster/query/HarbormasterBuildTargetQuery.php +++ b/src/applications/harbormaster/query/HarbormasterBuildTargetQuery.php @@ -34,55 +34,46 @@ return $this; } + public function newResultObject() { + return new HarbormasterBuildTarget(); + } + 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); + return $this->loadStandardPage($this->newResultObject()); } - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { - $where = array(); + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { + $where = parent::buildWhereClauseParts($conn); - if ($this->ids) { + 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) {