@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.

Remove HeraldActionConfig, HeraldFieldConfig

Summary:
Ref T2769. Move all of this stuff into Adapters and get rid of the hard-coded classes.

I cheated in two places.

Test Plan: Edited and activated Herald rules.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, chad

Maniphest Tasks: T2769

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

+76 -107
+5 -5
src/__phutil_library_map__.php
··· 595 595 'HarbormasterRunnerWorker' => 'applications/harbormaster/worker/HarbormasterRunnerWorker.php', 596 596 'HarbormasterScratchTable' => 'applications/harbormaster/storage/HarbormasterScratchTable.php', 597 597 'HeraldAction' => 'applications/herald/storage/HeraldAction.php', 598 - 'HeraldActionConfig' => 'applications/herald/config/HeraldActionConfig.php', 599 598 'HeraldAdapter' => 'applications/herald/adapter/HeraldAdapter.php', 600 599 'HeraldApplyTranscript' => 'applications/herald/storage/transcript/HeraldApplyTranscript.php', 601 600 'HeraldCommitAdapter' => 'applications/herald/adapter/HeraldCommitAdapter.php', ··· 609 608 'HeraldEditLogQuery' => 'applications/herald/query/HeraldEditLogQuery.php', 610 609 'HeraldEffect' => 'applications/herald/engine/HeraldEffect.php', 611 610 'HeraldEngine' => 'applications/herald/engine/HeraldEngine.php', 612 - 'HeraldFieldConfig' => 'applications/herald/config/HeraldFieldConfig.php', 613 - 'HeraldInvalidConditionException' => 'applications/herald/engine/engine/HeraldInvalidConditionException.php', 614 - 'HeraldInvalidFieldException' => 'applications/herald/engine/engine/HeraldInvalidFieldException.php', 611 + 'HeraldInvalidActionException' => 'applications/herald/engine/exception/HeraldInvalidActionException.php', 612 + 'HeraldInvalidConditionException' => 'applications/herald/engine/exception/HeraldInvalidConditionException.php', 613 + 'HeraldInvalidFieldException' => 'applications/herald/engine/exception/HeraldInvalidFieldException.php', 615 614 'HeraldNewController' => 'applications/herald/controller/HeraldNewController.php', 616 615 'HeraldObjectTranscript' => 'applications/herald/storage/transcript/HeraldObjectTranscript.php', 617 616 'HeraldPHIDTypeRule' => 'applications/herald/phid/HeraldPHIDTypeRule.php', 618 - 'HeraldRecursiveConditionsException' => 'applications/herald/engine/engine/HeraldRecursiveConditionsException.php', 617 + 'HeraldRecursiveConditionsException' => 'applications/herald/engine/exception/HeraldRecursiveConditionsException.php', 619 618 'HeraldRepetitionPolicyConfig' => 'applications/herald/config/HeraldRepetitionPolicyConfig.php', 620 619 'HeraldRule' => 'applications/herald/storage/HeraldRule.php', 621 620 'HeraldRuleController' => 'applications/herald/controller/HeraldRuleController.php', ··· 2617 2616 'HeraldDifferentialRevisionAdapter' => 'HeraldAdapter', 2618 2617 'HeraldDryRunAdapter' => 'HeraldAdapter', 2619 2618 'HeraldEditLogQuery' => 'PhabricatorOffsetPagedQuery', 2619 + 'HeraldInvalidActionException' => 'Exception', 2620 2620 'HeraldInvalidConditionException' => 'Exception', 2621 2621 'HeraldInvalidFieldException' => 'Exception', 2622 2622 'HeraldNewController' => 'HeraldController',
+42
src/applications/herald/adapter/HeraldAdapter.php
··· 435 435 } 436 436 } 437 437 438 + public function willSaveAction( 439 + HeraldRule $rule, 440 + HeraldAction $action) { 441 + 442 + $target = $action->getTarget(); 443 + if (is_array($target)) { 444 + $target = array_keys($target); 445 + } 446 + 447 + $author_phid = $rule->getAuthorPHID(); 448 + 449 + $rule_type = $rule->getRuleType(); 450 + if ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL) { 451 + switch ($action->getAction()) { 452 + case self::ACTION_EMAIL: 453 + case self::ACTION_ADD_CC: 454 + case self::ACTION_REMOVE_CC: 455 + case self::ACTION_AUDIT: 456 + // For personal rules, force these actions to target the rule owner. 457 + $target = array($author_phid); 458 + break; 459 + case self::ACTION_FLAG: 460 + // Make sure flag color is valid; set to blue if not. 461 + $color_map = PhabricatorFlagColor::getColorNameMap(); 462 + if (empty($color_map[$target])) { 463 + $target = PhabricatorFlagColor::COLOR_BLUE; 464 + } 465 + break; 466 + case self::ACTION_NOTHING: 467 + break; 468 + default: 469 + throw new HeraldInvalidActionException( 470 + pht( 471 + 'Unrecognized action type "%s"!', 472 + $action->getAction())); 473 + } 474 + } 475 + 476 + $action->setTarget($target); 477 + } 478 + 479 + 438 480 439 481 /* -( Values )------------------------------------------------------------- */ 440 482
+4 -4
src/applications/herald/adapter/HeraldCommitAdapter.php
··· 299 299 foreach ($effects as $effect) { 300 300 $action = $effect->getAction(); 301 301 switch ($action) { 302 - case HeraldActionConfig::ACTION_NOTHING: 302 + case self::ACTION_NOTHING: 303 303 $result[] = new HeraldApplyTranscript( 304 304 $effect, 305 305 true, 306 306 pht('Great success at doing nothing.')); 307 307 break; 308 - case HeraldActionConfig::ACTION_EMAIL: 308 + case self::ACTION_EMAIL: 309 309 foreach ($effect->getTarget() as $phid) { 310 310 $this->emailPHIDs[$phid] = true; 311 311 } ··· 314 314 true, 315 315 pht('Added address to email targets.')); 316 316 break; 317 - case HeraldActionConfig::ACTION_AUDIT: 317 + case self::ACTION_AUDIT: 318 318 foreach ($effect->getTarget() as $phid) { 319 319 if (empty($this->auditMap[$phid])) { 320 320 $this->auditMap[$phid] = array(); ··· 326 326 true, 327 327 pht('Triggered an audit.')); 328 328 break; 329 - case HeraldActionConfig::ACTION_FLAG: 329 + case self::ACTION_FLAG: 330 330 $result[] = parent::applyFlagEffect( 331 331 $effect, 332 332 $this->commit->getPHID());
+8 -8
src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php
··· 269 269 $result = array(); 270 270 if ($this->explicitCCs) { 271 271 $effect = new HeraldEffect(); 272 - $effect->setAction(HeraldActionConfig::ACTION_ADD_CC); 272 + $effect->setAction(self::ACTION_ADD_CC); 273 273 $effect->setTarget(array_keys($this->explicitCCs)); 274 274 $effect->setReason( 275 275 pht('CCs provided explicitly by revision author or carried over '. ··· 287 287 foreach ($effects as $effect) { 288 288 $action = $effect->getAction(); 289 289 switch ($action) { 290 - case HeraldActionConfig::ACTION_NOTHING: 290 + case self::ACTION_NOTHING: 291 291 $result[] = new HeraldApplyTranscript( 292 292 $effect, 293 293 true, 294 294 pht('OK, did nothing.')); 295 295 break; 296 - case HeraldActionConfig::ACTION_FLAG: 296 + case self::ACTION_FLAG: 297 297 $result[] = parent::applyFlagEffect( 298 298 $effect, 299 299 $this->revision->getPHID()); 300 300 break; 301 - case HeraldActionConfig::ACTION_EMAIL: 302 - case HeraldActionConfig::ACTION_ADD_CC: 303 - $op = ($action == HeraldActionConfig::ACTION_EMAIL) ? 'email' : 'CC'; 301 + case self::ACTION_EMAIL: 302 + case self::ACTION_ADD_CC: 303 + $op = ($action == self::ACTION_EMAIL) ? 'email' : 'CC'; 304 304 $base_target = $effect->getTarget(); 305 305 $forbidden = array(); 306 306 foreach ($base_target as $key => $fbid) { ··· 308 308 $forbidden[] = $fbid; 309 309 unset($base_target[$key]); 310 310 } else { 311 - if ($action == HeraldActionConfig::ACTION_EMAIL) { 311 + if ($action == self::ACTION_EMAIL) { 312 312 $this->emailPHIDs[$fbid] = true; 313 313 } else { 314 314 $this->newCCs[$fbid] = true; ··· 338 338 pht('Added addresses to %s list.', $op)); 339 339 } 340 340 break; 341 - case HeraldActionConfig::ACTION_REMOVE_CC: 341 + case self::ACTION_REMOVE_CC: 342 342 foreach ($effect->getTarget() as $fbid) { 343 343 $this->remCCs[$fbid] = true; 344 344 }
-60
src/applications/herald/config/HeraldActionConfig.php
··· 1 - <?php 2 - 3 - final class HeraldActionConfig { 4 - 5 - const ACTION_ADD_CC = 'addcc'; 6 - const ACTION_REMOVE_CC = 'remcc'; 7 - const ACTION_EMAIL = 'email'; 8 - const ACTION_NOTHING = 'nothing'; 9 - const ACTION_AUDIT = 'audit'; 10 - const ACTION_FLAG = 'flag'; 11 - 12 - /** 13 - * Create a HeraldAction to save from data. 14 - * 15 - * $data is of the form: 16 - * array( 17 - * 0 => <action type> 18 - * 1 => array(<targets>) 19 - * ) 20 - */ 21 - public static function willSaveAction($rule_type, 22 - $author_phid, 23 - $data) { 24 - $obj = new HeraldAction(); 25 - $obj->setAction($data[0]); 26 - 27 - // for personal rule types, set the target to be the owner of the rule 28 - if ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL) { 29 - switch ($obj->getAction()) { 30 - case HeraldActionConfig::ACTION_EMAIL: 31 - case HeraldActionConfig::ACTION_ADD_CC: 32 - case HeraldActionConfig::ACTION_REMOVE_CC: 33 - case HeraldActionConfig::ACTION_AUDIT: 34 - $data[1] = array($author_phid => $author_phid); 35 - break; 36 - case HeraldActionConfig::ACTION_FLAG: 37 - // Make sure flag color is valid; set to blue if not. 38 - $color_map = PhabricatorFlagColor::getColorNameMap(); 39 - if (empty($color_map[$data[1]])) { 40 - $data[1] = PhabricatorFlagColor::COLOR_BLUE; 41 - } 42 - break; 43 - case HeraldActionConfig::ACTION_NOTHING: 44 - break; 45 - default: 46 - throw new Exception('Unrecognized action type: ' . 47 - $obj->getAction()); 48 - } 49 - } 50 - 51 - if (is_array($data[1])) { 52 - $obj->setTarget(array_keys($data[1])); 53 - } else { 54 - $obj->setTarget($data[1]); 55 - } 56 - 57 - return $obj; 58 - } 59 - 60 - }
-24
src/applications/herald/config/HeraldFieldConfig.php
··· 1 - <?php 2 - 3 - final class HeraldFieldConfig { 4 - 5 - // TODO: Remove; still required by conditions, etc. 6 - const FIELD_TITLE = 'title'; 7 - const FIELD_BODY = 'body'; 8 - const FIELD_AUTHOR = 'author'; 9 - const FIELD_REVIEWER = 'reviewer'; 10 - const FIELD_REVIEWERS = 'reviewers'; 11 - const FIELD_CC = 'cc'; 12 - const FIELD_TAGS = 'tags'; 13 - const FIELD_DIFF_FILE = 'diff-file'; 14 - const FIELD_DIFF_CONTENT = 'diff-content'; 15 - const FIELD_REPOSITORY = 'repository'; 16 - const FIELD_RULE = 'rule'; 17 - const FIELD_AFFECTED_PACKAGE = 'affected-package'; 18 - const FIELD_AFFECTED_PACKAGE_OWNER = 'affected-package-owner'; 19 - const FIELD_NEED_AUDIT_FOR_PACKAGE = 'need-audit-for-package'; 20 - const FIELD_DIFFERENTIAL_REVISION = 'differential-revision'; 21 - const FIELD_DIFFERENTIAL_REVIEWERS = 'differential-reviewers'; 22 - const FIELD_DIFFERENTIAL_CCS = 'differential-ccs'; 23 - 24 - }
+12 -4
src/applications/herald/controller/HeraldRuleController.php
··· 261 261 $action[1] = null; 262 262 } 263 263 264 - $actions[] = HeraldActionConfig::willSaveAction($rule->getRuleType(), 265 - $rule->getAuthorPHID(), 266 - $action); 264 + $obj = new HeraldAction(); 265 + $obj->setAction($action[0]); 266 + $obj->setTarget($action[1]); 267 + 268 + try { 269 + $adapter->willSaveAction($rule, $obj); 270 + } catch (HeraldInvalidActionException $ex) { 271 + $errors[] = $ex; 272 + } 273 + 274 + $actions[] = $obj; 267 275 } 268 276 269 277 $rule->attachConditions($conditions); ··· 328 336 foreach ($rule->getActions() as $action) { 329 337 330 338 switch ($action->getAction()) { 331 - case HeraldActionConfig::ACTION_FLAG: 339 + case HeraldAdapter::ACTION_FLAG: 332 340 $current_value = $action->getTarget(); 333 341 break; 334 342 default:
+2 -2
src/applications/herald/controller/HeraldTranscriptController.php
··· 273 273 274 274 $target = $apply_xscript->getTarget(); 275 275 switch ($apply_xscript->getAction()) { 276 - case HeraldActionConfig::ACTION_NOTHING: 276 + case HeraldAdapter::ACTION_NOTHING: 277 277 $target = ''; 278 278 break; 279 - case HeraldActionConfig::ACTION_FLAG: 279 + case HeraldAdapter::ACTION_FLAG: 280 280 $target = PhabricatorFlagColor::getColorName($target); 281 281 break; 282 282 default:
src/applications/herald/engine/engine/HeraldInvalidConditionException.php src/applications/herald/engine/exception/HeraldInvalidConditionException.php
src/applications/herald/engine/engine/HeraldInvalidFieldException.php src/applications/herald/engine/exception/HeraldInvalidFieldException.php
src/applications/herald/engine/engine/HeraldRecursiveConditionsException.php src/applications/herald/engine/exception/HeraldRecursiveConditionsException.php
+3
src/applications/herald/engine/exception/HeraldInvalidActionException.php
··· 1 + <?php 2 + 3 + final class HeraldInvalidActionException extends Exception {}