@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.

Reduce Lint/Unit rendering duplication

Summary: Ref T8096. No functional changes, just a bit less code.

Test Plan: Viewed some revisions, saw the same stuff as before.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8096

Differential Revision: https://secure.phabricator.com/D13404

+149 -157
+4 -2
src/__phutil_library_map__.php
··· 376 376 'DifferentialGetWorkingCopy' => 'applications/differential/DifferentialGetWorkingCopy.php', 377 377 'DifferentialGitHubLandingStrategy' => 'applications/differential/landing/DifferentialGitHubLandingStrategy.php', 378 378 'DifferentialGitSVNIDField' => 'applications/differential/customfield/DifferentialGitSVNIDField.php', 379 + 'DifferentialHarbormasterField' => 'applications/differential/customfield/DifferentialHarbormasterField.php', 379 380 'DifferentialHiddenComment' => 'applications/differential/storage/DifferentialHiddenComment.php', 380 381 'DifferentialHostField' => 'applications/differential/customfield/DifferentialHostField.php', 381 382 'DifferentialHostedGitLandingStrategy' => 'applications/differential/landing/DifferentialHostedGitLandingStrategy.php', ··· 3743 3744 'DifferentialGetWorkingCopy' => 'Phobject', 3744 3745 'DifferentialGitHubLandingStrategy' => 'DifferentialLandingStrategy', 3745 3746 'DifferentialGitSVNIDField' => 'DifferentialCustomField', 3747 + 'DifferentialHarbormasterField' => 'DifferentialCustomField', 3746 3748 'DifferentialHiddenComment' => 'DifferentialDAO', 3747 3749 'DifferentialHostField' => 'DifferentialCustomField', 3748 3750 'DifferentialHostedGitLandingStrategy' => 'DifferentialLandingStrategy', ··· 3768 3770 'DifferentialLandingStrategy' => 'Phobject', 3769 3771 'DifferentialLegacyHunk' => 'DifferentialHunk', 3770 3772 'DifferentialLineAdjustmentMap' => 'Phobject', 3771 - 'DifferentialLintField' => 'DifferentialCustomField', 3773 + 'DifferentialLintField' => 'DifferentialHarbormasterField', 3772 3774 'DifferentialLintStatus' => 'Phobject', 3773 3775 'DifferentialLocalCommitsView' => 'AphrontView', 3774 3776 'DifferentialManiphestTasksField' => 'DifferentialCoreCustomField', ··· 3844 3846 'DifferentialTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 3845 3847 'DifferentialTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 3846 3848 'DifferentialTransactionView' => 'PhabricatorApplicationTransactionView', 3847 - 'DifferentialUnitField' => 'DifferentialCustomField', 3849 + 'DifferentialUnitField' => 'DifferentialHarbormasterField', 3848 3850 'DifferentialUnitStatus' => 'Phobject', 3849 3851 'DifferentialUnitTestResult' => 'Phobject', 3850 3852 'DifferentialUpdateRevisionConduitAPIMethod' => 'DifferentialConduitAPIMethod',
+96
src/applications/differential/customfield/DifferentialHarbormasterField.php
··· 1 + <?php 2 + 3 + abstract class DifferentialHarbormasterField 4 + extends DifferentialCustomField { 5 + 6 + abstract protected function getDiffPropertyKeys(); 7 + abstract protected function loadHarbormasterTargetMessages( 8 + array $target_phids); 9 + abstract protected function getLegacyProperty(); 10 + abstract protected function newModernMessage(array $message); 11 + abstract protected function renderHarbormasterStatus( 12 + DifferentialDiff $diff, 13 + array $messages); 14 + abstract protected function newHarbormasterMessageView(array $messages); 15 + 16 + public function renderDiffPropertyViewValue(DifferentialDiff $diff) { 17 + // TODO: This load is slightly inefficient, but most of this is moving 18 + // to Harbormaster and this simplifies the transition. Eat 1-2 extra 19 + // queries for now. 20 + $keys = $this->getDiffPropertyKeys(); 21 + 22 + $properties = id(new DifferentialDiffProperty())->loadAllWhere( 23 + 'diffID = %d AND name IN (%Ls)', 24 + $diff->getID(), 25 + $keys); 26 + $properties = mpull($properties, 'getData', 'getName'); 27 + 28 + foreach ($keys as $key) { 29 + $diff->attachProperty($key, idx($properties, $key)); 30 + } 31 + 32 + $messages = array(); 33 + 34 + $buildable = $diff->getBuildable(); 35 + if ($buildable) { 36 + $target_phids = array(); 37 + foreach ($buildable->getBuilds() as $build) { 38 + foreach ($build->getBuildTargets() as $target) { 39 + $target_phids[] = $target->getPHID(); 40 + } 41 + } 42 + 43 + if ($target_phids) { 44 + $messages = $this->loadHarbormasterTargetMessages($target_phids); 45 + } 46 + } 47 + 48 + if (!$messages) { 49 + // No Harbormaster messages, so look for legacy messages and make them 50 + // look like modern messages. 51 + $legacy_messages = $diff->getProperty($this->getLegacyProperty()); 52 + if ($legacy_messages) { 53 + // Show the top 100 legacy lint messages. Previously, we showed some 54 + // by default and let the user toggle the rest. With modern messages, 55 + // we can send the user to the Harbormaster detail page. Just show 56 + // "a lot" of messages in legacy cases to try to strike a balance 57 + // between implementation simplicitly and compatibility. 58 + $legacy_messages = array_slice($legacy_messages, 0, 100); 59 + 60 + foreach ($legacy_messages as $message) { 61 + try { 62 + $modern = $this->newModernMessage($message); 63 + $messages[] = $modern; 64 + } catch (Exception $ex) { 65 + // Ignore any poorly formatted messages. 66 + } 67 + } 68 + } 69 + } 70 + 71 + $status = $this->renderHarbormasterStatus($diff, $messages); 72 + 73 + if ($messages) { 74 + $path_map = mpull($diff->loadChangesets(), 'getID', 'getFilename'); 75 + foreach ($path_map as $path => $id) { 76 + $href = '#C'.$id.'NL'; 77 + 78 + // TODO: When the diff is not the right-hand-size diff, we should 79 + // ideally adjust this URI to be absolute. 80 + 81 + $path_map[$path] = $href; 82 + } 83 + 84 + $view = $this->newHarbormasterMessageView($messages) 85 + ->setPathURIMap($path_map); 86 + } else { 87 + $view = null; 88 + } 89 + 90 + return array( 91 + $status, 92 + $view, 93 + ); 94 + } 95 + 96 + }
+25 -81
src/applications/differential/customfield/DifferentialLintField.php
··· 1 1 <?php 2 2 3 3 final class DifferentialLintField 4 - extends DifferentialCustomField { 4 + extends DifferentialHarbormasterField { 5 5 6 6 public function getFieldKey() { 7 7 return 'differential:lint'; ··· 31 31 return $this->getFieldName(); 32 32 } 33 33 34 - public function renderDiffPropertyViewValue(DifferentialDiff $diff) { 35 - // TODO: This load is slightly inefficient, but most of this is moving 36 - // to Harbormaster and this simplifies the transition. Eat 1-2 extra 37 - // queries for now. 38 - $keys = array( 34 + protected function getLegacyProperty() { 35 + return 'arc:lint'; 36 + } 37 + 38 + protected function getDiffPropertyKeys() { 39 + return array( 39 40 'arc:lint', 40 41 'arc:lint-excuse', 41 42 ); 42 - 43 - $properties = id(new DifferentialDiffProperty())->loadAllWhere( 44 - 'diffID = %d AND name IN (%Ls)', 45 - $diff->getID(), 46 - $keys); 47 - $properties = mpull($properties, 'getData', 'getName'); 48 - 49 - foreach ($keys as $key) { 50 - $diff->attachProperty($key, idx($properties, $key)); 51 - } 52 - 53 - $status = $this->renderLintStatus($diff); 54 - 55 - $lint = array(); 56 - 57 - $buildable = $diff->getBuildable(); 58 - if ($buildable) { 59 - $target_phids = array(); 60 - foreach ($buildable->getBuilds() as $build) { 61 - foreach ($build->getBuildTargets() as $target) { 62 - $target_phids[] = $target->getPHID(); 63 - } 64 - } 65 - 66 - $lint = id(new HarbormasterBuildLintMessage())->loadAllWhere( 67 - 'buildTargetPHID IN (%Ls) LIMIT 25', 68 - $target_phids); 69 - } 70 - 71 - if (!$lint) { 72 - // No Harbormaster messages, so look for legacy messages and make them 73 - // look like modern messages. 74 - $legacy_lint = $diff->getProperty('arc:lint'); 75 - if ($legacy_lint) { 76 - // Show the top 100 legacy lint messages. Previously, we showed some 77 - // by default and let the user toggle the rest. With modern messages, 78 - // we can send the user to the Harbormaster detail page. Just show 79 - // "a lot" of messages in legacy cases to try to strike a balance 80 - // between implementation simplicitly and compatibility. 81 - $legacy_lint = array_slice($legacy_lint, 0, 100); 43 + } 82 44 83 - $target = new HarbormasterBuildTarget(); 84 - foreach ($legacy_lint as $message) { 85 - try { 86 - $modern = HarbormasterBuildLintMessage::newFromDictionary( 87 - $target, 88 - $this->getModernLintMessageDictionary($message)); 89 - $lint[] = $modern; 90 - } catch (Exception $ex) { 91 - // Ignore any poorly formatted messages. 92 - } 93 - } 94 - } 95 - } 45 + protected function loadHarbormasterTargetMessages(array $target_phids) { 46 + return id(new HarbormasterBuildLintMessage())->loadAllWhere( 47 + 'buildTargetPHID IN (%Ls) LIMIT 25', 48 + $target_phids); 49 + } 96 50 97 - if ($lint) { 98 - $path_map = mpull($diff->loadChangesets(), 'getID', 'getFilename'); 99 - foreach ($path_map as $path => $id) { 100 - $href = '#C'.$id.'NL'; 51 + protected function newHarbormasterMessageView(array $messages) { 52 + return id(new HarbormasterLintPropertyView()) 53 + ->setLintMessages($messages); 54 + } 101 55 102 - // TODO: When the diff is not the right-hand-size diff, we should 103 - // ideally adjust this URI to be absolute. 104 - 105 - $path_map[$path] = $href; 106 - } 107 - 108 - $view = id(new HarbormasterLintPropertyView()) 109 - ->setPathURIMap($path_map) 110 - ->setLintMessages($lint); 111 - } else { 112 - $view = null; 113 - } 114 - 115 - return array( 116 - $status, 117 - $view, 118 - ); 56 + protected function newModernMessage(array $message) { 57 + return HarbormasterBuildLintMessage::newFromDictionary( 58 + new HarbormasterBuildTarget(), 59 + $this->getModernLintMessageDictionary($message)); 119 60 } 120 61 121 62 public function getWarningsForDetailView() { ··· 141 82 return $warnings; 142 83 } 143 84 144 - private function renderLintStatus(DifferentialDiff $diff) { 85 + protected function renderHarbormasterStatus( 86 + DifferentialDiff $diff, 87 + array $messages) { 88 + 145 89 $colors = array( 146 90 DifferentialLintStatus::LINT_NONE => 'grey', 147 91 DifferentialLintStatus::LINT_OKAY => 'green',
+24 -74
src/applications/differential/customfield/DifferentialUnitField.php
··· 1 1 <?php 2 2 3 3 final class DifferentialUnitField 4 - extends DifferentialCustomField { 4 + extends DifferentialHarbormasterField { 5 5 6 6 public function getFieldKey() { 7 7 return 'differential:unit'; ··· 31 31 return $this->getFieldName(); 32 32 } 33 33 34 - public function renderDiffPropertyViewValue(DifferentialDiff $diff) { 35 - // TODO: See DifferentialLintField. 36 - $keys = array( 34 + protected function getLegacyProperty() { 35 + return 'arc:unit'; 36 + } 37 + 38 + protected function getDiffPropertyKeys() { 39 + return array( 37 40 'arc:unit', 38 41 'arc:unit-excuse', 39 42 ); 40 - 41 - $properties = id(new DifferentialDiffProperty())->loadAllWhere( 42 - 'diffID = %d AND name IN (%Ls)', 43 - $diff->getID(), 44 - $keys); 45 - $properties = mpull($properties, 'getData', 'getName'); 46 - 47 - foreach ($keys as $key) { 48 - $diff->attachProperty($key, idx($properties, $key)); 49 - } 50 - 51 - $status = $this->renderUnitStatus($diff); 52 - 53 - $unit = array(); 54 - 55 - $buildable = $diff->getBuildable(); 56 - if ($buildable) { 57 - $target_phids = array(); 58 - foreach ($buildable->getBuilds() as $build) { 59 - foreach ($build->getBuildTargets() as $target) { 60 - $target_phids[] = $target->getPHID(); 61 - } 62 - } 63 - 64 - $unit = id(new HarbormasterBuildUnitMessage())->loadAllWhere( 65 - 'buildTargetPHID IN (%Ls) LIMIT 25', 66 - $target_phids); 67 - } 68 - 69 - if (!$unit) { 70 - $legacy_unit = $diff->getProperty('arc:unit'); 71 - if ($legacy_unit) { 72 - // Show the top 100 legacy unit messages. 73 - $legacy_unit = array_slice($legacy_unit, 0, 100); 74 - 75 - $target = new HarbormasterBuildTarget(); 76 - foreach ($legacy_unit as $message) { 77 - try { 78 - $modern = HarbormasterBuildUnitMessage::newFromDictionary( 79 - $target, 80 - $this->getModernUnitMessageDictionary($message)); 81 - $unit[] = $modern; 82 - } catch (Exception $ex) { 83 - // Just ignore it if legacy messages aren't formatted like 84 - // we expect. 85 - } 86 - } 87 - } 88 - } 43 + } 89 44 90 - if ($unit) { 91 - $path_map = mpull($diff->loadChangesets(), 'getID', 'getFilename'); 92 - foreach ($path_map as $path => $id) { 93 - $href = '#C'.$id.'NL'; 45 + protected function loadHarbormasterTargetMessages(array $target_phids) { 46 + return id(new HarbormasterBuildUnitMessage())->loadAllWhere( 47 + 'buildTargetPHID IN (%Ls) LIMIT 25', 48 + $target_phids); 49 + } 94 50 95 - // TODO: When the diff is not the right-hand-size diff, we should 96 - // ideally adjust this URI to be absolute. 97 - 98 - $path_map[$path] = $href; 99 - } 100 - 101 - $view = id(new HarbormasterUnitPropertyView()) 102 - ->setPathURIMap($path_map) 103 - ->setUnitMessages($unit); 104 - } else { 105 - $view = null; 106 - } 51 + protected function newModernMessage(array $message) { 52 + return HarbormasterBuildUnitMessage::newFromDictionary( 53 + new HarbormasterBuildTarget(), 54 + $this->getModernUnitMessageDictionary($message)); 55 + } 107 56 108 - return array( 109 - $status, 110 - $view, 111 - ); 57 + protected function newHarbormasterMessageView(array $messages) { 58 + return id(new HarbormasterUnitPropertyView()) 59 + ->setUnitMessages($messages); 112 60 } 113 61 114 62 public function getWarningsForDetailView() { ··· 132 80 return $warnings; 133 81 } 134 82 83 + protected function renderHarbormasterStatus( 84 + DifferentialDiff $diff, 85 + array $messages) { 135 86 136 - private function renderUnitStatus(DifferentialDiff $diff) { 137 87 $colors = array( 138 88 DifferentialUnitStatus::UNIT_NONE => 'grey', 139 89 DifferentialUnitStatus::UNIT_OKAY => 'green',