1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

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
This commit is contained in:
epriestley 2018-02-09 11:48:41 -08:00
parent 4887c6aa80
commit 41d28abfcc
7 changed files with 88 additions and 3 deletions

View file

@ -52,6 +52,7 @@ final class HeraldWebhookTestController
$request = HeraldWebhookRequest::initializeNewWebhookRequest($hook) $request = HeraldWebhookRequest::initializeNewWebhookRequest($hook)
->setObjectPHID($object->getPHID()) ->setObjectPHID($object->getPHID())
->setTriggerPHIDs(array($viewer->getPHID()))
->setIsTestAction(true) ->setIsTestAction(true)
->setTransactionPHIDs(mpull($xactions, 'getPHID')) ->setTransactionPHIDs(mpull($xactions, 'getPHID'))
->save(); ->save();

View file

@ -19,4 +19,13 @@ final class HeraldWebhookEditor
return pht('%s created %s.', $author, $object); return pht('%s created %s.', $author, $object);
} }
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
return $types;
}
} }

View file

@ -78,11 +78,14 @@ final class HeraldWebhookCallManagementWorkflow
->setLimit(10) ->setLimit(10)
->execute(); ->execute();
$application_phid = id(new PhabricatorHeraldApplication())->getPHID();
$request = HeraldWebhookRequest::initializeNewWebhookRequest($hook) $request = HeraldWebhookRequest::initializeNewWebhookRequest($hook)
->setObjectPHID($object->getPHID()) ->setObjectPHID($object->getPHID())
->setIsTestAction(true) ->setIsTestAction(true)
->setIsSilentAction((bool)$args->getArg('silent')) ->setIsSilentAction((bool)$args->getArg('silent'))
->setIsSecureAction((bool)$args->getArg('secure')) ->setIsSecureAction((bool)$args->getArg('secure'))
->setTriggerPHIDs(array($application_phid))
->setTransactionPHIDs(mpull($xactions, 'getPHID')) ->setTransactionPHIDs(mpull($xactions, 'getPHID'))
->save(); ->save();

View file

@ -31,8 +31,7 @@ final class HeraldWebhookRequestPHIDType extends PhabricatorPHIDType {
foreach ($handles as $phid => $handle) { foreach ($handles as $phid => $handle) {
$request = $objects[$phid]; $request = $objects[$phid];
$handle->setName(pht('Webhook Request %d', $request->getID()));
// TODO: Fill this in.
} }
} }

View file

@ -116,6 +116,14 @@ final class HeraldWebhookRequest
return $this->getProperty('transactionPHIDs', array()); return $this->getProperty('transactionPHIDs', array());
} }
public function setTriggerPHIDs(array $phids) {
return $this->setProperty('triggerPHIDs', $phids);
}
public function getTriggerPHIDs() {
return $this->getProperty('triggerPHIDs', array());
}
public function setIsSilentAction($bool) { public function setIsSilentAction($bool) {
return $this->setProperty('silent', $bool); return $this->setProperty('silent', $bool);
} }

View file

@ -138,11 +138,19 @@ final class HeraldWebhookWorker
); );
} }
$trigger_data = array();
foreach ($request->getTriggerPHIDs() as $trigger_phid) {
$trigger_data[] = array(
'phid' => $trigger_phid,
);
}
$payload = array( $payload = array(
'triggers' => array(),
'object' => array( 'object' => array(
'type' => phid_get_type($object->getPHID()),
'phid' => $object->getPHID(), 'phid' => $object->getPHID(),
), ),
'triggers' => $trigger_data,
'action' => array( 'action' => array(
'test' => $request->getIsTestAction(), 'test' => $request->getIsTestAction(),
'silent' => $request->getIsSilentAction(), 'silent' => $request->getIsSilentAction(),

View file

@ -79,6 +79,7 @@ abstract class PhabricatorApplicationTransactionEditor
private $mailRemovedPHIDs = array(); private $mailRemovedPHIDs = array();
private $mailUnexpandablePHIDs = array(); private $mailUnexpandablePHIDs = array();
private $mailMutedPHIDs = array(); private $mailMutedPHIDs = array();
private $webhookMap = array();
private $transactionQueue = array(); private $transactionQueue = array();
@ -1307,6 +1308,8 @@ abstract class PhabricatorApplicationTransactionEditor
$mail->save(); $mail->save();
} }
$this->queueWebhooks($object, $xactions);
return $xactions; return $xactions;
} }
@ -3660,6 +3663,8 @@ abstract class PhabricatorApplicationTransactionEditor
'mailStamps', 'mailStamps',
'mailUnexpandablePHIDs', 'mailUnexpandablePHIDs',
'mailMutedPHIDs', 'mailMutedPHIDs',
'webhookMap',
'silent',
); );
} }
@ -4240,4 +4245,56 @@ abstract class PhabricatorApplicationTransactionEditor
return $this; return $this;
} }
private function queueWebhooks($object, array $xactions) {
$hook_viewer = PhabricatorUser::getOmnipotentUser();
$webhook_map = $this->webhookMap;
if (!is_array($webhook_map)) {
$webhook_map = array();
}
// Add any "Firehose" hooks to the list of hooks we're going to call.
$firehose_hooks = id(new HeraldWebhookQuery())
->setViewer($hook_viewer)
->withStatuses(
array(
HeraldWebhook::HOOKSTATUS_FIREHOSE,
))
->execute();
foreach ($firehose_hooks as $firehose_hook) {
// This is "the hook itself is the reason this hook is being called",
// since we're including it because it's configured as a firehose
// hook.
$hook_phid = $firehose_hook->getPHID();
$webhook_map[$hook_phid][] = $hook_phid;
}
if (!$webhook_map) {
return;
}
// NOTE: We're going to queue calls to disabled webhooks, they'll just
// immediately fail in the worker queue. This makes the behavior more
// visible.
$call_hooks = id(new HeraldWebhookQuery())
->setViewer($hook_viewer)
->withPHIDs(array_keys($webhook_map))
->execute();
foreach ($call_hooks as $call_hook) {
$trigger_phids = idx($webhook_map, $call_hook->getPHID());
$request = HeraldWebhookRequest::initializeNewWebhookRequest($call_hook)
->setObjectPHID($object->getPHID())
->setTransactionPHIDs(mpull($xactions, 'getPHID'))
->setTriggerPHIDs($trigger_phids)
->setIsSilentAction((bool)$this->getIsSilent())
->setIsSecureAction((bool)$this->getMustEncrypt())
->save();
$request->queueCall();
}
}
} }