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

Trigger all "Firehose" webhooks on all transactional edits

Summary: Depends on D19047. Ref T11330. Triggers every firehose hook on every edit; prepares for Herald triggers.

Test Plan: Configured a firehose hook, edited some objects, saw callbacks.

Maniphest Tasks: T11330

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

+88 -3
+1
src/applications/herald/controller/HeraldWebhookTestController.php
··· 52 52 53 53 $request = HeraldWebhookRequest::initializeNewWebhookRequest($hook) 54 54 ->setObjectPHID($object->getPHID()) 55 + ->setTriggerPHIDs(array($viewer->getPHID())) 55 56 ->setIsTestAction(true) 56 57 ->setTransactionPHIDs(mpull($xactions, 'getPHID')) 57 58 ->save();
+9
src/applications/herald/editor/HeraldWebhookEditor.php
··· 19 19 return pht('%s created %s.', $author, $object); 20 20 } 21 21 22 + public function getTransactionTypes() { 23 + $types = parent::getTransactionTypes(); 24 + 25 + $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 26 + $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 27 + 28 + return $types; 29 + } 30 + 22 31 }
+3
src/applications/herald/management/HeraldWebhookCallManagementWorkflow.php
··· 78 78 ->setLimit(10) 79 79 ->execute(); 80 80 81 + $application_phid = id(new PhabricatorHeraldApplication())->getPHID(); 82 + 81 83 $request = HeraldWebhookRequest::initializeNewWebhookRequest($hook) 82 84 ->setObjectPHID($object->getPHID()) 83 85 ->setIsTestAction(true) 84 86 ->setIsSilentAction((bool)$args->getArg('silent')) 85 87 ->setIsSecureAction((bool)$args->getArg('secure')) 88 + ->setTriggerPHIDs(array($application_phid)) 86 89 ->setTransactionPHIDs(mpull($xactions, 'getPHID')) 87 90 ->save(); 88 91
+1 -2
src/applications/herald/phid/HeraldWebhookRequestPHIDType.php
··· 31 31 32 32 foreach ($handles as $phid => $handle) { 33 33 $request = $objects[$phid]; 34 - 35 - // TODO: Fill this in. 34 + $handle->setName(pht('Webhook Request %d', $request->getID())); 36 35 } 37 36 } 38 37
+8
src/applications/herald/storage/HeraldWebhookRequest.php
··· 116 116 return $this->getProperty('transactionPHIDs', array()); 117 117 } 118 118 119 + public function setTriggerPHIDs(array $phids) { 120 + return $this->setProperty('triggerPHIDs', $phids); 121 + } 122 + 123 + public function getTriggerPHIDs() { 124 + return $this->getProperty('triggerPHIDs', array()); 125 + } 126 + 119 127 public function setIsSilentAction($bool) { 120 128 return $this->setProperty('silent', $bool); 121 129 }
+9 -1
src/applications/herald/worker/HeraldWebhookWorker.php
··· 138 138 ); 139 139 } 140 140 141 + $trigger_data = array(); 142 + foreach ($request->getTriggerPHIDs() as $trigger_phid) { 143 + $trigger_data[] = array( 144 + 'phid' => $trigger_phid, 145 + ); 146 + } 147 + 141 148 $payload = array( 142 - 'triggers' => array(), 143 149 'object' => array( 150 + 'type' => phid_get_type($object->getPHID()), 144 151 'phid' => $object->getPHID(), 145 152 ), 153 + 'triggers' => $trigger_data, 146 154 'action' => array( 147 155 'test' => $request->getIsTestAction(), 148 156 'silent' => $request->getIsSilentAction(),
+57
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 79 79 private $mailRemovedPHIDs = array(); 80 80 private $mailUnexpandablePHIDs = array(); 81 81 private $mailMutedPHIDs = array(); 82 + private $webhookMap = array(); 82 83 83 84 private $transactionQueue = array(); 84 85 ··· 1306 1307 foreach ($messages as $mail) { 1307 1308 $mail->save(); 1308 1309 } 1310 + 1311 + $this->queueWebhooks($object, $xactions); 1309 1312 1310 1313 return $xactions; 1311 1314 } ··· 3660 3663 'mailStamps', 3661 3664 'mailUnexpandablePHIDs', 3662 3665 'mailMutedPHIDs', 3666 + 'webhookMap', 3667 + 'silent', 3663 3668 ); 3664 3669 } 3665 3670 ··· 4238 4243 } 4239 4244 4240 4245 return $this; 4246 + } 4247 + 4248 + private function queueWebhooks($object, array $xactions) { 4249 + $hook_viewer = PhabricatorUser::getOmnipotentUser(); 4250 + 4251 + $webhook_map = $this->webhookMap; 4252 + if (!is_array($webhook_map)) { 4253 + $webhook_map = array(); 4254 + } 4255 + 4256 + // Add any "Firehose" hooks to the list of hooks we're going to call. 4257 + $firehose_hooks = id(new HeraldWebhookQuery()) 4258 + ->setViewer($hook_viewer) 4259 + ->withStatuses( 4260 + array( 4261 + HeraldWebhook::HOOKSTATUS_FIREHOSE, 4262 + )) 4263 + ->execute(); 4264 + foreach ($firehose_hooks as $firehose_hook) { 4265 + // This is "the hook itself is the reason this hook is being called", 4266 + // since we're including it because it's configured as a firehose 4267 + // hook. 4268 + $hook_phid = $firehose_hook->getPHID(); 4269 + $webhook_map[$hook_phid][] = $hook_phid; 4270 + } 4271 + 4272 + if (!$webhook_map) { 4273 + return; 4274 + } 4275 + 4276 + // NOTE: We're going to queue calls to disabled webhooks, they'll just 4277 + // immediately fail in the worker queue. This makes the behavior more 4278 + // visible. 4279 + 4280 + $call_hooks = id(new HeraldWebhookQuery()) 4281 + ->setViewer($hook_viewer) 4282 + ->withPHIDs(array_keys($webhook_map)) 4283 + ->execute(); 4284 + 4285 + foreach ($call_hooks as $call_hook) { 4286 + $trigger_phids = idx($webhook_map, $call_hook->getPHID()); 4287 + 4288 + $request = HeraldWebhookRequest::initializeNewWebhookRequest($call_hook) 4289 + ->setObjectPHID($object->getPHID()) 4290 + ->setTransactionPHIDs(mpull($xactions, 'getPHID')) 4291 + ->setTriggerPHIDs($trigger_phids) 4292 + ->setIsSilentAction((bool)$this->getIsSilent()) 4293 + ->setIsSecureAction((bool)$this->getMustEncrypt()) 4294 + ->save(); 4295 + 4296 + $request->queueCall(); 4297 + } 4241 4298 } 4242 4299 4243 4300 }