Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/adapter/HeraldAdapter.php
Show All 23 Lines | abstract class HeraldAdapter extends Phobject { | ||||
const FIELD_DIFFERENTIAL_REVISION = 'differential-revision'; | const FIELD_DIFFERENTIAL_REVISION = 'differential-revision'; | ||||
const FIELD_DIFFERENTIAL_REVIEWERS = 'differential-reviewers'; | const FIELD_DIFFERENTIAL_REVIEWERS = 'differential-reviewers'; | ||||
const FIELD_DIFFERENTIAL_CCS = 'differential-ccs'; | const FIELD_DIFFERENTIAL_CCS = 'differential-ccs'; | ||||
const FIELD_DIFFERENTIAL_ACCEPTED = 'differential-accepted'; | const FIELD_DIFFERENTIAL_ACCEPTED = 'differential-accepted'; | ||||
const FIELD_IS_MERGE_COMMIT = 'is-merge-commit'; | const FIELD_IS_MERGE_COMMIT = 'is-merge-commit'; | ||||
const FIELD_BRANCHES = 'branches'; | const FIELD_BRANCHES = 'branches'; | ||||
const FIELD_AUTHOR_RAW = 'author-raw'; | const FIELD_AUTHOR_RAW = 'author-raw'; | ||||
const FIELD_COMMITTER_RAW = 'committer-raw'; | const FIELD_COMMITTER_RAW = 'committer-raw'; | ||||
const FIELD_TASK_PRIORITY = 'taskpriority'; | |||||
const FIELD_TASK_STATUS = 'taskstatus'; | |||||
const FIELD_PUSHER_IS_COMMITTER = 'pusher-is-committer'; | const FIELD_PUSHER_IS_COMMITTER = 'pusher-is-committer'; | ||||
const FIELD_PATH = 'path'; | const FIELD_PATH = 'path'; | ||||
const CONDITION_CONTAINS = 'contains'; | const CONDITION_CONTAINS = 'contains'; | ||||
const CONDITION_NOT_CONTAINS = '!contains'; | const CONDITION_NOT_CONTAINS = '!contains'; | ||||
const CONDITION_IS = 'is'; | const CONDITION_IS = 'is'; | ||||
const CONDITION_IS_NOT = '!is'; | const CONDITION_IS_NOT = '!is'; | ||||
const CONDITION_IS_ANY = 'isany'; | const CONDITION_IS_ANY = 'isany'; | ||||
▲ Show 20 Lines • Show All 336 Lines • ▼ Show 20 Lines | return $map + array( | ||||
self::FIELD_DIFFERENTIAL_REVIEWERS => pht('Differential reviewers'), | self::FIELD_DIFFERENTIAL_REVIEWERS => pht('Differential reviewers'), | ||||
self::FIELD_DIFFERENTIAL_CCS => pht('Differential CCs'), | self::FIELD_DIFFERENTIAL_CCS => pht('Differential CCs'), | ||||
self::FIELD_DIFFERENTIAL_ACCEPTED | self::FIELD_DIFFERENTIAL_ACCEPTED | ||||
=> pht('Accepted Differential revision'), | => pht('Accepted Differential revision'), | ||||
self::FIELD_IS_MERGE_COMMIT => pht('Commit is a merge'), | self::FIELD_IS_MERGE_COMMIT => pht('Commit is a merge'), | ||||
self::FIELD_BRANCHES => pht('Commit\'s branches'), | self::FIELD_BRANCHES => pht('Commit\'s branches'), | ||||
self::FIELD_AUTHOR_RAW => pht('Raw author name'), | self::FIELD_AUTHOR_RAW => pht('Raw author name'), | ||||
self::FIELD_COMMITTER_RAW => pht('Raw committer name'), | self::FIELD_COMMITTER_RAW => pht('Raw committer name'), | ||||
self::FIELD_TASK_PRIORITY => pht('Task priority'), | |||||
self::FIELD_TASK_STATUS => pht('Task status'), | |||||
self::FIELD_PUSHER_IS_COMMITTER => pht('Pusher same as committer'), | self::FIELD_PUSHER_IS_COMMITTER => pht('Pusher same as committer'), | ||||
self::FIELD_PATH => pht('Path'), | self::FIELD_PATH => pht('Path'), | ||||
); | ); | ||||
} | } | ||||
/* -( Conditions )--------------------------------------------------------- */ | /* -( Conditions )--------------------------------------------------------- */ | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | switch ($field) { | ||||
self::CONDITION_CONTAINS, | self::CONDITION_CONTAINS, | ||||
self::CONDITION_NOT_CONTAINS, | self::CONDITION_NOT_CONTAINS, | ||||
self::CONDITION_IS, | self::CONDITION_IS, | ||||
self::CONDITION_IS_NOT, | self::CONDITION_IS_NOT, | ||||
self::CONDITION_REGEXP, | self::CONDITION_REGEXP, | ||||
); | ); | ||||
case self::FIELD_REVIEWER: | case self::FIELD_REVIEWER: | ||||
case self::FIELD_PUSHER: | case self::FIELD_PUSHER: | ||||
case self::FIELD_TASK_PRIORITY: | |||||
case self::FIELD_TASK_STATUS: | |||||
return array( | return array( | ||||
self::CONDITION_IS_ANY, | self::CONDITION_IS_ANY, | ||||
self::CONDITION_IS_NOT_ANY, | self::CONDITION_IS_NOT_ANY, | ||||
); | ); | ||||
case self::FIELD_REPOSITORY: | case self::FIELD_REPOSITORY: | ||||
case self::FIELD_ASSIGNEE: | case self::FIELD_ASSIGNEE: | ||||
case self::FIELD_AUTHOR: | case self::FIELD_AUTHOR: | ||||
case self::FIELD_COMMITTER: | case self::FIELD_COMMITTER: | ||||
▲ Show 20 Lines • Show All 445 Lines • ▼ Show 20 Lines | switch ($condition) { | ||||
case self::CONDITION_IS: | case self::CONDITION_IS: | ||||
case self::CONDITION_IS_NOT: | case self::CONDITION_IS_NOT: | ||||
return self::VALUE_TEXT; | return self::VALUE_TEXT; | ||||
case self::CONDITION_IS_ANY: | case self::CONDITION_IS_ANY: | ||||
case self::CONDITION_IS_NOT_ANY: | case self::CONDITION_IS_NOT_ANY: | ||||
switch ($field) { | switch ($field) { | ||||
case self::FIELD_REPOSITORY: | case self::FIELD_REPOSITORY: | ||||
return self::VALUE_REPOSITORY; | return self::VALUE_REPOSITORY; | ||||
case self::FIELD_TASK_PRIORITY: | |||||
return self::VALUE_TASK_PRIORITY; | |||||
case self::FIELD_TASK_STATUS: | |||||
return self::VALUE_TASK_STATUS; | |||||
default: | default: | ||||
return self::VALUE_USER; | return self::VALUE_USER; | ||||
} | } | ||||
break; | break; | ||||
case self::CONDITION_INCLUDE_ALL: | case self::CONDITION_INCLUDE_ALL: | ||||
case self::CONDITION_INCLUDE_ANY: | case self::CONDITION_INCLUDE_ANY: | ||||
case self::CONDITION_INCLUDE_NONE: | case self::CONDITION_INCLUDE_NONE: | ||||
switch ($field) { | switch ($field) { | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | foreach ($adapters as $adapter) { | ||||
$type = $adapter->getAdapterContentType(); | $type = $adapter->getAdapterContentType(); | ||||
$name = $adapter->getAdapterContentName(); | $name = $adapter->getAdapterContentName(); | ||||
$map[$type] = $name; | $map[$type] = $name; | ||||
} | } | ||||
return $map; | return $map; | ||||
} | } | ||||
public function getEditorValueForCondition( | |||||
PhabricatorUser $viewer, | |||||
HeraldCondition $condition, | |||||
array $handles) { | |||||
$impl = $this->getFieldImplementation($condition->getFieldName()); | |||||
if ($impl) { | |||||
return $impl->getEditorValue( | |||||
$viewer, | |||||
$condition->getValue()); | |||||
} | |||||
$value = $condition->getValue(); | |||||
if (is_array($value)) { | |||||
$value_map = array(); | |||||
foreach ($value as $k => $phid) { | |||||
$value_map[$phid] = $handles[$phid]->getName(); | |||||
} | |||||
$value = $value_map; | |||||
} | |||||
return $value; | |||||
} | |||||
public function renderRuleAsText( | public function renderRuleAsText( | ||||
HeraldRule $rule, | HeraldRule $rule, | ||||
PhabricatorHandleList $handles) { | PhabricatorHandleList $handles, | ||||
PhabricatorUser $viewer) { | |||||
require_celerity_resource('herald-css'); | require_celerity_resource('herald-css'); | ||||
$icon = id(new PHUIIconView()) | $icon = id(new PHUIIconView()) | ||||
->setIconFont('fa-chevron-circle-right lightgreytext') | ->setIconFont('fa-chevron-circle-right lightgreytext') | ||||
->addClass('herald-list-icon'); | ->addClass('herald-list-icon'); | ||||
if ($rule->getMustMatchAll()) { | if ($rule->getMustMatchAll()) { | ||||
Show All 13 Lines | public function renderRuleAsText( | ||||
foreach ($rule->getConditions() as $condition) { | foreach ($rule->getConditions() as $condition) { | ||||
$match_list[] = phutil_tag( | $match_list[] = phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'class' => 'herald-list-item', | 'class' => 'herald-list-item', | ||||
), | ), | ||||
array( | array( | ||||
$icon, | $icon, | ||||
$this->renderConditionAsText($condition, $handles), | $this->renderConditionAsText($condition, $handles, $viewer), | ||||
)); | )); | ||||
} | } | ||||
$integer_code_for_every = HeraldRepetitionPolicyConfig::toInt( | $integer_code_for_every = HeraldRepetitionPolicyConfig::toInt( | ||||
HeraldRepetitionPolicyConfig::EVERY); | HeraldRepetitionPolicyConfig::EVERY); | ||||
if ($rule->getRepetitionPolicy() == $integer_code_for_every) { | if ($rule->getRepetitionPolicy() == $integer_code_for_every) { | ||||
$action_text = | $action_text = | ||||
Show All 28 Lines | return array( | ||||
$match_list, | $match_list, | ||||
$action_title, | $action_title, | ||||
$action_list, | $action_list, | ||||
); | ); | ||||
} | } | ||||
private function renderConditionAsText( | private function renderConditionAsText( | ||||
HeraldCondition $condition, | HeraldCondition $condition, | ||||
PhabricatorHandleList $handles) { | PhabricatorHandleList $handles, | ||||
PhabricatorUser $viewer) { | |||||
$field_type = $condition->getFieldName(); | $field_type = $condition->getFieldName(); | ||||
$default = pht('(Unknown Field "%s")', $field_type); | $default = pht('(Unknown Field "%s")', $field_type); | ||||
$field_name = idx($this->getFieldNameMap(), $field_type, $default); | $field_name = idx($this->getFieldNameMap(), $field_type, $default); | ||||
$condition_type = $condition->getFieldCondition(); | $condition_type = $condition->getFieldCondition(); | ||||
$condition_name = idx($this->getConditionNameMap(), $condition_type); | $condition_name = idx($this->getConditionNameMap(), $condition_type); | ||||
$value = $this->renderConditionValueAsText($condition, $handles); | $value = $this->renderConditionValueAsText($condition, $handles, $viewer); | ||||
return hsprintf(' %s %s %s', $field_name, $condition_name, $value); | return hsprintf(' %s %s %s', $field_name, $condition_name, $value); | ||||
} | } | ||||
private function renderActionAsText( | private function renderActionAsText( | ||||
HeraldAction $action, | HeraldAction $action, | ||||
PhabricatorHandleList $handles) { | PhabricatorHandleList $handles) { | ||||
$rule_global = HeraldRuleTypeConfig::RULE_TYPE_GLOBAL; | $rule_global = HeraldRuleTypeConfig::RULE_TYPE_GLOBAL; | ||||
Show All 9 Lines | private function renderActionAsText( | ||||
$target = $this->renderActionTargetAsText($action, $handles); | $target = $this->renderActionTargetAsText($action, $handles); | ||||
return hsprintf(' %s %s', $action_name, $target); | return hsprintf(' %s %s', $action_name, $target); | ||||
} | } | ||||
private function renderConditionValueAsText( | private function renderConditionValueAsText( | ||||
HeraldCondition $condition, | HeraldCondition $condition, | ||||
PhabricatorHandleList $handles) { | PhabricatorHandleList $handles, | ||||
PhabricatorUser $viewer) { | |||||
$impl = $this->getFieldImplementation($condition->getFieldName()); | |||||
if ($impl) { | |||||
return $impl->renderConditionValue( | |||||
$viewer, | |||||
$condition->getValue()); | |||||
} | |||||
$value = $condition->getValue(); | $value = $condition->getValue(); | ||||
if (!is_array($value)) { | if (!is_array($value)) { | ||||
$value = array($value); | $value = array($value); | ||||
} | } | ||||
switch ($condition->getFieldName()) { | switch ($condition->getFieldName()) { | ||||
case self::FIELD_TASK_PRIORITY: | |||||
$priority_map = ManiphestTaskPriority::getTaskPriorityMap(); | |||||
foreach ($value as $index => $val) { | |||||
$name = idx($priority_map, $val); | |||||
if ($name) { | |||||
$value[$index] = $name; | |||||
} | |||||
} | |||||
break; | |||||
case self::FIELD_TASK_STATUS: | |||||
$status_map = ManiphestTaskStatus::getTaskStatusMap(); | |||||
foreach ($value as $index => $val) { | |||||
$name = idx($status_map, $val); | |||||
if ($name) { | |||||
$value[$index] = $name; | |||||
} | |||||
} | |||||
break; | |||||
case HeraldPreCommitRefAdapter::FIELD_REF_CHANGE: | case HeraldPreCommitRefAdapter::FIELD_REF_CHANGE: | ||||
$change_map = | $change_map = | ||||
PhabricatorRepositoryPushLog::getHeraldChangeFlagConditionOptions(); | PhabricatorRepositoryPushLog::getHeraldChangeFlagConditionOptions(); | ||||
foreach ($value as $index => $val) { | foreach ($value as $index => $val) { | ||||
$name = idx($change_map, $val); | $name = idx($change_map, $val); | ||||
if ($name) { | if ($name) { | ||||
$value[$index] = $name; | $value[$index] = $name; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 336 Lines • Show Last 20 Lines |