diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1357,6 +1357,7 @@ 'HeraldApplyTranscript' => 'applications/herald/storage/transcript/HeraldApplyTranscript.php', 'HeraldBasicFieldGroup' => 'applications/herald/field/HeraldBasicFieldGroup.php', 'HeraldBuildableState' => 'applications/herald/state/HeraldBuildableState.php', + 'HeraldCallWebhookAction' => 'applications/herald/action/HeraldCallWebhookAction.php', 'HeraldCommentAction' => 'applications/herald/action/HeraldCommentAction.php', 'HeraldCommitAdapter' => 'applications/diffusion/herald/HeraldCommitAdapter.php', 'HeraldCondition' => 'applications/herald/storage/HeraldCondition.php', @@ -1444,6 +1445,7 @@ 'HeraldWebhook' => 'applications/herald/storage/HeraldWebhook.php', 'HeraldWebhookCallManagementWorkflow' => 'applications/herald/management/HeraldWebhookCallManagementWorkflow.php', 'HeraldWebhookController' => 'applications/herald/controller/HeraldWebhookController.php', + 'HeraldWebhookDatasource' => 'applications/herald/typeahead/HeraldWebhookDatasource.php', 'HeraldWebhookEditController' => 'applications/herald/controller/HeraldWebhookEditController.php', 'HeraldWebhookEditEngine' => 'applications/herald/editor/HeraldWebhookEditEngine.php', 'HeraldWebhookEditor' => 'applications/herald/editor/HeraldWebhookEditor.php', @@ -6631,6 +6633,7 @@ 'HeraldApplyTranscript' => 'Phobject', 'HeraldBasicFieldGroup' => 'HeraldFieldGroup', 'HeraldBuildableState' => 'HeraldState', + 'HeraldCallWebhookAction' => 'HeraldAction', 'HeraldCommentAction' => 'HeraldAction', 'HeraldCommitAdapter' => array( 'HeraldAdapter', @@ -6741,6 +6744,7 @@ ), 'HeraldWebhookCallManagementWorkflow' => 'HeraldWebhookManagementWorkflow', 'HeraldWebhookController' => 'HeraldController', + 'HeraldWebhookDatasource' => 'PhabricatorTypeaheadDatasource', 'HeraldWebhookEditController' => 'HeraldWebhookController', 'HeraldWebhookEditEngine' => 'PhabricatorEditEngine', 'HeraldWebhookEditor' => 'PhabricatorApplicationTransactionEditor', diff --git a/src/applications/herald/action/HeraldCallWebhookAction.php b/src/applications/herald/action/HeraldCallWebhookAction.php new file mode 100644 --- /dev/null +++ b/src/applications/herald/action/HeraldCallWebhookAction.php @@ -0,0 +1,62 @@ +getAdapter(); + $rule = $effect->getRule(); + $target = $effect->getTarget(); + + foreach ($target as $webhook_phid) { + $adapter->queueWebhook($webhook_phid, $rule->getPHID()); + } + + $this->logEffect(self::DO_WEBHOOK, $target); + } + + public function getHeraldActionStandardType() { + return self::STANDARD_PHID_LIST; + } + + protected function getActionEffectMap() { + return array( + self::DO_WEBHOOK => array( + 'icon' => 'fa-cloud-upload', + 'color' => 'green', + 'name' => pht('Called Webhooks'), + ), + ); + } + + public function renderActionDescription($value) { + return pht('Call webhooks: %s.', $this->renderHandleList($value)); + } + + protected function renderActionEffectDescription($type, $data) { + return pht('Called webhooks: %s.', $this->renderHandleList($data)); + } + + protected function getDatasource() { + return new HeraldWebhookDatasource(); + } + +} diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -41,6 +41,7 @@ private $viewer; private $mustEncryptReasons = array(); private $actingAsPHID; + private $webhookMap = array(); public function getEmailPHIDs() { return array_values($this->emailPHIDs); @@ -1206,4 +1207,17 @@ return $this->mustEncryptReasons; } + +/* -( Webhooks )----------------------------------------------------------- */ + + + final public function queueWebhook($webhook_phid, $rule_phid) { + $this->webhookMap[$webhook_phid][] = $rule_phid; + return $this; + } + + final public function getWebhookMap() { + return $this->webhookMap; + } + } diff --git a/src/applications/herald/typeahead/HeraldWebhookDatasource.php b/src/applications/herald/typeahead/HeraldWebhookDatasource.php new file mode 100644 --- /dev/null +++ b/src/applications/herald/typeahead/HeraldWebhookDatasource.php @@ -0,0 +1,48 @@ +getViewer(); + $raw_query = $this->getRawQuery(); + + $hooks = id(new HeraldWebhookQuery()) + ->setViewer($viewer) + ->execute(); + + $handles = id(new PhabricatorHandleQuery()) + ->setViewer($viewer) + ->withPHIDs(mpull($hooks, 'getPHID')) + ->execute(); + + $results = array(); + foreach ($hooks as $hook) { + $handle = $handles[$hook->getPHID()]; + + $result = id(new PhabricatorTypeaheadResult()) + ->setName($handle->getFullName()) + ->setPHID($handle->getPHID()); + + if ($hook->isDisabled()) { + $result->setClosed(pht('Disabled')); + } + + $results[] = $result; + } + + return $results; + } +} diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php @@ -1156,6 +1156,7 @@ $adapter = $this->getHeraldAdapter(); $this->heraldEmailPHIDs = $adapter->getEmailPHIDs(); $this->heraldForcedEmailPHIDs = $adapter->getForcedEmailPHIDs(); + $this->webhookMap = $adapter->getWebhookMap(); } $xactions = $this->didApplyTransactions($object, $xactions);