3 final class HeraldWebhookCallManagementWorkflow
4 extends HeraldWebhookManagementWorkflow
{
6 protected function didConstruct() {
9 ->setExamples('**call** --id __id__ [--object __object__]')
10 ->setSynopsis(pht('Call a webhook.'))
16 'help' => pht('Webhook ID to call'),
21 'help' => pht('Submit transactions for a particular object.'),
25 'help' => pht('Set the "silent" flag on the request.'),
29 'help' => pht('Set the "secure" flag on the request.'),
34 'help' => pht('Make a total of __N__ copies of the call.'),
37 'name' => 'background',
39 'Instead of making calls in the foreground, add the tasks '.
40 'to the daemon queue.'),
45 public function execute(PhutilArgumentParser
$args) {
46 $viewer = $this->getViewer();
48 $id = $args->getArg('id');
50 throw new PhutilArgumentUsageException(
52 'Specify a webhook to call with "--id".'));
55 $count = $args->getArg('count');
56 if ($count === null) {
61 throw new PhutilArgumentUsageException(
63 'Specified "--count" must be larger than 0.'));
66 $hook = id(new HeraldWebhookQuery())
71 throw new PhutilArgumentUsageException(
73 'Unable to load specified webhook ("%s").',
77 $object_name = $args->getArg('object');
78 if ($object_name === null) {
81 $objects = id(new PhabricatorObjectQuery())
83 ->withNames(array($object_name))
86 throw new PhutilArgumentUsageException(
88 'Unable to load specified object ("%s").',
91 $object = head($objects);
94 $is_background = $args->getArg('background');
97 PhabricatorApplicationTransactionQuery
::newQueryForObject($object);
99 $xactions = $xaction_query
100 ->withObjectPHIDs(array($object->getPHID()))
105 $application_phid = id(new PhabricatorHeraldApplication())->getPHID();
107 if ($is_background) {
111 'Queueing webhook calls...'));
112 $progress_bar = id(new PhutilConsoleProgressBar())
118 'Calling webhook...'));
119 PhabricatorWorker
::setRunAllTasksInProcess(true);
122 for ($ii = 0; $ii < $count; $ii++
) {
123 $request = HeraldWebhookRequest
::initializeNewWebhookRequest($hook)
124 ->setObjectPHID($object->getPHID())
125 ->setIsTestAction(true)
126 ->setIsSilentAction((bool)$args->getArg('silent'))
127 ->setIsSecureAction((bool)$args->getArg('secure'))
128 ->setTriggerPHIDs(array($application_phid))
129 ->setTransactionPHIDs(mpull($xactions, 'getPHID'))
132 $request->queueCall();
134 if ($is_background) {
135 $progress_bar->update(1);
142 'Success, got HTTP %s from webhook.',
143 $request->getErrorCode()));
147 if ($is_background) {
148 $progress_bar->done();