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

Provide basic commit content hooks for Herald

Summary: Ref T4195. This doesn't provide any interesting fields yet (content, affected paths, commit message) but fires the hook correctly.

Test Plan: Added a blocking hook and saw it fire.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4195

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

+157 -12
+2
src/__phutil_library_map__.php
··· 756 756 'HeraldObjectTranscript' => 'applications/herald/storage/transcript/HeraldObjectTranscript.php', 757 757 'HeraldPHIDTypeRule' => 'applications/herald/phid/HeraldPHIDTypeRule.php', 758 758 'HeraldPholioMockAdapter' => 'applications/herald/adapter/HeraldPholioMockAdapter.php', 759 + 'HeraldPreCommitContentAdapter' => 'applications/diffusion/herald/HeraldPreCommitContentAdapter.php', 759 760 'HeraldPreCommitRefAdapter' => 'applications/diffusion/herald/HeraldPreCommitRefAdapter.php', 760 761 'HeraldRecursiveConditionsException' => 'applications/herald/engine/exception/HeraldRecursiveConditionsException.php', 761 762 'HeraldRemarkupRule' => 'applications/herald/remarkup/HeraldRemarkupRule.php', ··· 3180 3181 'HeraldNewController' => 'HeraldController', 3181 3182 'HeraldPHIDTypeRule' => 'PhabricatorPHIDType', 3182 3183 'HeraldPholioMockAdapter' => 'HeraldAdapter', 3184 + 'HeraldPreCommitContentAdapter' => 'HeraldAdapter', 3183 3185 'HeraldPreCommitRefAdapter' => 'HeraldAdapter', 3184 3186 'HeraldRecursiveConditionsException' => 'Exception', 3185 3187 'HeraldRemarkupRule' => 'PhabricatorRemarkupRuleObject',
+34 -11
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
··· 132 132 throw $ex; 133 133 } 134 134 135 - $this->applyHeraldRefRules($ref_updates); 135 + $this->applyHeraldRefRules($ref_updates, $all_updates); 136 136 137 137 $content_updates = $this->findContentUpdates($ref_updates); 138 138 $all_updates = array_merge($all_updates, $content_updates); 139 139 140 - // TODO: Fire content Herald rules. 140 + $this->applyHeraldContentRules($content_updates, $all_updates); 141 + 141 142 // TODO: Fire external hooks. 142 143 143 144 // If we make it this far, we're accepting these changes. Mark all the ··· 225 226 226 227 /* -( Herald )------------------------------------------------------------- */ 227 228 229 + private function applyHeraldRefRules( 230 + array $ref_updates, 231 + array $all_updates) { 232 + $this->applyHeraldRules( 233 + $ref_updates, 234 + new HeraldPreCommitRefAdapter(), 235 + $all_updates); 236 + } 228 237 229 - private function applyHeraldRefRules(array $ref_updates) { 230 - if (!$ref_updates) { 238 + private function applyHeraldContentRules( 239 + array $content_updates, 240 + array $all_updates) { 241 + $this->applyHeraldRules( 242 + $content_updates, 243 + new HeraldPreCommitContentAdapter(), 244 + $all_updates); 245 + } 246 + 247 + private function applyHeraldRules( 248 + array $updates, 249 + HeraldAdapter $adapter_template, 250 + array $all_updates) { 251 + 252 + if (!$updates) { 231 253 return; 232 254 } 255 + 256 + $adapter_template->setHookEngine($this); 233 257 234 258 $engine = new HeraldEngine(); 235 259 $rules = null; 236 260 $blocking_effect = null; 237 - foreach ($ref_updates as $ref_update) { 238 - $adapter = id(new HeraldPreCommitRefAdapter()) 239 - ->setPushLog($ref_update) 240 - ->setHookEngine($this); 261 + foreach ($updates as $update) { 262 + $adapter = id(clone $adapter_template) 263 + ->setPushLog($update); 241 264 242 265 if ($rules === null) { 243 266 $rules = $engine->loadRulesForAdapter($adapter); ··· 258 281 } 259 282 260 283 if ($blocking_effect) { 261 - foreach ($ref_updates as $ref_update) { 262 - $ref_update->setRejectCode(PhabricatorRepositoryPushLog::REJECT_HERALD); 263 - $ref_update->setRejectDetails($blocking_effect->getRulePHID()); 284 + foreach ($all_updates as $update) { 285 + $update->setRejectCode(PhabricatorRepositoryPushLog::REJECT_HERALD); 286 + $update->setRejectDetails($blocking_effect->getRulePHID()); 264 287 } 265 288 266 289 $message = $blocking_effect->getTarget();
+120
src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
··· 1 + <?php 2 + 3 + final class HeraldPreCommitContentAdapter extends HeraldAdapter { 4 + 5 + private $log; 6 + private $hookEngine; 7 + 8 + public function setPushLog(PhabricatorRepositoryPushLog $log) { 9 + $this->log = $log; 10 + return $this; 11 + } 12 + 13 + public function setHookEngine(DiffusionCommitHookEngine $engine) { 14 + $this->hookEngine = $engine; 15 + return $this; 16 + } 17 + 18 + public function getAdapterApplicationClass() { 19 + return 'PhabricatorApplicationDiffusion'; 20 + } 21 + 22 + public function getObject() { 23 + return $this->log; 24 + } 25 + 26 + public function getAdapterContentName() { 27 + return pht('Commit Hook: Commit Content'); 28 + } 29 + 30 + public function getFieldNameMap() { 31 + return array( 32 + ) + parent::getFieldNameMap(); 33 + } 34 + 35 + public function getFields() { 36 + return array_merge( 37 + array( 38 + self::FIELD_REPOSITORY, 39 + self::FIELD_PUSHER, 40 + self::FIELD_PUSHER_PROJECTS, 41 + self::FIELD_RULE, 42 + ), 43 + parent::getFields()); 44 + } 45 + 46 + public function getConditionsForField($field) { 47 + switch ($field) { 48 + } 49 + return parent::getConditionsForField($field); 50 + } 51 + 52 + public function getActions($rule_type) { 53 + switch ($rule_type) { 54 + case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 55 + return array( 56 + self::ACTION_BLOCK, 57 + self::ACTION_NOTHING 58 + ); 59 + case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 60 + return array( 61 + self::ACTION_NOTHING, 62 + ); 63 + } 64 + } 65 + 66 + public function getValueTypeForFieldAndCondition($field, $condition) { 67 + return parent::getValueTypeForFieldAndCondition($field, $condition); 68 + } 69 + 70 + public function getPHID() { 71 + return $this->getObject()->getPHID(); 72 + } 73 + 74 + public function getHeraldName() { 75 + return pht('Push Log'); 76 + } 77 + 78 + public function getHeraldField($field) { 79 + $log = $this->getObject(); 80 + switch ($field) { 81 + case self::FIELD_REPOSITORY: 82 + return $this->hookEngine->getRepository()->getPHID(); 83 + case self::FIELD_PUSHER: 84 + return $this->hookEngine->getViewer()->getPHID(); 85 + case self::FIELD_PUSHER_PROJECTS: 86 + return $this->hookEngine->loadViewerProjectPHIDsForHerald(); 87 + } 88 + 89 + return parent::getHeraldField($field); 90 + } 91 + 92 + 93 + public function applyHeraldEffects(array $effects) { 94 + assert_instances_of($effects, 'HeraldEffect'); 95 + 96 + $result = array(); 97 + foreach ($effects as $effect) { 98 + $action = $effect->getAction(); 99 + switch ($action) { 100 + case self::ACTION_NOTHING: 101 + $result[] = new HeraldApplyTranscript( 102 + $effect, 103 + true, 104 + pht('Did nothing.')); 105 + break; 106 + case self::ACTION_BLOCK: 107 + $result[] = new HeraldApplyTranscript( 108 + $effect, 109 + true, 110 + pht('Blocked push.')); 111 + break; 112 + default: 113 + throw new Exception(pht('No rules to handle action "%s"!', $action)); 114 + } 115 + } 116 + 117 + return $result; 118 + } 119 + 120 + }
+1 -1
src/applications/herald/storage/HeraldRule.php
··· 16 16 protected $ruleType; 17 17 protected $isDisabled = 0; 18 18 19 - protected $configVersion = 16; 19 + protected $configVersion = 17; 20 20 21 21 // phids for which this rule has been applied 22 22 private $ruleApplied = self::ATTACHABLE;