Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/adapter/HeraldAdapter.php
<?php | <?php | ||||
abstract class HeraldAdapter extends Phobject { | abstract class HeraldAdapter extends Phobject { | ||||
const FIELD_TITLE = 'title'; | |||||
const FIELD_BODY = 'body'; | |||||
const FIELD_AUTHOR = 'author'; | |||||
const FIELD_REVIEWER = 'reviewer'; | |||||
const FIELD_COMMITTER = 'committer'; | |||||
const FIELD_DIFF_FILE = 'diff-file'; | |||||
const FIELD_DIFF_CONTENT = 'diff-content'; | |||||
const FIELD_DIFF_ADDED_CONTENT = 'diff-added-content'; | |||||
const FIELD_DIFF_REMOVED_CONTENT = 'diff-removed-content'; | |||||
const FIELD_DIFF_ENORMOUS = 'diff-enormous'; | |||||
const FIELD_REPOSITORY = 'repository'; | |||||
const FIELD_REPOSITORY_PROJECTS = 'repository-projects'; | |||||
const FIELD_AFFECTED_PACKAGE = 'affected-package'; | |||||
const FIELD_AFFECTED_PACKAGE_OWNER = 'affected-package-owner'; | |||||
const FIELD_AUTHOR_PROJECTS = 'authorprojects'; | |||||
const FIELD_PUSHER = 'pusher'; | |||||
const FIELD_PUSHER_PROJECTS = 'pusher-projects'; | |||||
const FIELD_DIFFERENTIAL_REVISION = 'differential-revision'; | |||||
const FIELD_DIFFERENTIAL_REVIEWERS = 'differential-reviewers'; | |||||
const FIELD_DIFFERENTIAL_CCS = 'differential-ccs'; | |||||
const FIELD_DIFFERENTIAL_ACCEPTED = 'differential-accepted'; | |||||
const FIELD_IS_MERGE_COMMIT = 'is-merge-commit'; | |||||
const FIELD_BRANCHES = 'branches'; | |||||
const FIELD_AUTHOR_RAW = 'author-raw'; | |||||
const FIELD_COMMITTER_RAW = 'committer-raw'; | |||||
const FIELD_PUSHER_IS_COMMITTER = 'pusher-is-committer'; | |||||
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'; | ||||
const CONDITION_IS_NOT_ANY = '!isany'; | const CONDITION_IS_NOT_ANY = '!isany'; | ||||
const CONDITION_INCLUDE_ALL = 'all'; | const CONDITION_INCLUDE_ALL = 'all'; | ||||
const CONDITION_INCLUDE_ANY = 'any'; | const CONDITION_INCLUDE_ANY = 'any'; | ||||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | abstract class HeraldAdapter extends Phobject { | ||||
} | } | ||||
public function getPHID() { | public function getPHID() { | ||||
return $this->getObject()->getPHID(); | return $this->getObject()->getPHID(); | ||||
} | } | ||||
abstract public function getHeraldName(); | abstract public function getHeraldName(); | ||||
public function getHeraldField($field_name) { | public function getHeraldField($field_key) { | ||||
$impl = $this->getFieldImplementation($field_name); | return $this->requireFieldImplementation($field_key) | ||||
if ($impl) { | ->getHeraldFieldValue($this->getObject()); | ||||
return $impl->getHeraldFieldValue($this->getObject()); | |||||
} | |||||
throw new Exception(pht("Unknown field '%s'!", $field_name)); | |||||
} | } | ||||
public function applyHeraldEffects(array $effects) { | public function applyHeraldEffects(array $effects) { | ||||
assert_instances_of($effects, 'HeraldEffect'); | assert_instances_of($effects, 'HeraldEffect'); | ||||
$result = array(); | $result = array(); | ||||
foreach ($effects as $effect) { | foreach ($effects as $effect) { | ||||
$result[] = $this->applyStandardEffect($effect); | $result[] = $this->applyStandardEffect($effect); | ||||
▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | private function getFieldImplementation($key) { | ||||
return idx($this->getFieldImplementationMap(), $key); | return idx($this->getFieldImplementationMap(), $key); | ||||
} | } | ||||
public function getFields() { | public function getFields() { | ||||
return array_keys($this->getFieldImplementationMap()); | return array_keys($this->getFieldImplementationMap()); | ||||
} | } | ||||
public function getFieldNameMap() { | public function getFieldNameMap() { | ||||
$map = mpull($this->getFieldImplementationMap(), 'getHeraldFieldName'); | return mpull($this->getFieldImplementationMap(), 'getHeraldFieldName'); | ||||
return $map + array( | |||||
self::FIELD_TITLE => pht('Title'), | |||||
self::FIELD_BODY => pht('Body'), | |||||
self::FIELD_AUTHOR => pht('Author'), | |||||
self::FIELD_COMMITTER => pht('Committer'), | |||||
self::FIELD_REVIEWER => pht('Reviewer'), | |||||
self::FIELD_DIFF_FILE => pht('Any changed filename'), | |||||
self::FIELD_DIFF_CONTENT => pht('Any changed file content'), | |||||
self::FIELD_DIFF_ADDED_CONTENT => pht('Any added file content'), | |||||
self::FIELD_DIFF_REMOVED_CONTENT => pht('Any removed file content'), | |||||
self::FIELD_DIFF_ENORMOUS => pht('Change is enormous'), | |||||
self::FIELD_REPOSITORY => pht('Repository'), | |||||
self::FIELD_REPOSITORY_PROJECTS => pht('Repository\'s projects'), | |||||
self::FIELD_AFFECTED_PACKAGE => pht('Any affected package'), | |||||
self::FIELD_AFFECTED_PACKAGE_OWNER => | |||||
pht("Any affected package's owner"), | |||||
self::FIELD_AUTHOR_PROJECTS => pht("Author's projects"), | |||||
self::FIELD_PUSHER => pht('Pusher'), | |||||
self::FIELD_PUSHER_PROJECTS => pht("Pusher's projects"), | |||||
self::FIELD_DIFFERENTIAL_REVISION => pht('Differential revision'), | |||||
self::FIELD_DIFFERENTIAL_REVIEWERS => pht('Differential reviewers'), | |||||
self::FIELD_DIFFERENTIAL_CCS => pht('Differential CCs'), | |||||
self::FIELD_DIFFERENTIAL_ACCEPTED | |||||
=> pht('Accepted Differential revision'), | |||||
self::FIELD_IS_MERGE_COMMIT => pht('Commit is a merge'), | |||||
self::FIELD_BRANCHES => pht('Commit\'s branches'), | |||||
self::FIELD_AUTHOR_RAW => pht('Raw author name'), | |||||
self::FIELD_COMMITTER_RAW => pht('Raw committer name'), | |||||
self::FIELD_PUSHER_IS_COMMITTER => pht('Pusher same as committer'), | |||||
); | |||||
} | } | ||||
/* -( Conditions )--------------------------------------------------------- */ | /* -( Conditions )--------------------------------------------------------- */ | ||||
public function getConditionNameMap() { | public function getConditionNameMap() { | ||||
return array( | return array( | ||||
Show All 19 Lines | return array( | ||||
self::CONDITION_NEVER => '', // don't show anything! | self::CONDITION_NEVER => '', // don't show anything! | ||||
self::CONDITION_REGEXP_PAIR => pht('matches regexp pair'), | self::CONDITION_REGEXP_PAIR => pht('matches regexp pair'), | ||||
self::CONDITION_HAS_BIT => pht('has bit'), | self::CONDITION_HAS_BIT => pht('has bit'), | ||||
self::CONDITION_NOT_BIT => pht('lacks bit'), | self::CONDITION_NOT_BIT => pht('lacks bit'), | ||||
); | ); | ||||
} | } | ||||
public function getConditionsForField($field) { | public function getConditionsForField($field) { | ||||
$impl = $this->getFieldImplementation($field); | return $this->requireFieldImplementation($field) | ||||
if ($impl) { | ->getHeraldFieldConditions(); | ||||
return $impl->getHeraldFieldConditions(); | |||||
} | } | ||||
switch ($field) { | private function requireFieldImplementation($field_key) { | ||||
case self::FIELD_TITLE: | $field = $this->getFieldImplementation($field_key); | ||||
case self::FIELD_BODY: | |||||
case self::FIELD_COMMITTER_RAW: | if (!$field) { | ||||
case self::FIELD_AUTHOR_RAW: | |||||
return array( | |||||
self::CONDITION_CONTAINS, | |||||
self::CONDITION_NOT_CONTAINS, | |||||
self::CONDITION_IS, | |||||
self::CONDITION_IS_NOT, | |||||
self::CONDITION_REGEXP, | |||||
); | |||||
case self::FIELD_REVIEWER: | |||||
case self::FIELD_PUSHER: | |||||
return array( | |||||
self::CONDITION_IS_ANY, | |||||
self::CONDITION_IS_NOT_ANY, | |||||
); | |||||
case self::FIELD_REPOSITORY: | |||||
case self::FIELD_AUTHOR: | |||||
case self::FIELD_COMMITTER: | |||||
return array( | |||||
self::CONDITION_IS_ANY, | |||||
self::CONDITION_IS_NOT_ANY, | |||||
self::CONDITION_EXISTS, | |||||
self::CONDITION_NOT_EXISTS, | |||||
); | |||||
case self::FIELD_AUTHOR_PROJECTS: | |||||
case self::FIELD_AFFECTED_PACKAGE: | |||||
case self::FIELD_AFFECTED_PACKAGE_OWNER: | |||||
case self::FIELD_PUSHER_PROJECTS: | |||||
case self::FIELD_REPOSITORY_PROJECTS: | |||||
return array( | |||||
self::CONDITION_INCLUDE_ALL, | |||||
self::CONDITION_INCLUDE_ANY, | |||||
self::CONDITION_INCLUDE_NONE, | |||||
self::CONDITION_EXISTS, | |||||
self::CONDITION_NOT_EXISTS, | |||||
); | |||||
case self::FIELD_DIFF_FILE: | |||||
case self::FIELD_BRANCHES: | |||||
return array( | |||||
self::CONDITION_CONTAINS, | |||||
self::CONDITION_REGEXP, | |||||
); | |||||
case self::FIELD_DIFF_CONTENT: | |||||
case self::FIELD_DIFF_ADDED_CONTENT: | |||||
case self::FIELD_DIFF_REMOVED_CONTENT: | |||||
return array( | |||||
self::CONDITION_CONTAINS, | |||||
self::CONDITION_REGEXP, | |||||
self::CONDITION_REGEXP_PAIR, | |||||
); | |||||
case self::FIELD_DIFFERENTIAL_REVIEWERS: | |||||
return array( | |||||
self::CONDITION_EXISTS, | |||||
self::CONDITION_NOT_EXISTS, | |||||
self::CONDITION_INCLUDE_ALL, | |||||
self::CONDITION_INCLUDE_ANY, | |||||
self::CONDITION_INCLUDE_NONE, | |||||
); | |||||
case self::FIELD_DIFFERENTIAL_CCS: | |||||
return array( | |||||
self::CONDITION_INCLUDE_ALL, | |||||
self::CONDITION_INCLUDE_ANY, | |||||
self::CONDITION_INCLUDE_NONE, | |||||
); | |||||
case self::FIELD_DIFFERENTIAL_REVISION: | |||||
case self::FIELD_DIFFERENTIAL_ACCEPTED: | |||||
return array( | |||||
self::CONDITION_EXISTS, | |||||
self::CONDITION_NOT_EXISTS, | |||||
); | |||||
case self::FIELD_IS_MERGE_COMMIT: | |||||
case self::FIELD_DIFF_ENORMOUS: | |||||
case self::FIELD_PUSHER_IS_COMMITTER: | |||||
return array( | |||||
self::CONDITION_IS_TRUE, | |||||
self::CONDITION_IS_FALSE, | |||||
); | |||||
default: | |||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
"This adapter does not define conditions for field '%s'!", | 'No field with key "%s" is available to Herald adapter "%s".', | ||||
$field)); | $field_key, | ||||
get_class($this))); | |||||
} | } | ||||
return $field; | |||||
} | } | ||||
public function doesConditionMatch( | public function doesConditionMatch( | ||||
HeraldEngine $engine, | HeraldEngine $engine, | ||||
HeraldRule $rule, | HeraldRule $rule, | ||||
HeraldCondition $condition, | HeraldCondition $condition, | ||||
$field_value) { | $field_value) { | ||||
▲ Show 20 Lines • Show All 352 Lines • ▼ Show 20 Lines | /* -( Actions )------------------------------------------------------------ */ | ||||
} | } | ||||
/* -( Values )------------------------------------------------------------- */ | /* -( Values )------------------------------------------------------------- */ | ||||
public function getValueTypeForFieldAndCondition($field, $condition) { | public function getValueTypeForFieldAndCondition($field, $condition) { | ||||
$impl = $this->getFieldImplementation($field); | return $this->requireFieldImplementation($field) | ||||
if ($impl) { | ->getHeraldFieldValueType($condition); | ||||
return $impl->getHeraldFieldValueType($condition); | |||||
} | |||||
switch ($condition) { | |||||
case self::CONDITION_CONTAINS: | |||||
case self::CONDITION_NOT_CONTAINS: | |||||
case self::CONDITION_REGEXP: | |||||
case self::CONDITION_REGEXP_PAIR: | |||||
return self::VALUE_TEXT; | |||||
case self::CONDITION_IS: | |||||
case self::CONDITION_IS_NOT: | |||||
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_AFFECTED_PACKAGE: | |||||
return self::VALUE_OWNERS_PACKAGE; | |||||
case self::FIELD_AUTHOR_PROJECTS: | |||||
case self::FIELD_PUSHER_PROJECTS: | |||||
case self::FIELD_REPOSITORY_PROJECTS: | |||||
return self::VALUE_PROJECT; | |||||
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: | |||||
case self::CONDITION_UNCONDITIONALLY: | |||||
case self::CONDITION_NEVER: | |||||
case self::CONDITION_IS_TRUE: | |||||
case self::CONDITION_IS_FALSE: | |||||
return self::VALUE_NONE; | |||||
default: | |||||
throw new Exception(pht("Unknown condition '%s'.", $condition)); | |||||
} | |||||
} | } | ||||
public function getValueTypeForAction($action, $rule_type) { | public function getValueTypeForAction($action, $rule_type) { | ||||
$is_personal = ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); | $is_personal = ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL); | ||||
if ($is_personal) { | if ($is_personal) { | ||||
switch ($action) { | switch ($action) { | ||||
case self::ACTION_ADD_CC: | case self::ACTION_ADD_CC: | ||||
▲ Show 20 Lines • Show All 602 Lines • Show Last 20 Lines |