diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index bbee64ccbd..2c3dc027e3 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -635,7 +635,6 @@ phutil_register_library_map(array( 'HeraldTranscript' => 'applications/herald/storage/transcript/HeraldTranscript.php', 'HeraldTranscriptController' => 'applications/herald/controller/HeraldTranscriptController.php', 'HeraldTranscriptListController' => 'applications/herald/controller/HeraldTranscriptListController.php', - 'HeraldValueTypeConfig' => 'applications/herald/config/HeraldValueTypeConfig.php', 'Javelin' => 'infrastructure/javelin/Javelin.php', 'JavelinReactorExample' => 'applications/uiexample/examples/JavelinReactorExample.php', 'JavelinUIExample' => 'applications/uiexample/examples/JavelinUIExample.php', diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index 871abce5a3..2913fd747d 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -16,23 +16,41 @@ abstract class HeraldAdapter { const FIELD_AFFECTED_PACKAGE = 'affected-package'; const FIELD_AFFECTED_PACKAGE_OWNER = 'affected-package-owner'; - const CONDITION_CONTAINS = 'contains'; - const CONDITION_NOT_CONTAINS = '!contains'; - const CONDITION_IS = 'is'; - const CONDITION_IS_NOT = '!is'; - const CONDITION_IS_ANY = 'isany'; - const CONDITION_IS_NOT_ANY = '!isany'; - const CONDITION_INCLUDE_ALL = 'all'; - const CONDITION_INCLUDE_ANY = 'any'; - const CONDITION_INCLUDE_NONE = 'none'; - const CONDITION_IS_ME = 'me'; - const CONDITION_IS_NOT_ME = '!me'; - const CONDITION_REGEXP = 'regexp'; - const CONDITION_RULE = 'conditions'; - const CONDITION_NOT_RULE = '!conditions'; - const CONDITION_EXISTS = 'exists'; - const CONDITION_NOT_EXISTS = '!exists'; - const CONDITION_REGEXP_PAIR = 'regexp-pair'; + const CONDITION_CONTAINS = 'contains'; + const CONDITION_NOT_CONTAINS = '!contains'; + const CONDITION_IS = 'is'; + const CONDITION_IS_NOT = '!is'; + const CONDITION_IS_ANY = 'isany'; + const CONDITION_IS_NOT_ANY = '!isany'; + const CONDITION_INCLUDE_ALL = 'all'; + const CONDITION_INCLUDE_ANY = 'any'; + const CONDITION_INCLUDE_NONE = 'none'; + const CONDITION_IS_ME = 'me'; + const CONDITION_IS_NOT_ME = '!me'; + const CONDITION_REGEXP = 'regexp'; + const CONDITION_RULE = 'conditions'; + const CONDITION_NOT_RULE = '!conditions'; + const CONDITION_EXISTS = 'exists'; + const CONDITION_NOT_EXISTS = '!exists'; + const CONDITION_REGEXP_PAIR = 'regexp-pair'; + + const ACTION_ADD_CC = 'addcc'; + const ACTION_REMOVE_CC = 'remcc'; + const ACTION_EMAIL = 'email'; + const ACTION_NOTHING = 'nothing'; + const ACTION_AUDIT = 'audit'; + const ACTION_FLAG = 'flag'; + + const VALUE_TEXT = 'text'; + const VALUE_NONE = 'none'; + const VALUE_EMAIL = 'email'; + const VALUE_USER = 'user'; + const VALUE_TAG = 'tag'; + const VALUE_RULE = 'rule'; + const VALUE_REPOSITORY = 'repository'; + const VALUE_OWNERS_PACKAGE = 'package'; + const VALUE_PROJECT = 'project'; + const VALUE_FLAG_COLOR = 'flagcolor'; abstract public function getPHID(); abstract public function getHeraldName(); @@ -53,6 +71,11 @@ abstract class HeraldAdapter { } abstract public function getAdapterContentName(); + + +/* -( Fields )------------------------------------------------------------- */ + + abstract public function getFields(); public function getFieldNameMap() { @@ -74,6 +97,10 @@ abstract class HeraldAdapter { ); } + +/* -( Conditions )--------------------------------------------------------- */ + + public function getConditionNameMap() { return array( self::CONDITION_CONTAINS => pht('contains'), @@ -151,6 +178,120 @@ abstract class HeraldAdapter { } +/* -( Actions )------------------------------------------------------------ */ + + abstract public function getActions($rule_type); + + public function getActionNameMap($rule_type) { + switch ($rule_type) { + case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: + return array( + self::ACTION_NOTHING => pht('Do nothing'), + self::ACTION_ADD_CC => pht('Add emails to CC'), + self::ACTION_REMOVE_CC => pht('Remove emails from CC'), + self::ACTION_EMAIL => pht('Send an email to'), + self::ACTION_AUDIT => pht('Trigger an Audit by'), + ); + case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: + return array( + self::ACTION_NOTHING => pht('Do nothing'), + self::ACTION_ADD_CC => pht('Add me to CC'), + self::ACTION_REMOVE_CC => pht('Remove me from CC'), + self::ACTION_EMAIL => pht('Send me an email'), + self::ACTION_AUDIT => pht('Trigger an Audit by me'), + self::ACTION_FLAG => pht('Mark with flag'), + ); + default: + throw new Exception("Unknown rule type '{$rule_type}'!"); + } + } + + +/* -( Values )------------------------------------------------------------- */ + + + public function getValueTypeForFieldAndCondition($field, $condition) { + switch ($condition) { + case self::CONDITION_CONTAINS: + case self::CONDITION_NOT_CONTAINS: + case self::CONDITION_IS: + case self::CONDITION_IS_NOT: + case self::CONDITION_REGEXP: + case self::CONDITION_REGEXP_PAIR: + return self::VALUE_TEXT; + case self::CONDITION_IS_ANY: + case self::CONDITION_IS_NOT_ANY: + switch ($field) { + case self::FIELD_REPOSITORY: + return self::VALUE_REPOSITORY; + default: + return self::VALUE_USER; + } + break; + case self::CONDITION_INCLUDE_ALL: + case self::CONDITION_INCLUDE_ANY: + case self::CONDITION_INCLUDE_NONE: + switch ($field) { + case self::FIELD_REPOSITORY: + return self::VALUE_REPOSITORY; + case self::FIELD_CC: + return self::VALUE_EMAIL; + case self::FIELD_TAGS: + return self::VALUE_TAG; + case self::FIELD_AFFECTED_PACKAGE: + return self::VALUE_OWNERS_PACKAGE; + default: + return self::VALUE_USER; + } + break; + case self::CONDITION_IS_ME: + case self::CONDITION_IS_NOT_ME: + case self::CONDITION_EXISTS: + case self::CONDITION_NOT_EXISTS: + return self::VALUE_NONE; + case self::CONDITION_RULE: + case self::CONDITION_NOT_RULE: + return self::VALUE_RULE; + default: + throw new Exception("Unknown condition '{$condition}'."); + } + } + + public static function getValueTypeForAction($action, $rule_type) { + $is_personal = ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); + + if ($is_personal) { + switch ($action) { + case self::ACTION_ADD_CC: + case self::ACTION_REMOVE_CC: + case self::ACTION_EMAIL: + case self::ACTION_NOTHING: + case self::ACTION_AUDIT: + return self::VALUE_NONE; + case self::ACTION_FLAG: + return self::VALUE_FLAG_COLOR; + default: + throw new Exception("Unknown or invalid action '{$action}'."); + } + } else { + switch ($action) { + case self::ACTION_ADD_CC: + case self::ACTION_REMOVE_CC: + case self::ACTION_EMAIL: + return self::VALUE_EMAIL; + case self::ACTION_NOTHING: + return self::VALUE_NONE; + case self::ACTION_AUDIT: + return self::VALUE_PROJECT; + case self::ACTION_FLAG: + return self::VALUE_FLAG_COLOR; + default: + throw new Exception("Unknown or invalid action '{$action}'."); + } + } + } + + public static function applyFlagEffect(HeraldEffect $effect, $phid) { $color = $effect->getTarget(); diff --git a/src/applications/herald/adapter/HeraldCommitAdapter.php b/src/applications/herald/adapter/HeraldCommitAdapter.php index 68e0650409..e025e1c2ec 100644 --- a/src/applications/herald/adapter/HeraldCommitAdapter.php +++ b/src/applications/herald/adapter/HeraldCommitAdapter.php @@ -86,6 +86,36 @@ final class HeraldCommitAdapter extends HeraldAdapter { return parent::getConditionsForField($field); } + public function getActions($rule_type) { + switch ($rule_type) { + case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: + return array( + self::ACTION_ADD_CC, + self::ACTION_REMOVE_CC, + self::ACTION_EMAIL, + self::ACTION_NOTHING, + ); + case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: + return array( + self::ACTION_ADD_CC, + self::ACTION_REMOVE_CC, + self::ACTION_EMAIL, + self::ACTION_NOTHING, + ); + } + } + + public function getValueTypeForFieldAndCondition($field, $condition) { + switch ($field) { + case self::FIELD_DIFFERENTIAL_CCS: + return self::VALUE_EMAIL; + case self::FIELD_NEED_AUDIT_FOR_PACKAGE: + return self::VALUE_OWNERS_PACKAGE; + } + + return parent::getValueTypeForFieldAndCondition($field, $condition); + } + public static function newLegacyAdapter( PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit, diff --git a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php index 8483da7a38..885c727f9b 100644 --- a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php +++ b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php @@ -242,6 +242,25 @@ final class HeraldDifferentialRevisionAdapter extends HeraldAdapter { } } + public function getActions($rule_type) { + switch ($rule_type) { + case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: + return array( + self::ACTION_ADD_CC, + self::ACTION_REMOVE_CC, + self::ACTION_EMAIL, + self::ACTION_NOTHING, + ); + case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: + return array( + self::ACTION_ADD_CC, + self::ACTION_REMOVE_CC, + self::ACTION_EMAIL, + self::ACTION_NOTHING, + ); + } + } + public function applyHeraldEffects(array $effects) { assert_instances_of($effects, 'HeraldEffect'); diff --git a/src/applications/herald/adapter/HeraldDryRunAdapter.php b/src/applications/herald/adapter/HeraldDryRunAdapter.php index 179d375314..fc644add16 100644 --- a/src/applications/herald/adapter/HeraldDryRunAdapter.php +++ b/src/applications/herald/adapter/HeraldDryRunAdapter.php @@ -30,6 +30,10 @@ final class HeraldDryRunAdapter extends HeraldAdapter { return array(); } + public function getActions($rule_type) { + return array(); + } + public function applyHeraldEffects(array $effects) { assert_instances_of($effects, 'HeraldEffect'); $results = array(); diff --git a/src/applications/herald/config/HeraldActionConfig.php b/src/applications/herald/config/HeraldActionConfig.php index 3dc9d6b9ef..feee86d955 100644 --- a/src/applications/herald/config/HeraldActionConfig.php +++ b/src/applications/herald/config/HeraldActionConfig.php @@ -9,6 +9,7 @@ final class HeraldActionConfig { const ACTION_AUDIT = 'audit'; const ACTION_FLAG = 'flag'; + // TODO: Remove; still used by transcripts. public static function getActionMessageMapForRuleType($rule_type) { $generic_mappings = array( self::ACTION_NOTHING => pht('Do nothing'), @@ -43,6 +44,7 @@ final class HeraldActionConfig { return $specific_mappings + $generic_mappings; } + // TODO: Remove; still used by transcripts. public static function getActionMessageMap($content_type, $rule_type) { $map = self::getActionMessageMapForRuleType($rule_type); diff --git a/src/applications/herald/config/HeraldValueTypeConfig.php b/src/applications/herald/config/HeraldValueTypeConfig.php deleted file mode 100644 index 15bf939715..0000000000 --- a/src/applications/herald/config/HeraldValueTypeConfig.php +++ /dev/null @@ -1,98 +0,0 @@ -getFieldNameMap(); $all_conditions = $adapter->getConditionNameMap(); + $all_actions = $adapter->getActionNameMap($rule->getRuleType()); $fields = $adapter->getFields(); $field_map = array_select_keys($all_fields, $fields); + $actions = $adapter->getActions($rule->getRuleType()); + $action_map = array_select_keys($all_actions, $actions); + $config_info = array(); $config_info['fields'] = $field_map; $config_info['conditions'] = $all_conditions; + $config_info['actions'] = $action_map; + foreach ($config_info['fields'] as $field => $name) { $field_conditions = $adapter->getConditionsForField($field); $config_info['conditionMap'][$field] = $field_conditions; @@ -403,23 +409,19 @@ final class HeraldRuleController extends HeraldController { foreach ($config_info['fields'] as $field => $fname) { foreach ($config_info['conditionMap'][$field] as $condition) { - $config_info['values'][$field][$condition] = - HeraldValueTypeConfig::getValueTypeForFieldAndCondition( - $field, - $condition); + $value_type = $adapter->getValueTypeForFieldAndCondition( + $field, + $condition); + $config_info['values'][$field][$condition] = $value_type; } } - $config_info['actions'] = - HeraldActionConfig::getActionMessageMap($rule->getContentType(), - $rule->getRuleType()); - $config_info['rule_type'] = $rule->getRuleType(); foreach ($config_info['actions'] as $action => $name) { - $config_info['targets'][$action] = - HeraldValueTypeConfig::getValueTypeForAction($action, - $rule->getRuleType()); + $config_info['targets'][$action] = $adapter->getValueTypeForAction( + $action, + $rule->getRuleType()); } Javelin::initBehavior(