@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+117 -65
+9
src/applications/harbormaster/artifact/HarbormasterURIArtifact.php
··· 46 46 } 47 47 48 48 public function renderArtifactSummary(PhabricatorUser $viewer) { 49 + return $this->renderLink(); 50 + } 51 + 52 + public function isExternalLink() { 53 + $artifact = $this->getBuildArtifact(); 54 + return (bool)$artifact->getProperty('ui.external', false); 55 + } 56 + 57 + public function renderLink() { 49 58 $artifact = $this->getBuildArtifact(); 50 59 $uri = $artifact->getProperty('uri'); 51 60
+38 -10
src/applications/harbormaster/controller/HarbormasterBuildViewController.php
··· 67 67 $messages = array(); 68 68 } 69 69 70 + if ($build_targets) { 71 + $artifacts = id(new HarbormasterBuildArtifactQuery()) 72 + ->setViewer($viewer) 73 + ->withBuildTargetPHIDs(mpull($build_targets, 'getPHID')) 74 + ->execute(); 75 + $artifacts = msort($artifacts, 'getArtifactKey'); 76 + $artifacts = mgroup($artifacts, 'getBuildTargetPHID'); 77 + } else { 78 + $artifacts = array(); 79 + } 80 + 81 + 70 82 $targets = array(); 71 83 foreach ($build_targets as $build_target) { 72 84 $header = id(new PHUIHeaderView()) ··· 77 89 ->setHeader($header); 78 90 79 91 $properties = new PHUIPropertyListView(); 92 + 93 + $target_artifacts = idx($artifacts, $build_target->getPHID(), array()); 94 + 95 + $links = array(); 96 + $type_uri = HarbormasterURIArtifact::ARTIFACTCONST; 97 + foreach ($target_artifacts as $artifact) { 98 + if ($artifact->getArtifactType() == $type_uri) { 99 + $impl = $artifact->getArtifactImplementation(); 100 + if ($impl->isExternalLink()) { 101 + $links[] = $impl->renderLink(); 102 + } 103 + } 104 + } 105 + 106 + if ($links) { 107 + $links = phutil_implode_html(phutil_tag('br'), $links); 108 + $properties->addProperty( 109 + pht('External Link'), 110 + $links); 111 + } 112 + 80 113 $status_view = new PHUIStatusListView(); 81 114 82 115 $item = new PHUIStatusItemView(); ··· 177 210 $properties->addRawContent($this->buildProperties($variables)); 178 211 $target_box->addPropertyList($properties, pht('Variables')); 179 212 180 - $artifacts = $this->buildArtifacts($build_target); 213 + $artifacts_tab = $this->buildArtifacts($build_target, $target_artifacts); 181 214 $properties = new PHUIPropertyListView(); 182 - $properties->addRawContent($artifacts); 215 + $properties->addRawContent($artifacts_tab); 183 216 $target_box->addPropertyList($properties, pht('Artifacts')); 184 217 185 218 $build_messages = idx($messages, $build_target->getPHID(), array()); ··· 218 251 )); 219 252 } 220 253 221 - private function buildArtifacts(HarbormasterBuildTarget $build_target) { 254 + private function buildArtifacts( 255 + HarbormasterBuildTarget $build_target, 256 + array $artifacts) { 222 257 $viewer = $this->getViewer(); 223 - 224 - $artifacts = id(new HarbormasterBuildArtifactQuery()) 225 - ->setViewer($viewer) 226 - ->withBuildTargetPHIDs(array($build_target->getPHID())) 227 - ->execute(); 228 - 229 - $artifacts = msort($artifacts, 'getArtifactKey'); 230 258 231 259 $rows = array(); 232 260 foreach ($artifacts as $artifact) {
+41 -8
src/applications/harbormaster/event/HarbormasterUIEventListener.php
··· 16 16 } 17 17 18 18 private function handlePropertyEvent($ui_event) { 19 - $user = $ui_event->getUser(); 19 + $viewer = $ui_event->getUser(); 20 20 $object = $ui_event->getValue('object'); 21 21 22 22 if (!$object || !$object->getPHID()) { ··· 52 52 } 53 53 54 54 $buildable = id(new HarbormasterBuildableQuery()) 55 - ->setViewer($user) 55 + ->setViewer($viewer) 56 56 ->withManualBuildables(false) 57 57 ->withBuildablePHIDs(array($buildable_phid)) 58 58 ->needBuilds(true) 59 + ->needTargets(true) 59 60 ->executeOne(); 60 61 if (!$buildable) { 61 62 return; ··· 63 64 64 65 $builds = $buildable->getBuilds(); 65 66 66 - $build_handles = id(new PhabricatorHandleQuery()) 67 - ->setViewer($user) 68 - ->withPHIDs(mpull($builds, 'getPHID')) 69 - ->execute(); 67 + $targets = array(); 68 + foreach ($builds as $build) { 69 + foreach ($build->getBuildTargets() as $target) { 70 + $targets[] = $target; 71 + } 72 + } 73 + 74 + if ($targets) { 75 + $artifacts = id(new HarbormasterBuildArtifactQuery()) 76 + ->setViewer($viewer) 77 + ->withBuildTargetPHIDs(mpull($targets, 'getPHID')) 78 + ->withArtifactTypes( 79 + array( 80 + HarbormasterURIArtifact::ARTIFACTCONST, 81 + )) 82 + ->execute(); 83 + $artifacts = mgroup($artifacts, 'getBuildTargetPHID'); 84 + } else { 85 + $artifacts = array(); 86 + } 70 87 71 88 $status_view = new PHUIStatusListView(); 72 89 ··· 87 104 88 105 $target = phutil_tag('strong', array(), $target); 89 106 107 + 90 108 $status_view 91 109 ->addItem( 92 110 id(new PHUIStatusItemView()) ··· 95 113 96 114 foreach ($builds as $build) { 97 115 $item = new PHUIStatusItemView(); 98 - $item->setTarget($build_handles[$build->getPHID()]->renderLink()); 116 + $item->setTarget($viewer->renderHandle($build->getPHID())); 117 + 118 + $links = array(); 119 + foreach ($build->getBuildTargets() as $build_target) { 120 + $uris = idx($artifacts, $build_target->getPHID(), array()); 121 + foreach ($uris as $uri) { 122 + $impl = $uri->getArtifactImplementation(); 123 + if ($impl->isExternalLink()) { 124 + $links[] = $impl->renderLink(); 125 + } 126 + } 127 + } 128 + 129 + if ($links) { 130 + $links = phutil_implode_html(" \xC2\xB7 ", $links); 131 + $item->setNote($links); 132 + } 99 133 100 134 $status = $build->getBuildStatus(); 101 135 $status_name = HarbormasterBuild::getBuildStatusName($status); ··· 103 137 $color = HarbormasterBuild::getBuildStatusColor($status); 104 138 105 139 $item->setIcon($icon, $color, $status_name); 106 - 107 140 108 141 $status_view->addItem($item); 109 142 }
+13 -22
src/applications/harbormaster/query/HarbormasterBuildQuery.php
··· 40 40 return $this; 41 41 } 42 42 43 + public function newResultObject() { 44 + return new HarbormasterBuild(); 45 + } 46 + 43 47 protected function loadPage() { 44 - $table = new HarbormasterBuild(); 45 - $conn_r = $table->establishConnection('r'); 46 - 47 - $data = queryfx_all( 48 - $conn_r, 49 - 'SELECT * FROM %T %Q %Q %Q', 50 - $table->getTableName(), 51 - $this->buildWhereClause($conn_r), 52 - $this->buildOrderClause($conn_r), 53 - $this->buildLimitClause($conn_r)); 54 - 55 - return $table->loadAllFromArray($data); 48 + return $this->loadStandardPage($this->newResultObject()); 56 49 } 57 50 58 51 protected function willFilterPage(array $page) { ··· 136 129 return $page; 137 130 } 138 131 139 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 140 - $where = array(); 132 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 133 + $where = parent::buildWhereClauseParts($conn); 141 134 142 135 if ($this->ids !== null) { 143 136 $where[] = qsprintf( 144 - $conn_r, 137 + $conn, 145 138 'id IN (%Ld)', 146 139 $this->ids); 147 140 } 148 141 149 142 if ($this->phids !== null) { 150 143 $where[] = qsprintf( 151 - $conn_r, 144 + $conn, 152 145 'phid in (%Ls)', 153 146 $this->phids); 154 147 } 155 148 156 149 if ($this->buildStatuses !== null) { 157 150 $where[] = qsprintf( 158 - $conn_r, 151 + $conn, 159 152 'buildStatus in (%Ls)', 160 153 $this->buildStatuses); 161 154 } 162 155 163 156 if ($this->buildablePHIDs !== null) { 164 157 $where[] = qsprintf( 165 - $conn_r, 158 + $conn, 166 159 'buildablePHID IN (%Ls)', 167 160 $this->buildablePHIDs); 168 161 } 169 162 170 163 if ($this->buildPlanPHIDs !== null) { 171 164 $where[] = qsprintf( 172 - $conn_r, 165 + $conn, 173 166 'buildPlanPHID IN (%Ls)', 174 167 $this->buildPlanPHIDs); 175 168 } 176 169 177 - $where[] = $this->buildPagingClause($conn_r); 178 - 179 - return $this->formatWhereClause($where); 170 + return $where; 180 171 } 181 172 182 173 public function getQueryApplicationClass() {
+16 -25
src/applications/harbormaster/query/HarbormasterBuildTargetQuery.php
··· 34 34 return $this; 35 35 } 36 36 37 + public function newResultObject() { 38 + return new HarbormasterBuildTarget(); 39 + } 40 + 37 41 protected function loadPage() { 38 - $table = new HarbormasterBuildTarget(); 39 - $conn_r = $table->establishConnection('r'); 40 - 41 - $data = queryfx_all( 42 - $conn_r, 43 - 'SELECT * FROM %T %Q %Q %Q', 44 - $table->getTableName(), 45 - $this->buildWhereClause($conn_r), 46 - $this->buildOrderClause($conn_r), 47 - $this->buildLimitClause($conn_r)); 48 - 49 - return $table->loadAllFromArray($data); 42 + return $this->loadStandardPage($this->newResultObject()); 50 43 } 51 44 52 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 53 - $where = array(); 45 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 46 + $where = parent::buildWhereClauseParts($conn); 54 47 55 - if ($this->ids) { 48 + if ($this->ids !== null) { 56 49 $where[] = qsprintf( 57 - $conn_r, 50 + $conn, 58 51 'id IN (%Ld)', 59 52 $this->ids); 60 53 } 61 54 62 - if ($this->phids) { 55 + if ($this->phids !== null) { 63 56 $where[] = qsprintf( 64 - $conn_r, 57 + $conn, 65 58 'phid in (%Ls)', 66 59 $this->phids); 67 60 } 68 61 69 - if ($this->buildPHIDs) { 62 + if ($this->buildPHIDs !== null) { 70 63 $where[] = qsprintf( 71 - $conn_r, 64 + $conn, 72 65 'buildPHID in (%Ls)', 73 66 $this->buildPHIDs); 74 67 } 75 68 76 - if ($this->buildGenerations) { 69 + if ($this->buildGenerations !== null) { 77 70 $where[] = qsprintf( 78 - $conn_r, 71 + $conn, 79 72 'buildGeneration in (%Ld)', 80 73 $this->buildGenerations); 81 74 } 82 75 83 - $where[] = $this->buildPagingClause($conn_r); 84 - 85 - return $this->formatWhereClause($where); 76 + return $where; 86 77 } 87 78 88 79 protected function didFilterPage(array $page) {