@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move most Herald condition config into dynamic adapters

Summary: Ref T2769. Pushes most condition configuration into Adapters, out of the hard-coded class.

Test Plan: Looked at, edited, and dry-run'd Herald rules.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2769

Differential Revision: https://secure.phabricator.com/D6658

+151 -105
+95
src/applications/herald/adapter/HeraldAdapter.php
··· 16 16 const FIELD_AFFECTED_PACKAGE = 'affected-package'; 17 17 const FIELD_AFFECTED_PACKAGE_OWNER = 'affected-package-owner'; 18 18 19 + const CONDITION_CONTAINS = 'contains'; 20 + const CONDITION_NOT_CONTAINS = '!contains'; 21 + const CONDITION_IS = 'is'; 22 + const CONDITION_IS_NOT = '!is'; 23 + const CONDITION_IS_ANY = 'isany'; 24 + const CONDITION_IS_NOT_ANY = '!isany'; 25 + const CONDITION_INCLUDE_ALL = 'all'; 26 + const CONDITION_INCLUDE_ANY = 'any'; 27 + const CONDITION_INCLUDE_NONE = 'none'; 28 + const CONDITION_IS_ME = 'me'; 29 + const CONDITION_IS_NOT_ME = '!me'; 30 + const CONDITION_REGEXP = 'regexp'; 31 + const CONDITION_RULE = 'conditions'; 32 + const CONDITION_NOT_RULE = '!conditions'; 33 + const CONDITION_EXISTS = 'exists'; 34 + const CONDITION_NOT_EXISTS = '!exists'; 35 + const CONDITION_REGEXP_PAIR = 'regexp-pair'; 36 + 19 37 abstract public function getPHID(); 20 38 abstract public function getHeraldName(); 21 39 abstract public function getHeraldTypeName(); ··· 55 73 pht("Any affected package's owner"), 56 74 ); 57 75 } 76 + 77 + public function getConditionNameMap() { 78 + return array( 79 + self::CONDITION_CONTAINS => pht('contains'), 80 + self::CONDITION_NOT_CONTAINS => pht('does not contain'), 81 + self::CONDITION_IS => pht('is'), 82 + self::CONDITION_IS_NOT => pht('is not'), 83 + self::CONDITION_IS_ANY => pht('is any of'), 84 + self::CONDITION_IS_NOT_ANY => pht('is not any of'), 85 + self::CONDITION_INCLUDE_ALL => pht('include all of'), 86 + self::CONDITION_INCLUDE_ANY => pht('include any of'), 87 + self::CONDITION_INCLUDE_NONE => pht('include none of'), 88 + self::CONDITION_IS_ME => pht('is myself'), 89 + self::CONDITION_IS_NOT_ME => pht('is not myself'), 90 + self::CONDITION_REGEXP => pht('matches regexp'), 91 + self::CONDITION_RULE => pht('matches:'), 92 + self::CONDITION_NOT_RULE => pht('does not match:'), 93 + self::CONDITION_EXISTS => pht('exists'), 94 + self::CONDITION_NOT_EXISTS => pht('does not exist'), 95 + self::CONDITION_REGEXP_PAIR => pht('matches regexp pair'), 96 + ); 97 + } 98 + 99 + public function getConditionsForField($field) { 100 + switch ($field) { 101 + case self::FIELD_TITLE: 102 + case self::FIELD_BODY: 103 + return array( 104 + self::CONDITION_CONTAINS, 105 + self::CONDITION_NOT_CONTAINS, 106 + self::CONDITION_IS, 107 + self::CONDITION_IS_NOT, 108 + self::CONDITION_REGEXP, 109 + ); 110 + case self::FIELD_AUTHOR: 111 + case self::FIELD_REPOSITORY: 112 + case self::FIELD_REVIEWER: 113 + return array( 114 + self::CONDITION_IS_ANY, 115 + self::CONDITION_IS_NOT_ANY, 116 + ); 117 + case self::FIELD_TAGS: 118 + case self::FIELD_REVIEWERS: 119 + case self::FIELD_CC: 120 + return array( 121 + self::CONDITION_INCLUDE_ALL, 122 + self::CONDITION_INCLUDE_ANY, 123 + self::CONDITION_INCLUDE_NONE, 124 + ); 125 + case self::FIELD_DIFF_FILE: 126 + return array( 127 + self::CONDITION_CONTAINS, 128 + self::CONDITION_REGEXP, 129 + ); 130 + case self::FIELD_DIFF_CONTENT: 131 + return array( 132 + self::CONDITION_CONTAINS, 133 + self::CONDITION_REGEXP, 134 + self::CONDITION_REGEXP_PAIR, 135 + ); 136 + case self::FIELD_RULE: 137 + return array( 138 + self::CONDITION_RULE, 139 + self::CONDITION_NOT_RULE, 140 + ); 141 + case self::FIELD_AFFECTED_PACKAGE: 142 + case self::FIELD_AFFECTED_PACKAGE_OWNER: 143 + return array( 144 + self::CONDITION_INCLUDE_ANY, 145 + self::CONDITION_INCLUDE_NONE, 146 + ); 147 + default: 148 + throw new Exception( 149 + "This adapter does not define conditions for field '{$field}'!"); 150 + } 151 + } 152 + 58 153 59 154 public static function applyFlagEffect(HeraldEffect $effect, $phid) { 60 155 $color = $effect->getTarget();
+35 -12
src/applications/herald/adapter/HeraldCommitAdapter.php
··· 63 63 ); 64 64 } 65 65 66 + public function getConditionsForField($field) { 67 + switch ($field) { 68 + case self::FIELD_DIFFERENTIAL_REVIEWERS: 69 + case self::FIELD_DIFFERENTIAL_CCS: 70 + return array( 71 + self::CONDITION_INCLUDE_ALL, 72 + self::CONDITION_INCLUDE_ANY, 73 + self::CONDITION_INCLUDE_NONE, 74 + ); 75 + case self::FIELD_DIFFERENTIAL_REVISION: 76 + return array( 77 + self::CONDITION_EXISTS, 78 + self::CONDITION_NOT_EXISTS, 79 + ); 80 + case self::FIELD_NEED_AUDIT_FOR_PACKAGE: 81 + return array( 82 + self::CONDITION_INCLUDE_ANY, 83 + self::CONDITION_INCLUDE_NONE, 84 + ); 85 + } 86 + return parent::getConditionsForField($field); 87 + } 88 + 66 89 public static function newLegacyAdapter( 67 90 PhabricatorRepository $repository, 68 91 PhabricatorRepositoryCommit $commit, ··· 182 205 public function getHeraldField($field) { 183 206 $data = $this->commitData; 184 207 switch ($field) { 185 - case HeraldFieldConfig::FIELD_BODY: 208 + case self::FIELD_BODY: 186 209 return $data->getCommitMessage(); 187 - case HeraldFieldConfig::FIELD_AUTHOR: 210 + case self::FIELD_AUTHOR: 188 211 return $data->getCommitDetail('authorPHID'); 189 - case HeraldFieldConfig::FIELD_REVIEWER: 212 + case self::FIELD_REVIEWER: 190 213 return $data->getCommitDetail('reviewerPHID'); 191 - case HeraldFieldConfig::FIELD_DIFF_FILE: 214 + case self::FIELD_DIFF_FILE: 192 215 return $this->loadAffectedPaths(); 193 - case HeraldFieldConfig::FIELD_REPOSITORY: 216 + case self::FIELD_REPOSITORY: 194 217 return $this->repository->getPHID(); 195 - case HeraldFieldConfig::FIELD_DIFF_CONTENT: 218 + case self::FIELD_DIFF_CONTENT: 196 219 try { 197 220 $diff = $this->loadCommitDiff(); 198 221 } catch (Exception $ex) { ··· 211 234 $dict[$change->getFilename()] = implode("\n", $lines); 212 235 } 213 236 return $dict; 214 - case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE: 237 + case self::FIELD_AFFECTED_PACKAGE: 215 238 $packages = $this->loadAffectedPackages(); 216 239 return mpull($packages, 'getPHID'); 217 - case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE_OWNER: 240 + case self::FIELD_AFFECTED_PACKAGE_OWNER: 218 241 $packages = $this->loadAffectedPackages(); 219 242 $owners = PhabricatorOwnersOwner::loadAllForPackages($packages); 220 243 return mpull($owners, 'getUserPHID'); 221 - case HeraldFieldConfig::FIELD_NEED_AUDIT_FOR_PACKAGE: 244 + case self::FIELD_NEED_AUDIT_FOR_PACKAGE: 222 245 return $this->loadAuditNeededPackage(); 223 - case HeraldFieldConfig::FIELD_DIFFERENTIAL_REVISION: 246 + case self::FIELD_DIFFERENTIAL_REVISION: 224 247 $revision = $this->loadDifferentialRevision(); 225 248 if (!$revision) { 226 249 return null; 227 250 } 228 251 return $revision->getID(); 229 - case HeraldFieldConfig::FIELD_DIFFERENTIAL_REVIEWERS: 252 + case self::FIELD_DIFFERENTIAL_REVIEWERS: 230 253 $revision = $this->loadDifferentialRevision(); 231 254 if (!$revision) { 232 255 return array(); 233 256 } 234 257 return $revision->getReviewers(); 235 - case HeraldFieldConfig::FIELD_DIFFERENTIAL_CCS: 258 + case self::FIELD_DIFFERENTIAL_CCS: 236 259 $revision = $this->loadDifferentialRevision(); 237 260 if (!$revision) { 238 261 return array();
+10 -10
src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php
··· 198 198 199 199 public function getHeraldField($field) { 200 200 switch ($field) { 201 - case HeraldFieldConfig::FIELD_TITLE: 201 + case self::FIELD_TITLE: 202 202 return $this->revision->getTitle(); 203 203 break; 204 - case HeraldFieldConfig::FIELD_BODY: 204 + case self::FIELD_BODY: 205 205 return $this->revision->getSummary()."\n". 206 206 $this->revision->getTestPlan(); 207 207 break; 208 - case HeraldFieldConfig::FIELD_AUTHOR: 208 + case self::FIELD_AUTHOR: 209 209 return $this->revision->getAuthorPHID(); 210 210 break; 211 - case HeraldFieldConfig::FIELD_DIFF_FILE: 211 + case self::FIELD_DIFF_FILE: 212 212 return $this->loadAffectedPaths(); 213 - case HeraldFieldConfig::FIELD_CC: 213 + case self::FIELD_CC: 214 214 if (isset($this->explicitCCs)) { 215 215 return array_keys($this->explicitCCs); 216 216 } else { 217 217 return $this->revision->getCCPHIDs(); 218 218 } 219 - case HeraldFieldConfig::FIELD_REVIEWERS: 219 + case self::FIELD_REVIEWERS: 220 220 if (isset($this->explicitReviewers)) { 221 221 return array_keys($this->explicitReviewers); 222 222 } else { 223 223 return $this->revision->getReviewers(); 224 224 } 225 - case HeraldFieldConfig::FIELD_REPOSITORY: 225 + case self::FIELD_REPOSITORY: 226 226 $repository = $this->loadRepository(); 227 227 if (!$repository) { 228 228 return null; 229 229 } 230 230 return $repository->getPHID(); 231 - case HeraldFieldConfig::FIELD_DIFF_CONTENT: 231 + case self::FIELD_DIFF_CONTENT: 232 232 return $this->loadContentDictionary(); 233 - case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE: 233 + case self::FIELD_AFFECTED_PACKAGE: 234 234 $packages = $this->loadAffectedPackages(); 235 235 return mpull($packages, 'getPHID'); 236 - case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE_OWNER: 236 + case self::FIELD_AFFECTED_PACKAGE_OWNER: 237 237 $packages = $this->loadAffectedPackages(); 238 238 return PhabricatorOwnersOwner::loadAffiliatedUserPHIDs( 239 239 mpull($packages, 'getID'));
+2 -78
src/applications/herald/config/HeraldConditionConfig.php
··· 2 2 3 3 final class HeraldConditionConfig { 4 4 5 + // TODO: Remove; still used by Engine/etc. 5 6 const CONDITION_CONTAINS = 'contains'; 6 7 const CONDITION_NOT_CONTAINS = '!contains'; 7 8 const CONDITION_IS = 'is'; ··· 20 21 const CONDITION_NOT_EXISTS = '!exists'; 21 22 const CONDITION_REGEXP_PAIR = 'regexp-pair'; 22 23 24 + // TODO: Remove; still used by Transcripts. 23 25 public static function getConditionMap() { 24 26 $map = array( 25 27 self::CONDITION_CONTAINS => pht('contains'), ··· 42 44 ); 43 45 44 46 return $map; 45 - } 46 - 47 - public static function getConditionMapForField($field) { 48 - $map = self::getConditionMap(); 49 - switch ($field) { 50 - case HeraldFieldConfig::FIELD_TITLE: 51 - case HeraldFieldConfig::FIELD_BODY: 52 - return array_select_keys( 53 - $map, 54 - array( 55 - self::CONDITION_CONTAINS, 56 - self::CONDITION_NOT_CONTAINS, 57 - self::CONDITION_IS, 58 - self::CONDITION_IS_NOT, 59 - self::CONDITION_REGEXP, 60 - )); 61 - case HeraldFieldConfig::FIELD_AUTHOR: 62 - case HeraldFieldConfig::FIELD_REPOSITORY: 63 - case HeraldFieldConfig::FIELD_REVIEWER: 64 - return array_select_keys( 65 - $map, 66 - array( 67 - self::CONDITION_IS_ANY, 68 - self::CONDITION_IS_NOT_ANY, 69 - )); 70 - case HeraldFieldConfig::FIELD_TAGS: 71 - case HeraldFieldConfig::FIELD_REVIEWERS: 72 - case HeraldFieldConfig::FIELD_CC: 73 - case HeraldFieldConfig::FIELD_DIFFERENTIAL_REVIEWERS: 74 - case HeraldFieldConfig::FIELD_DIFFERENTIAL_CCS: 75 - return array_select_keys( 76 - $map, 77 - array( 78 - self::CONDITION_INCLUDE_ALL, 79 - self::CONDITION_INCLUDE_ANY, 80 - self::CONDITION_INCLUDE_NONE, 81 - )); 82 - case HeraldFieldConfig::FIELD_DIFF_FILE: 83 - return array_select_keys( 84 - $map, 85 - array( 86 - self::CONDITION_CONTAINS, 87 - self::CONDITION_REGEXP, 88 - )); 89 - case HeraldFieldConfig::FIELD_DIFF_CONTENT: 90 - return array_select_keys( 91 - $map, 92 - array( 93 - self::CONDITION_CONTAINS, 94 - self::CONDITION_REGEXP, 95 - self::CONDITION_REGEXP_PAIR, 96 - )); 97 - case HeraldFieldConfig::FIELD_RULE: 98 - return array_select_keys( 99 - $map, 100 - array( 101 - self::CONDITION_RULE, 102 - self::CONDITION_NOT_RULE, 103 - )); 104 - case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE: 105 - case HeraldFieldConfig::FIELD_AFFECTED_PACKAGE_OWNER: 106 - case HeraldFieldConfig::FIELD_NEED_AUDIT_FOR_PACKAGE: 107 - return array_select_keys( 108 - $map, 109 - array( 110 - self::CONDITION_INCLUDE_ANY, 111 - self::CONDITION_INCLUDE_NONE, 112 - )); 113 - case HeraldFieldConfig::FIELD_DIFFERENTIAL_REVISION: 114 - return array_select_keys( 115 - $map, 116 - array( 117 - self::CONDITION_EXISTS, 118 - self::CONDITION_NOT_EXISTS, 119 - )); 120 - default: 121 - throw new Exception("Unknown field type '{$field}'."); 122 - } 123 47 } 124 48 125 49 }
+9 -5
src/applications/herald/controller/HeraldRuleController.php
··· 387 387 $all_rules = mpull($all_rules, 'getName', 'getID'); 388 388 asort($all_rules); 389 389 390 + $all_fields = $adapter->getFieldNameMap(); 391 + $all_conditions = $adapter->getConditionNameMap(); 392 + 390 393 $fields = $adapter->getFields(); 391 - $field_map = array_select_keys($adapter->getFieldNameMap(), $fields); 394 + $field_map = array_select_keys($all_fields, $fields); 392 395 393 396 $config_info = array(); 394 397 $config_info['fields'] = $field_map; 395 - $config_info['conditions'] = HeraldConditionConfig::getConditionMap(); 398 + $config_info['conditions'] = $all_conditions; 396 399 foreach ($config_info['fields'] as $field => $name) { 397 - $config_info['conditionMap'][$field] = array_keys( 398 - HeraldConditionConfig::getConditionMapForField($field)); 400 + $field_conditions = $adapter->getConditionsForField($field); 401 + $config_info['conditionMap'][$field] = $field_conditions; 399 402 } 403 + 400 404 foreach ($config_info['fields'] as $field => $fname) { 401 - foreach ($config_info['conditions'] as $condition => $cname) { 405 + foreach ($config_info['conditionMap'][$field] as $condition) { 402 406 $config_info['values'][$field][$condition] = 403 407 HeraldValueTypeConfig::getValueTypeForFieldAndCondition( 404 408 $field,