diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a94149f67b..bbee64ccbd 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -596,7 +596,7 @@ phutil_register_library_map(array( 'HarbormasterScratchTable' => 'applications/harbormaster/storage/HarbormasterScratchTable.php', 'HeraldAction' => 'applications/herald/storage/HeraldAction.php', 'HeraldActionConfig' => 'applications/herald/config/HeraldActionConfig.php', - 'HeraldAdapter' => 'applications/herald/adapter/HeraldObjectAdapter.php', + 'HeraldAdapter' => 'applications/herald/adapter/HeraldAdapter.php', 'HeraldApplyTranscript' => 'applications/herald/storage/transcript/HeraldApplyTranscript.php', 'HeraldCommitAdapter' => 'applications/herald/adapter/HeraldCommitAdapter.php', 'HeraldCondition' => 'applications/herald/storage/HeraldCondition.php', diff --git a/src/applications/differential/editor/DifferentialRevisionEditor.php b/src/applications/differential/editor/DifferentialRevisionEditor.php index 5bdc91b3b4..e6fd362baf 100644 --- a/src/applications/differential/editor/DifferentialRevisionEditor.php +++ b/src/applications/differential/editor/DifferentialRevisionEditor.php @@ -232,7 +232,7 @@ final class DifferentialRevisionEditor extends PhabricatorEditor { $rem_ccs = array(); $xscript_phid = null; if ($diff) { - $adapter = new HeraldDifferentialRevisionAdapter( + $adapter = HeraldDifferentialRevisionAdapter::newLegacyAdapter( $revision, $diff); $adapter->setExplicitCCs($new['ccs']); diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index 4ad8128582..b5f051ff13 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -8,6 +8,20 @@ abstract class HeraldAdapter { abstract public function getHeraldField($field_name); abstract public function applyHeraldEffects(array $effects); + public function isEnabled() { + return true; + } + + /** + * NOTE: You generally should not override this; it exists to support legacy + * adapters which had hard-coded content types. + */ + public function getAdapterContentType() { + return get_class($this); + } + + abstract public function getAdapterContentName(); + public static function applyFlagEffect(HeraldEffect $effect, $phid) { $color = $effect->getTarget(); @@ -48,5 +62,26 @@ abstract class HeraldAdapter { pht('Added flag.')); } + public static function getAllAdapters() { + static $adapters; + if (!$adapters) { + $adapters = id(new PhutilSymbolLoader()) + ->setAncestorClass(__CLASS__) + ->loadObjects(); + } + return $adapters; + } + + public static function getAllEnabledAdapters() { + $adapters = self::getAllAdapters(); + foreach ($adapters as $key => $adapter) { + if (!$adapter->isEnabled()) { + unset($adapters[$key]); + } + } + return $adapters; + } + + } diff --git a/src/applications/herald/adapter/HeraldCommitAdapter.php b/src/applications/herald/adapter/HeraldCommitAdapter.php index 1944a30d91..ef24261b43 100644 --- a/src/applications/herald/adapter/HeraldCommitAdapter.php +++ b/src/applications/herald/adapter/HeraldCommitAdapter.php @@ -17,14 +17,31 @@ final class HeraldCommitAdapter extends HeraldAdapter { protected $affectedPackages; protected $auditNeededPackages; - public function __construct( + public function isEnabled() { + $app = 'PhabricatorApplicationDiffusion'; + return PhabricatorApplication::isClassInstalled($app); + } + + public function getAdapterContentType() { + return 'commit'; + } + + public function getAdapterContentName() { + return pht('Commits'); + } + + public static function newLegacyAdapter( PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit, PhabricatorRepositoryCommitData $commit_data) { - $this->repository = $repository; - $this->commit = $commit; - $this->commitData = $commit_data; + $object = new HeraldCommitAdapter(); + + $object->repository = $repository; + $object->commit = $commit; + $object->commitData = $commit_data; + + return $object; } public function getPHID() { diff --git a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php index 8e5dcd9015..2c63d025f0 100644 --- a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php +++ b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php @@ -17,13 +17,30 @@ final class HeraldDifferentialRevisionAdapter extends HeraldAdapter { protected $affectedPackages; protected $changesets; - public function __construct( + public function isEnabled() { + $app = 'PhabricatorApplicationDifferential'; + return PhabricatorApplication::isClassInstalled($app); + } + + public function getAdapterContentType() { + return 'differential'; + } + + public function getAdapterContentName() { + return pht('Differential Revisions'); + } + + public static function newLegacyAdapter( DifferentialRevision $revision, DifferentialDiff $diff) { + $object = new HeraldDifferentialRevisionAdapter(); + $revision->loadRelationships(); - $this->revision = $revision; - $this->diff = $diff; + $object->revision = $revision; + $object->diff = $diff; + + return $object; } public function setExplicitCCs($explicit_ccs) { diff --git a/src/applications/herald/adapter/HeraldDryRunAdapter.php b/src/applications/herald/adapter/HeraldDryRunAdapter.php index 3e0882a37d..584e5ca384 100644 --- a/src/applications/herald/adapter/HeraldDryRunAdapter.php +++ b/src/applications/herald/adapter/HeraldDryRunAdapter.php @@ -6,6 +6,14 @@ final class HeraldDryRunAdapter extends HeraldAdapter { return 0; } + public function isEnabled() { + return false; + } + + public function getAdapterContentName() { + return null; + } + public function getHeraldName() { return 'Dry Run'; } diff --git a/src/applications/herald/config/HeraldActionConfig.php b/src/applications/herald/config/HeraldActionConfig.php index 1194fdfcec..3dc9d6b9ef 100644 --- a/src/applications/herald/config/HeraldActionConfig.php +++ b/src/applications/herald/config/HeraldActionConfig.php @@ -66,20 +66,6 @@ final class HeraldActionConfig { self::ACTION_FLAG, self::ACTION_NOTHING, )); - case HeraldContentTypeConfig::CONTENT_TYPE_MERGE: - return array_select_keys( - $map, - array( - self::ACTION_EMAIL, - self::ACTION_NOTHING, - )); - case HeraldContentTypeConfig::CONTENT_TYPE_OWNERS: - return array_select_keys( - $map, - array( - self::ACTION_EMAIL, - self::ACTION_NOTHING, - )); default: throw new Exception("Unknown content type '{$content_type}'."); } diff --git a/src/applications/herald/config/HeraldContentTypeConfig.php b/src/applications/herald/config/HeraldContentTypeConfig.php index 01ea861b67..7b5c9485cc 100644 --- a/src/applications/herald/config/HeraldContentTypeConfig.php +++ b/src/applications/herald/config/HeraldContentTypeConfig.php @@ -4,18 +4,18 @@ final class HeraldContentTypeConfig { const CONTENT_TYPE_DIFFERENTIAL = 'differential'; const CONTENT_TYPE_COMMIT = 'commit'; - const CONTENT_TYPE_MERGE = 'merge'; - const CONTENT_TYPE_OWNERS = 'owners'; public static function getContentTypeMap() { - $map = array( - self::CONTENT_TYPE_DIFFERENTIAL => pht('Differential Revisions'), - self::CONTENT_TYPE_COMMIT => pht('Commits'), -/* TODO: Deal with this - self::CONTENT_TYPE_MERGE => 'Merge Requests', - self::CONTENT_TYPE_OWNERS => 'Owners Changes', -*/ - ); + $map = array(); + + $adapters = HeraldAdapter::getAllEnabledAdapters(); + foreach ($adapters as $adapter) { + $type = $adapter->getAdapterContentType(); + $name = $adapter->getAdapterContentName(); + $map[$type] = $name; + } + + asort($map); return $map; } } diff --git a/src/applications/herald/config/HeraldFieldConfig.php b/src/applications/herald/config/HeraldFieldConfig.php index 8942815102..f7af33c075 100644 --- a/src/applications/herald/config/HeraldFieldConfig.php +++ b/src/applications/herald/config/HeraldFieldConfig.php @@ -86,31 +86,6 @@ final class HeraldFieldConfig { self::FIELD_DIFFERENTIAL_REVIEWERS, self::FIELD_DIFFERENTIAL_CCS, )); - case HeraldContentTypeConfig::CONTENT_TYPE_MERGE: - return array_select_keys( - $map, - array( - self::FIELD_BODY, - self::FIELD_AUTHOR, - self::FIELD_REVIEWER, - self::FIELD_REPOSITORY, - self::FIELD_DIFF_FILE, - self::FIELD_DIFF_CONTENT, - self::FIELD_RULE, - self::FIELD_AFFECTED_PACKAGE, - self::FIELD_AFFECTED_PACKAGE_OWNER, - self::FIELD_DIFFERENTIAL_REVISION, - self::FIELD_DIFFERENTIAL_REVIEWERS, - self::FIELD_DIFFERENTIAL_CCS, - self::FIELD_MERGE_REQUESTER, - )); - case HeraldContentTypeConfig::CONTENT_TYPE_OWNERS: - return array_select_keys( - $map, - array( - self::FIELD_AFFECTED_PACKAGE, - self::FIELD_AFFECTED_PACKAGE_OWNER, - )); default: throw new Exception("Unknown content type."); } diff --git a/src/applications/herald/config/HeraldRepetitionPolicyConfig.php b/src/applications/herald/config/HeraldRepetitionPolicyConfig.php index 2e643021d6..43fd2b214c 100644 --- a/src/applications/herald/config/HeraldRepetitionPolicyConfig.php +++ b/src/applications/herald/config/HeraldRepetitionPolicyConfig.php @@ -29,8 +29,6 @@ final class HeraldRepetitionPolicyConfig { )); case HeraldContentTypeConfig::CONTENT_TYPE_COMMIT: - case HeraldContentTypeConfig::CONTENT_TYPE_MERGE: - case HeraldContentTypeConfig::CONTENT_TYPE_OWNERS: return array(); default: diff --git a/src/applications/herald/controller/HeraldTestConsoleController.php b/src/applications/herald/controller/HeraldTestConsoleController.php index e982144add..5eb8fcce3f 100644 --- a/src/applications/herald/controller/HeraldTestConsoleController.php +++ b/src/applications/herald/controller/HeraldTestConsoleController.php @@ -53,14 +53,14 @@ final class HeraldTestConsoleController extends HeraldController { if (!$errors) { if ($object instanceof DifferentialRevision) { - $adapter = new HeraldDifferentialRevisionAdapter( + $adapter = HeraldDifferentialRevisionAdapter::newLegacyAdapter( $object, $object->loadActiveDiff()); } else if ($object instanceof PhabricatorRepositoryCommit) { $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere( 'commitID = %d', $object->getID()); - $adapter = new HeraldCommitAdapter( + $adapter = HeraldCommitAdapter::newLegacyAdapter( $repo, $object, $data); diff --git a/src/applications/herald/query/HeraldRuleSearchEngine.php b/src/applications/herald/query/HeraldRuleSearchEngine.php index d516defceb..fbde424fdc 100644 --- a/src/applications/herald/query/HeraldRuleSearchEngine.php +++ b/src/applications/herald/query/HeraldRuleSearchEngine.php @@ -113,7 +113,7 @@ final class HeraldRuleSearchEngine } private function getContentTypeValues() { - return HeraldContentTypeConfig::getContentTypeMap(); + return array_fuse(array_keys(HeraldContentTypeConfig::getContentTypeMap())); } private function getRuleTypeOptions() { @@ -123,7 +123,7 @@ final class HeraldRuleSearchEngine } private function getRuleTypeValues() { - return HeraldRuleTypeConfig::getRuleTypeMap(); + return array_fuse(array_keys(HeraldRuleTypeConfig::getRuleTypeMap())); } } diff --git a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php index 64803aed7a..1230a05137 100644 --- a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php +++ b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php @@ -25,7 +25,7 @@ final class PhabricatorRepositoryCommitHeraldWorker HeraldContentTypeConfig::CONTENT_TYPE_COMMIT, $commit->getPHID()); - $adapter = new HeraldCommitAdapter( + $adapter = HeraldCommitAdapter::newLegacyAdapter( $repository, $commit, $data);