1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-26 22:48:19 +01:00

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
This commit is contained in:
epriestley 2013-08-02 08:55:13 -07:00
parent 307a41e895
commit 6badb05d64
13 changed files with 101 additions and 65 deletions

View file

@ -596,7 +596,7 @@ phutil_register_library_map(array(
'HarbormasterScratchTable' => 'applications/harbormaster/storage/HarbormasterScratchTable.php', 'HarbormasterScratchTable' => 'applications/harbormaster/storage/HarbormasterScratchTable.php',
'HeraldAction' => 'applications/herald/storage/HeraldAction.php', 'HeraldAction' => 'applications/herald/storage/HeraldAction.php',
'HeraldActionConfig' => 'applications/herald/config/HeraldActionConfig.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', 'HeraldApplyTranscript' => 'applications/herald/storage/transcript/HeraldApplyTranscript.php',
'HeraldCommitAdapter' => 'applications/herald/adapter/HeraldCommitAdapter.php', 'HeraldCommitAdapter' => 'applications/herald/adapter/HeraldCommitAdapter.php',
'HeraldCondition' => 'applications/herald/storage/HeraldCondition.php', 'HeraldCondition' => 'applications/herald/storage/HeraldCondition.php',

View file

@ -232,7 +232,7 @@ final class DifferentialRevisionEditor extends PhabricatorEditor {
$rem_ccs = array(); $rem_ccs = array();
$xscript_phid = null; $xscript_phid = null;
if ($diff) { if ($diff) {
$adapter = new HeraldDifferentialRevisionAdapter( $adapter = HeraldDifferentialRevisionAdapter::newLegacyAdapter(
$revision, $revision,
$diff); $diff);
$adapter->setExplicitCCs($new['ccs']); $adapter->setExplicitCCs($new['ccs']);

View file

@ -8,6 +8,20 @@ abstract class HeraldAdapter {
abstract public function getHeraldField($field_name); abstract public function getHeraldField($field_name);
abstract public function applyHeraldEffects(array $effects); 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) { public static function applyFlagEffect(HeraldEffect $effect, $phid) {
$color = $effect->getTarget(); $color = $effect->getTarget();
@ -48,5 +62,26 @@ abstract class HeraldAdapter {
pht('Added flag.')); 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;
}
} }

View file

@ -17,14 +17,31 @@ final class HeraldCommitAdapter extends HeraldAdapter {
protected $affectedPackages; protected $affectedPackages;
protected $auditNeededPackages; 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, PhabricatorRepository $repository,
PhabricatorRepositoryCommit $commit, PhabricatorRepositoryCommit $commit,
PhabricatorRepositoryCommitData $commit_data) { PhabricatorRepositoryCommitData $commit_data) {
$this->repository = $repository; $object = new HeraldCommitAdapter();
$this->commit = $commit;
$this->commitData = $commit_data; $object->repository = $repository;
$object->commit = $commit;
$object->commitData = $commit_data;
return $object;
} }
public function getPHID() { public function getPHID() {

View file

@ -17,13 +17,30 @@ final class HeraldDifferentialRevisionAdapter extends HeraldAdapter {
protected $affectedPackages; protected $affectedPackages;
protected $changesets; 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, DifferentialRevision $revision,
DifferentialDiff $diff) { DifferentialDiff $diff) {
$object = new HeraldDifferentialRevisionAdapter();
$revision->loadRelationships(); $revision->loadRelationships();
$this->revision = $revision; $object->revision = $revision;
$this->diff = $diff; $object->diff = $diff;
return $object;
} }
public function setExplicitCCs($explicit_ccs) { public function setExplicitCCs($explicit_ccs) {

View file

@ -6,6 +6,14 @@ final class HeraldDryRunAdapter extends HeraldAdapter {
return 0; return 0;
} }
public function isEnabled() {
return false;
}
public function getAdapterContentName() {
return null;
}
public function getHeraldName() { public function getHeraldName() {
return 'Dry Run'; return 'Dry Run';
} }

View file

@ -66,20 +66,6 @@ final class HeraldActionConfig {
self::ACTION_FLAG, self::ACTION_FLAG,
self::ACTION_NOTHING, 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: default:
throw new Exception("Unknown content type '{$content_type}'."); throw new Exception("Unknown content type '{$content_type}'.");
} }

View file

@ -4,18 +4,18 @@ final class HeraldContentTypeConfig {
const CONTENT_TYPE_DIFFERENTIAL = 'differential'; const CONTENT_TYPE_DIFFERENTIAL = 'differential';
const CONTENT_TYPE_COMMIT = 'commit'; const CONTENT_TYPE_COMMIT = 'commit';
const CONTENT_TYPE_MERGE = 'merge';
const CONTENT_TYPE_OWNERS = 'owners';
public static function getContentTypeMap() { public static function getContentTypeMap() {
$map = array( $map = array();
self::CONTENT_TYPE_DIFFERENTIAL => pht('Differential Revisions'),
self::CONTENT_TYPE_COMMIT => pht('Commits'), $adapters = HeraldAdapter::getAllEnabledAdapters();
/* TODO: Deal with this foreach ($adapters as $adapter) {
self::CONTENT_TYPE_MERGE => 'Merge Requests', $type = $adapter->getAdapterContentType();
self::CONTENT_TYPE_OWNERS => 'Owners Changes', $name = $adapter->getAdapterContentName();
*/ $map[$type] = $name;
); }
asort($map);
return $map; return $map;
} }
} }

View file

@ -86,31 +86,6 @@ final class HeraldFieldConfig {
self::FIELD_DIFFERENTIAL_REVIEWERS, self::FIELD_DIFFERENTIAL_REVIEWERS,
self::FIELD_DIFFERENTIAL_CCS, 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: default:
throw new Exception("Unknown content type."); throw new Exception("Unknown content type.");
} }

View file

@ -29,8 +29,6 @@ final class HeraldRepetitionPolicyConfig {
)); ));
case HeraldContentTypeConfig::CONTENT_TYPE_COMMIT: case HeraldContentTypeConfig::CONTENT_TYPE_COMMIT:
case HeraldContentTypeConfig::CONTENT_TYPE_MERGE:
case HeraldContentTypeConfig::CONTENT_TYPE_OWNERS:
return array(); return array();
default: default:

