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

Use Adapters to render Herald transcripts

Summary: Ref T2769. Use Adapters to build all the strings for transcripts, then get rid of the old maps.

Test Plan: Viewed revision and commit transcripts.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2769

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

+23 -167
+1
src/applications/herald/adapter/HeraldAdapter.php
··· 190 190 self::ACTION_REMOVE_CC => pht('Remove emails from CC'), 191 191 self::ACTION_EMAIL => pht('Send an email to'), 192 192 self::ACTION_AUDIT => pht('Trigger an Audit by'), 193 + self::ACTION_FLAG => pht('Mark with flag'), 193 194 ); 194 195 case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 195 196 return array(
-64
src/applications/herald/config/HeraldActionConfig.php
··· 9 9 const ACTION_AUDIT = 'audit'; 10 10 const ACTION_FLAG = 'flag'; 11 11 12 - // TODO: Remove; still used by transcripts. 13 - public static function getActionMessageMapForRuleType($rule_type) { 14 - $generic_mappings = array( 15 - self::ACTION_NOTHING => pht('Do nothing'), 16 - self::ACTION_ADD_CC => pht('Add emails to CC'), 17 - self::ACTION_REMOVE_CC => pht('Remove emails from CC'), 18 - self::ACTION_EMAIL => pht('Send an email to'), 19 - self::ACTION_AUDIT => pht('Trigger an Audit'), 20 - self::ACTION_FLAG => pht('Mark with flag'), 21 - ); 22 - 23 - switch ($rule_type) { 24 - case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 25 - $specific_mappings = array( 26 - self::ACTION_AUDIT => pht('Trigger an Audit for project'), 27 - ); 28 - break; 29 - case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 30 - $specific_mappings = array( 31 - self::ACTION_ADD_CC => pht('CC me'), 32 - self::ACTION_REMOVE_CC => pht('Remove me from CC'), 33 - self::ACTION_EMAIL => pht('Email me'), 34 - self::ACTION_AUDIT => pht('Trigger an Audit by me'), 35 - ); 36 - break; 37 - case null: 38 - $specific_mappings = array(); 39 - // Use generic mappings, used on transcript. 40 - break; 41 - default: 42 - throw new Exception("Unknown rule type '${rule_type}'"); 43 - } 44 - return $specific_mappings + $generic_mappings; 45 - } 46 - 47 - // TODO: Remove; still used by transcripts. 48 - public static function getActionMessageMap($content_type, 49 - $rule_type) { 50 - $map = self::getActionMessageMapForRuleType($rule_type); 51 - switch ($content_type) { 52 - case HeraldContentTypeConfig::CONTENT_TYPE_DIFFERENTIAL: 53 - return array_select_keys( 54 - $map, 55 - array( 56 - self::ACTION_ADD_CC, 57 - self::ACTION_REMOVE_CC, 58 - self::ACTION_EMAIL, 59 - self::ACTION_FLAG, 60 - self::ACTION_NOTHING, 61 - )); 62 - case HeraldContentTypeConfig::CONTENT_TYPE_COMMIT: 63 - return array_select_keys( 64 - $map, 65 - array( 66 - self::ACTION_EMAIL, 67 - self::ACTION_AUDIT, 68 - self::ACTION_FLAG, 69 - self::ACTION_NOTHING, 70 - )); 71 - default: 72 - throw new Exception("Unknown content type '{$content_type}'."); 73 - } 74 - } 75 - 76 12 /** 77 13 * Create a HeraldAction to save from data. 78 14 *
-25
src/applications/herald/config/HeraldConditionConfig.php
··· 21 21 const CONDITION_NOT_EXISTS = '!exists'; 22 22 const CONDITION_REGEXP_PAIR = 'regexp-pair'; 23 23 24 - // TODO: Remove; still used by Transcripts. 25 - public static function getConditionMap() { 26 - $map = array( 27 - self::CONDITION_CONTAINS => pht('contains'), 28 - self::CONDITION_NOT_CONTAINS => pht('does not contain'), 29 - self::CONDITION_IS => pht('is'), 30 - self::CONDITION_IS_NOT => pht('is not'), 31 - self::CONDITION_IS_ANY => pht('is any of'), 32 - self::CONDITION_IS_NOT_ANY => pht('is not any of'), 33 - self::CONDITION_INCLUDE_ALL => pht('include all of'), 34 - self::CONDITION_INCLUDE_ANY => pht('include any of'), 35 - self::CONDITION_INCLUDE_NONE => pht('include none of'), 36 - self::CONDITION_IS_ME => pht('is myself'), 37 - self::CONDITION_IS_NOT_ME => pht('is not myself'), 38 - self::CONDITION_REGEXP => pht('matches regexp'), 39 - self::CONDITION_RULE => pht('matches:'), 40 - self::CONDITION_NOT_RULE => pht('does not match:'), 41 - self::CONDITION_EXISTS => pht('exists'), 42 - self::CONDITION_NOT_EXISTS => pht('does not exist'), 43 - self::CONDITION_REGEXP_PAIR => pht('matches regexp pair'), 44 - ); 45 - 46 - return $map; 47 - } 48 - 49 24 }
-27
src/applications/herald/config/HeraldFieldConfig.php
··· 21 21 const FIELD_DIFFERENTIAL_REVIEWERS = 'differential-reviewers'; 22 22 const FIELD_DIFFERENTIAL_CCS = 'differential-ccs'; 23 23 24 - // TODO: Remove; still required by transcripts. 25 - public static function getFieldMap() { 26 - $map = array( 27 - self::FIELD_TITLE => pht('Title'), 28 - self::FIELD_BODY => pht('Body'), 29 - self::FIELD_AUTHOR => pht('Author'), 30 - self::FIELD_REVIEWER => pht('Reviewer'), 31 - self::FIELD_REVIEWERS => pht('Reviewers'), 32 - self::FIELD_CC => pht('CCs'), 33 - self::FIELD_TAGS => pht('Tags'), 34 - self::FIELD_DIFF_FILE => pht('Any changed filename'), 35 - self::FIELD_DIFF_CONTENT => pht('Any changed file content'), 36 - self::FIELD_REPOSITORY => pht('Repository'), 37 - self::FIELD_RULE => pht('Another Herald rule'), 38 - self::FIELD_AFFECTED_PACKAGE => pht('Any affected package'), 39 - self::FIELD_AFFECTED_PACKAGE_OWNER => 40 - pht("Any affected package's owner"), 41 - self::FIELD_NEED_AUDIT_FOR_PACKAGE => 42 - pht('Affected packages that need audit'), 43 - self::FIELD_DIFFERENTIAL_REVISION => pht('Differential revision'), 44 - self::FIELD_DIFFERENTIAL_REVIEWERS => pht('Differential reviewers'), 45 - self::FIELD_DIFFERENTIAL_CCS => pht('Differential CCs'), 46 - ); 47 - 48 - return $map; 49 - } 50 - 51 24 }
+22 -51
src/applications/herald/controller/HeraldTranscriptController.php
··· 9 9 private $id; 10 10 private $filter; 11 11 private $handles; 12 + private $adapter; 12 13 13 14 public function willProcessRequest(array $data) { 14 15 $this->id = $data['id']; ··· 17 18 if (empty($map[$this->filter])) { 18 19 $this->filter = self::FILTER_AFFECTED; 19 20 } 21 + } 22 + 23 + private function getAdapter() { 24 + return $this->adapter; 20 25 } 21 26 22 27 public function processRequest() { ··· 41 46 pht('Details of this transcript have been garbage collected.'))); 42 47 $nav->appendChild($notice); 43 48 } else { 49 + 50 + $this->adapter = HeraldAdapter::getAdapterForContentType( 51 + $object_xscript->getType()); 52 + 44 53 $filter = $this->getFilterPHIDs(); 45 54 $this->filterTranscript($xscript, $filter); 46 55 $phids = array_merge($filter, $this->getTranscriptPHIDs($xscript)); ··· 138 147 139 148 protected function getFilterPHIDs() { 140 149 return array($this->getRequest()->getUser()->getPHID()); 141 - 142 - /* TODO 143 - $viewer_id = $this->getRequest()->getUser()->getPHID(); 144 - 145 - $fbids = array(); 146 - if ($this->filter == self::FILTER_AFFECTED) { 147 - $fbids[] = $viewer_id; 148 - require_module_lazy('intern/subscriptions'); 149 - $datastore = new SubscriberDatabaseStore(); 150 - $lists = $datastore->getUserMailmanLists($viewer_id); 151 - foreach ($lists as $list) { 152 - $fbids[] = $list; 153 - } 154 - } 155 - return $fbids; 156 - */ 157 150 } 158 151 159 152 protected function getTranscriptPHIDs($xscript) { ··· 270 263 271 264 private function buildApplyTranscriptPanel($xscript) { 272 265 $handles = $this->handles; 266 + $adapter = $this->getAdapter(); 273 267 274 - $action_names = HeraldActionConfig::getActionMessageMapForRuleType(null); 268 + $rule_type_global = HeraldRuleTypeConfig::RULE_TYPE_GLOBAL; 269 + $action_names = $adapter->getActionNameMap($rule_type_global); 275 270 276 271 $rows = array(); 277 272 foreach ($xscript->getApplyTranscripts() as $apply_xscript) { ··· 307 302 } 308 303 309 304 $rows[] = array( 310 - $action_names[$apply_xscript->getAction()], 305 + idx($action_names, $apply_xscript->getAction(), pht('Unknown')), 311 306 $target, 312 307 hsprintf( 313 308 '<strong>Taken because:</strong> %s<br />'. ··· 344 339 private function buildActionTranscriptPanel($xscript) { 345 340 $action_xscript = mgroup($xscript->getApplyTranscripts(), 'getRuleID'); 346 341 347 - $field_names = HeraldFieldConfig::getFieldMap(); 348 - $condition_names = HeraldConditionConfig::getConditionMap(); 342 + $adapter = $this->getAdapter(); 343 + 344 + 345 + $field_names = $adapter->getFieldNameMap(); 346 + $condition_names = $adapter->getConditionNameMap(); 349 347 350 348 $handles = $this->handles; 351 349 ··· 379 377 pht( 380 378 '%s Condition: %s %s %s%s', 381 379 $result, 382 - $field_names[$cond->getFieldName()], 383 - $condition_names[$cond->getCondition()], 380 + idx($field_names, $cond->getFieldName(), pht('Unknown')), 381 + idx($condition_names, $cond->getCondition(), pht('Unknown')), 384 382 $this->renderConditionTestValue($cond, $handles), 385 383 $note)); 386 384 } ··· 398 396 } 399 397 400 398 $cond_markup[] = hsprintf('<li>%s %s</li>', $result, $rule->getReason()); 401 - 402 - /* 403 - if ($rule->getResult()) { 404 - $actions = idx($action_xscript, $rule_id, array()); 405 - if ($actions) { 406 - $cond_markup[] = <li><div class="action-header">Actions</div></li>; 407 - foreach ($actions as $action) { 408 - 409 - $target = $action->getTarget(); 410 - if ($target) { 411 - foreach ((array)$target as $k => $phid) { 412 - $target[$k] = $handles[$phid]->getName(); 413 - } 414 - $target = <strong>: {implode(', ', $target)}</strong>; 415 - } 416 - 417 - $cond_markup[] = 418 - <li> 419 - {$action_names[$action->getAction()]} 420 - {$target} 421 - </li>; 422 - } 423 - } 424 - } 425 - */ 426 399 $user_phid = $this->getRequest()->getUser()->getPHID(); 427 400 428 401 $name = $rule->getRuleName(); 429 - if ($rule->getRuleOwner() == $user_phid) { 430 - // $name = <a href={"/herald/rule/".$rule->getRuleID()."/"}>{$name}</a>; 431 - } 432 402 433 403 $rule_markup[] = 434 404 phutil_tag( ··· 458 428 459 429 private function buildObjectTranscriptPanel($xscript) { 460 430 461 - $field_names = HeraldFieldConfig::getFieldMap(); 431 + $adapter = $this->getAdapter(); 432 + $field_names = $adapter->getFieldNameMap(); 462 433 463 434 $object_xscript = $xscript->getObjectTranscript(); 464 435