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

Make Herald adapters provide content types

Summary:
Ref T2769. Get content types out of hard-coded config and into dynamic adapters.

This removes the "MERGE" and "OWNERS" content types, which were vestigal. These needs are likely better addressed through subscriptions/transactions, and are obsolete, and haven't existed for 2+ years and no one has asked for them to be restored.

Test Plan: Mostly a bunch of grep. Viewed rule list, rule edit. Edited a revision.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2769

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

+101 -65
+1 -1
src/__phutil_library_map__.php
··· 596 596 'HarbormasterScratchTable' => 'applications/harbormaster/storage/HarbormasterScratchTable.php', 597 597 'HeraldAction' => 'applications/herald/storage/HeraldAction.php', 598 598 'HeraldActionConfig' => 'applications/herald/config/HeraldActionConfig.php', 599 - 'HeraldAdapter' => 'applications/herald/adapter/HeraldObjectAdapter.php', 599 + 'HeraldAdapter' => 'applications/herald/adapter/HeraldAdapter.php', 600 600 'HeraldApplyTranscript' => 'applications/herald/storage/transcript/HeraldApplyTranscript.php', 601 601 'HeraldCommitAdapter' => 'applications/herald/adapter/HeraldCommitAdapter.php', 602 602 'HeraldCondition' => 'applications/herald/storage/HeraldCondition.php',
+1 -1
src/applications/differential/editor/DifferentialRevisionEditor.php
··· 232 232 $rem_ccs = array(); 233 233 $xscript_phid = null; 234 234 if ($diff) { 235 - $adapter = new HeraldDifferentialRevisionAdapter( 235 + $adapter = HeraldDifferentialRevisionAdapter::newLegacyAdapter( 236 236 $revision, 237 237 $diff); 238 238 $adapter->setExplicitCCs($new['ccs']);
+35
src/applications/herald/adapter/HeraldAdapter.php
··· 8 8 abstract public function getHeraldField($field_name); 9 9 abstract public function applyHeraldEffects(array $effects); 10 10 11 + public function isEnabled() { 12 + return true; 13 + } 14 + 15 + /** 16 + * NOTE: You generally should not override this; it exists to support legacy 17 + * adapters which had hard-coded content types. 18 + */ 19 + public function getAdapterContentType() { 20 + return get_class($this); 21 + } 22 + 23 + abstract public function getAdapterContentName(); 24 + 11 25 public static function applyFlagEffect(HeraldEffect $effect, $phid) { 12 26 $color = $effect->getTarget(); 13 27 ··· 47 61 true, 48 62 pht('Added flag.')); 49 63 } 64 + 65 + public static function getAllAdapters() { 66 + static $adapters; 67 + if (!$adapters) { 68 + $adapters = id(new PhutilSymbolLoader()) 69 + ->setAncestorClass(__CLASS__) 70 + ->loadObjects(); 71 + } 72 + return $adapters; 73 + } 74 + 75 + public static function getAllEnabledAdapters() { 76 + $adapters = self::getAllAdapters(); 77 + foreach ($adapters as $key => $adapter) { 78 + if (!$adapter->isEnabled()) { 79 + unset($adapters[$key]); 80 + } 81 + } 82 + return $adapters; 83 + } 84 + 50 85 51 86 } 52 87
+21 -4
src/applications/herald/adapter/HeraldCommitAdapter.php
··· 17 17 protected $affectedPackages; 18 18 protected $auditNeededPackages; 19 19 20 - public function __construct( 20 + public function isEnabled() { 21 + $app = 'PhabricatorApplicationDiffusion'; 22 + return PhabricatorApplication::isClassInstalled($app); 23 + } 24 + 25 + public function getAdapterContentType() { 26 + return 'commit'; 27 + } 28 + 29 + public function getAdapterContentName() { 30 + return pht('Commits'); 31 + } 32 + 33 + public static function newLegacyAdapter( 21 34 PhabricatorRepository $repository, 22 35 PhabricatorRepositoryCommit $commit, 23 36 PhabricatorRepositoryCommitData $commit_data) { 24 37 25 - $this->repository = $repository; 26 - $this->commit = $commit; 27 - $this->commitData = $commit_data; 38 + $object = new HeraldCommitAdapter(); 39 + 40 + $object->repository = $repository; 41 + $object->commit = $commit; 42 + $object->commitData = $commit_data; 43 + 44 + return $object; 28 45 } 29 46 30 47 public function getPHID() {
+20 -3
src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php
··· 17 17 protected $affectedPackages; 18 18 protected $changesets; 19 19 20 - public function __construct( 20 + public function isEnabled() { 21 + $app = 'PhabricatorApplicationDifferential'; 22 + return PhabricatorApplication::isClassInstalled($app); 23 + } 24 + 25 + public function getAdapterContentType() { 26 + return 'differential'; 27 + } 28 + 29 + public function getAdapterContentName() { 30 + return pht('Differential Revisions'); 31 + } 32 + 33 + public static function newLegacyAdapter( 21 34 DifferentialRevision $revision, 22 35 DifferentialDiff $diff) { 23 36 37 + $object = new HeraldDifferentialRevisionAdapter(); 38 + 24 39 $revision->loadRelationships(); 25 - $this->revision = $revision; 26 - $this->diff = $diff; 40 + $object->revision = $revision; 41 + $object->diff = $diff; 42 + 43 + return $object; 27 44 } 28 45 29 46 public function setExplicitCCs($explicit_ccs) {
+8
src/applications/herald/adapter/HeraldDryRunAdapter.php
··· 6 6 return 0; 7 7 } 8 8 9 + public function isEnabled() { 10 + return false; 11 + } 12 + 13 + public function getAdapterContentName() { 14 + return null; 15 + } 16 + 9 17 public function getHeraldName() { 10 18 return 'Dry Run'; 11 19 }
-14
src/applications/herald/config/HeraldActionConfig.php
··· 66 66 self::ACTION_FLAG, 67 67 self::ACTION_NOTHING, 68 68 )); 69 - case HeraldContentTypeConfig::CONTENT_TYPE_MERGE: 70 - return array_select_keys( 71 - $map, 72 - array( 73 - self::ACTION_EMAIL, 74 - self::ACTION_NOTHING, 75 - )); 76 - case HeraldContentTypeConfig::CONTENT_TYPE_OWNERS: 77 - return array_select_keys( 78 - $map, 79 - array( 80 - self::ACTION_EMAIL, 81 - self::ACTION_NOTHING, 82 - )); 83 69 default: 84 70 throw new Exception("Unknown content type '{$content_type}'."); 85 71 }
+10 -10
src/applications/herald/config/HeraldContentTypeConfig.php
··· 4 4 5 5 const CONTENT_TYPE_DIFFERENTIAL = 'differential'; 6 6 const CONTENT_TYPE_COMMIT = 'commit'; 7 - const CONTENT_TYPE_MERGE = 'merge'; 8 - const CONTENT_TYPE_OWNERS = 'owners'; 9 7 10 8 public static function getContentTypeMap() { 11 - $map = array( 12 - self::CONTENT_TYPE_DIFFERENTIAL => pht('Differential Revisions'), 13 - self::CONTENT_TYPE_COMMIT => pht('Commits'), 14 - /* TODO: Deal with this 15 - self::CONTENT_TYPE_MERGE => 'Merge Requests', 16 - self::CONTENT_TYPE_OWNERS => 'Owners Changes', 17 - */ 18 - ); 9 + $map = array(); 10 + 11 + $adapters = HeraldAdapter::getAllEnabledAdapters(); 12 + foreach ($adapters as $adapter) { 13 + $type = $adapter->getAdapterContentType(); 14 + $name = $adapter->getAdapterContentName(); 15 + $map[$type] = $name; 16 + } 17 + 18 + asort($map); 19 19 return $map; 20 20 } 21 21 }
-25
src/applications/herald/config/HeraldFieldConfig.php
··· 86 86 self::FIELD_DIFFERENTIAL_REVIEWERS, 87 87 self::FIELD_DIFFERENTIAL_CCS, 88 88 )); 89 - case HeraldContentTypeConfig::CONTENT_TYPE_MERGE: 90 - return array_select_keys( 91 - $map, 92 - array( 93 - self::FIELD_BODY, 94 - self::FIELD_AUTHOR, 95 - self::FIELD_REVIEWER, 96 - self::FIELD_REPOSITORY, 97 - self::FIELD_DIFF_FILE, 98 - self::FIELD_DIFF_CONTENT, 99 - self::FIELD_RULE, 100 - self::FIELD_AFFECTED_PACKAGE, 101 - self::FIELD_AFFECTED_PACKAGE_OWNER, 102 - self::FIELD_DIFFERENTIAL_REVISION, 103 - self::FIELD_DIFFERENTIAL_REVIEWERS, 104 - self::FIELD_DIFFERENTIAL_CCS, 105 - self::FIELD_MERGE_REQUESTER, 106 - )); 107 - case HeraldContentTypeConfig::CONTENT_TYPE_OWNERS: 108 - return array_select_keys( 109 - $map, 110 - array( 111 - self::FIELD_AFFECTED_PACKAGE, 112 - self::FIELD_AFFECTED_PACKAGE_OWNER, 113 - )); 114 89 default: 115 90 throw new Exception("Unknown content type."); 116 91 }
-2
src/applications/herald/config/HeraldRepetitionPolicyConfig.php
··· 29 29 )); 30 30 31 31 case HeraldContentTypeConfig::CONTENT_TYPE_COMMIT: 32 - case HeraldContentTypeConfig::CONTENT_TYPE_MERGE: 33 - case HeraldContentTypeConfig::CONTENT_TYPE_OWNERS: 34 32 return array(); 35 33 36 34 default:
+2 -2
src/applications/herald/controller/HeraldTestConsoleController.php
··· 53 53 54 54 if (!$errors) { 55 55 if ($object instanceof DifferentialRevision) { 56 - $adapter = new HeraldDifferentialRevisionAdapter( 56 + $adapter = HeraldDifferentialRevisionAdapter::newLegacyAdapter( 57 57 $object, 58 58 $object->loadActiveDiff()); 59 59 } else if ($object instanceof PhabricatorRepositoryCommit) { 60 60 $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere( 61 61 'commitID = %d', 62 62 $object->getID()); 63 - $adapter = new HeraldCommitAdapter( 63 + $adapter = HeraldCommitAdapter::newLegacyAdapter( 64 64 $repo, 65 65 $object, 66 66 $data);
+2 -2
src/applications/herald/query/HeraldRuleSearchEngine.php
··· 113 113 } 114 114 115 115 private function getContentTypeValues() { 116 - return HeraldContentTypeConfig::getContentTypeMap(); 116 + return array_fuse(array_keys(HeraldContentTypeConfig::getContentTypeMap())); 117 117 } 118 118 119 119 private function getRuleTypeOptions() { ··· 123 123 } 124 124 125 125 private function getRuleTypeValues() { 126 - return HeraldRuleTypeConfig::getRuleTypeMap(); 126 + return array_fuse(array_keys(HeraldRuleTypeConfig::getRuleTypeMap())); 127 127 } 128 128 129 129 }
+1 -1
src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php
··· 25 25 HeraldContentTypeConfig::CONTENT_TYPE_COMMIT, 26 26 $commit->getPHID()); 27 27 28 - $adapter = new HeraldCommitAdapter( 28 + $adapter = HeraldCommitAdapter::newLegacyAdapter( 29 29 $repository, 30 30 $commit, 31 31 $data);