1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-11 15:21:03 +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',
'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',

View file

@ -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']);

View file

@ -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;
}
}

View file

@ -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() {

View file

@ -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) {

View file

@ -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';
}

View file

@ -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}'.");
}

View file

@ -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;
}
}

View file

@ -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.");
}

View file

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

View file

@ -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);

View file

@ -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()));
}
}

View file

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