mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Move most Herald actions and values into dynamic adapters
Summary: Ref T2769. Shift the bulk of value and action config into Adapters. Test Plan: Viewed and edited Herald list and rules. Reviewers: btrahan Reviewed By: btrahan CC: aran, vrana Maniphest Tasks: T2769 Differential Revision: https://secure.phabricator.com/D6660
This commit is contained in:
parent
2e87f9f53c
commit
9c637604a2
8 changed files with 226 additions and 127 deletions
|
@ -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',
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class HeraldValueTypeConfig {
|
||||
|
||||
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';
|
||||
|
||||
public static function getValueTypeForFieldAndCondition($field, $condition) {
|
||||
switch ($condition) {
|
||||
case HeraldConditionConfig::CONDITION_CONTAINS:
|
||||
case HeraldConditionConfig::CONDITION_NOT_CONTAINS:
|
||||
case HeraldConditionConfig::CONDITION_IS:
|
||||
case HeraldConditionConfig::CONDITION_IS_NOT:
|
||||
case HeraldConditionConfig::CONDITION_REGEXP:
|
||||
case HeraldConditionConfig::CONDITION_REGEXP_PAIR:
|
||||
return self::VALUE_TEXT;
|
||||
case HeraldConditionConfig::CONDITION_IS_ANY:
|
||||
case HeraldConditionConfig::CONDITION_IS_NOT_ANY:
|
||||
switch ($field) {
|
||||
case HeraldFieldConfig::FIELD_REPOSITORY:
|
||||
return self::VALUE_REPOSITORY;
|
||||
default:
|
||||
return self::VALUE_USER;
|
||||
}
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_INCLUDE_ALL:
|
||||
case HeraldConditionConfig::CONDITION_INCLUDE_ANY:
|
||||
case HeraldConditionConfig::CONDITION_INCLUDE_NONE:
|
||||
switch ($field) {
|
||||
case HeraldFieldConfig::FIELD_REPOSITORY:
|
||||
return self::VALUE_REPOSITORY;
|
||||
case HeraldFieldConfig::FIELD_CC:
|
||||
case HeraldFieldConfig::FIELD_DIFFERENTIAL_CCS:
|
||||
return self::VALUE_EMAIL;
|
||||
case HeraldFieldConfig::FIELD_TAGS:
|
||||
return self::VALUE_TAG;
|
||||
case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE:
|
||||
case HeraldFieldConfig::FIELD_NEED_AUDIT_FOR_PACKAGE:
|
||||
return self::VALUE_OWNERS_PACKAGE;
|
||||
default:
|
||||
return self::VALUE_USER;
|
||||
}
|
||||
break;
|
||||
case HeraldConditionConfig::CONDITION_IS_ME:
|
||||
case HeraldConditionConfig::CONDITION_IS_NOT_ME:
|
||||
case HeraldConditionConfig::CONDITION_EXISTS:
|
||||
case HeraldConditionConfig::CONDITION_NOT_EXISTS:
|
||||
return self::VALUE_NONE;
|
||||
case HeraldConditionConfig::CONDITION_RULE:
|
||||
case HeraldConditionConfig::CONDITION_NOT_RULE:
|
||||
return self::VALUE_RULE;
|
||||
default:
|
||||
throw new Exception("Unknown condition.");
|
||||
}
|
||||
}
|
||||
|
||||
public static function getValueTypeForAction($action, $rule_type) {
|
||||
$is_personal = ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL);
|
||||
|
||||
if ($is_personal) {
|
||||
switch ($action) {
|
||||
case HeraldActionConfig::ACTION_ADD_CC:
|
||||
case HeraldActionConfig::ACTION_REMOVE_CC:
|
||||
case HeraldActionConfig::ACTION_EMAIL:
|
||||
case HeraldActionConfig::ACTION_NOTHING:
|
||||
case HeraldActionConfig::ACTION_AUDIT:
|
||||
return self::VALUE_NONE;
|
||||
case HeraldActionConfig::ACTION_FLAG:
|
||||
return self::VALUE_FLAG_COLOR;
|
||||
default:
|
||||
throw new Exception("Unknown or invalid action '{$action}'.");
|
||||
}
|
||||
} else {
|
||||
switch ($action) {
|
||||
case HeraldActionConfig::ACTION_ADD_CC:
|
||||
case HeraldActionConfig::ACTION_REMOVE_CC:
|
||||
case HeraldActionConfig::ACTION_EMAIL:
|
||||
return self::VALUE_EMAIL;
|
||||
case HeraldActionConfig::ACTION_NOTHING:
|
||||
return self::VALUE_NONE;
|
||||
case HeraldActionConfig::ACTION_AUDIT:
|
||||
return self::VALUE_PROJECT;
|
||||
case HeraldActionConfig::ACTION_FLAG:
|
||||
return self::VALUE_FLAG_COLOR;
|
||||
default:
|
||||
throw new Exception("Unknown or invalid action '{$action}'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -389,13 +389,19 @@ final class HeraldRuleController extends HeraldController {
|
|||
|
||||
$all_fields = $adapter->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(
|
||||
|
|
Loading…
Reference in a new issue