View file

@ -53,14 +53,14 @@ final class HeraldTestConsoleController extends HeraldController {
if (!$errors) { if (!$errors) {
if ($object instanceof DifferentialRevision) { if ($object instanceof DifferentialRevision) {
$adapter = new HeraldDifferentialRevisionAdapter( $adapter = HeraldDifferentialRevisionAdapter::newLegacyAdapter(
$object, $object,
$object->loadActiveDiff()); $object->loadActiveDiff());
} else if ($object instanceof PhabricatorRepositoryCommit) { } else if ($object instanceof PhabricatorRepositoryCommit) {
$data = id(new PhabricatorRepositoryCommitData())->loadOneWhere( $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere(
'commitID = %d', 'commitID = %d',
$object->getID()); $object->getID());
$adapter = new HeraldCommitAdapter( $adapter = HeraldCommitAdapter::newLegacyAdapter(
$repo, $repo,
$object, $object,
$data); $data);

View file

@ -113,7 +113,7 @@ final class HeraldRuleSearchEngine
} }
private function getContentTypeValues() { private function getContentTypeValues() {
return HeraldContentTypeConfig::getContentTypeMap(); return array_fuse(array_keys(HeraldContentTypeConfig::getContentTypeMap()));
} }
private function getRuleTypeOptions() { private function getRuleTypeOptions() {
@ -123,7 +123,7 @@ final class HeraldRuleSearchEngine
} }
private function getRuleTypeValues() { private function getRuleTypeValues() {
return HeraldRuleTypeConfig::getRuleTypeMap(); return array_fuse(array_keys(HeraldRuleTypeConfig::getRuleTypeMap()));
} }
} }

View file

@ -25,7 +25,7 @@ final class PhabricatorRepositoryCommitHeraldWorker
HeraldContentTypeConfig::CONTENT_TYPE_COMMIT, HeraldContentTypeConfig::CONTENT_TYPE_COMMIT,
$commit->getPHID()); $commit->getPHID());
$adapter = new HeraldCommitAdapter( $adapter = HeraldCommitAdapter::newLegacyAdapter(
$repository, $repository,
$commit, $commit,
$data); $data);