Differential D19046 Diff 45670 src/applications/herald/management/HeraldWebhookCallManagementWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/management/HeraldWebhookCallManagementWorkflow.php
<?php | <?php | ||||
final class HeraldWebhookCallManagementWorkflow | final class HeraldWebhookCallManagementWorkflow | ||||
extends HeraldWebhookManagementWorkflow { | extends HeraldWebhookManagementWorkflow { | ||||
protected function didConstruct() { | protected function didConstruct() { | ||||
$this | $this | ||||
->setName('call') | ->setName('call') | ||||
->setExamples('**call** --id __id__') | ->setExamples('**call** --id __id__ [--object __object__]') | ||||
->setSynopsis(pht('Call a webhook.')) | ->setSynopsis(pht('Call a webhook.')) | ||||
->setArguments( | ->setArguments( | ||||
array( | array( | ||||
array( | array( | ||||
'name' => 'id', | 'name' => 'id', | ||||
'param' => 'id', | 'param' => 'id', | ||||
'help' => pht('Webhook ID to call'), | 'help' => pht('Webhook ID to call'), | ||||
), | ), | ||||
array( | |||||
'name' => 'object', | |||||
'param' => 'object', | |||||
'help' => pht('Submit transactions for a particular object.'), | |||||
), | |||||
array( | |||||
'name' => 'silent', | |||||
'help' => pht('Set the "silent" flag on the request.'), | |||||
), | |||||
array( | |||||
'name' => 'secure', | |||||
'help' => pht('Set the "secure" flag on the request.'), | |||||
), | |||||
)); | )); | ||||
} | } | ||||
public function execute(PhutilArgumentParser $args) { | public function execute(PhutilArgumentParser $args) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$id = $args->getArg('id'); | $id = $args->getArg('id'); | ||||
if (!$id) { | if (!$id) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
'Specify a webhook to call with "--id".')); | 'Specify a webhook to call with "--id".')); | ||||
} | } | ||||
$hook = id(new HeraldWebhookQuery()) | $hook = id(new HeraldWebhookQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIDs(array($id)) | ->withIDs(array($id)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$hook) { | if (!$hook) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
'Unable to load specified webhook ("%s").', | 'Unable to load specified webhook ("%s").', | ||||
$id)); | $id)); | ||||
} | } | ||||
$object_name = $args->getArg('object'); | |||||
if ($object_name === null) { | |||||
$object = $hook; | $object = $hook; | ||||
} else { | |||||
$objects = id(new PhabricatorObjectQuery()) | |||||
->setViewer($viewer) | |||||
->withNames(array($object_name)) | |||||
->execute(); | |||||
if (!$objects) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Unable to load specified object ("%s").', | |||||
$object_name)); | |||||
} | |||||
$object = head($objects); | |||||
} | |||||
$xaction_query = | |||||
PhabricatorApplicationTransactionQuery::newQueryForObject($object); | |||||
$application_phid = id(new PhabricatorHeraldApplication())->getPHID(); | $xactions = $xaction_query | ||||
->withObjectPHIDs(array($object->getPHID())) | |||||
->setViewer($viewer) | |||||
->setLimit(10) | |||||
->execute(); | |||||
$request = HeraldWebhookRequest::initializeNewWebhookRequest($hook) | $request = HeraldWebhookRequest::initializeNewWebhookRequest($hook) | ||||
->setObjectPHID($object->getPHID()) | ->setObjectPHID($object->getPHID()) | ||||
->setIsTestAction(true) | |||||
->setIsSilentAction((bool)$args->getArg('silent')) | |||||
->setIsSecureAction((bool)$args->getArg('secure')) | |||||
->setTransactionPHIDs(mpull($xactions, 'getPHID')) | |||||
->save(); | ->save(); | ||||
PhabricatorWorker::setRunAllTasksInProcess(true); | PhabricatorWorker::setRunAllTasksInProcess(true); | ||||
$request->queueCall(); | $request->queueCall(); | ||||
$request->reload(); | $request->reload(); | ||||
echo tsprintf( | echo tsprintf( | ||||
Show All 9 Lines |