Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/bot/PhabricatorBot.php
| Show All 13 Lines | final class PhabricatorBot extends PhabricatorDaemon { | ||||
| private $conduit; | private $conduit; | ||||
| private $config; | private $config; | ||||
| private $pollFrequency; | private $pollFrequency; | ||||
| protected function run() { | protected function run() { | ||||
| $argv = $this->getArgv(); | $argv = $this->getArgv(); | ||||
| if (count($argv) !== 1) { | if (count($argv) !== 1) { | ||||
| throw new Exception('usage: PhabricatorBot <json_config_file>'); | throw new Exception( | ||||
| pht( | |||||
| 'Usage: %s %s', | |||||
| __CLASS__, | |||||
| '<json_config_file>')); | |||||
| } | } | ||||
| $json_raw = Filesystem::readFile($argv[0]); | $json_raw = Filesystem::readFile($argv[0]); | ||||
| try { | try { | ||||
| $config = phutil_json_decode($json_raw); | $config = phutil_json_decode($json_raw); | ||||
| } catch (PhutilJSONParserException $ex) { | } catch (PhutilJSONParserException $ex) { | ||||
| throw new PhutilProxyException( | throw new PhutilProxyException( | ||||
| pht("File '%s' is not valid JSON!", $argv[0]), | pht("File '%s' is not valid JSON!", $argv[0]), | ||||
| Show All 36 Lines | if ($conduit_uri) { | ||||
| $conduit->setConduitToken($conduit_token); | $conduit->setConduitToken($conduit_token); | ||||
| } else { | } else { | ||||
| $conduit_user = idx($config, 'conduit.user'); | $conduit_user = idx($config, 'conduit.user'); | ||||
| $conduit_cert = idx($config, 'conduit.cert'); | $conduit_cert = idx($config, 'conduit.cert'); | ||||
| $response = $conduit->callMethodSynchronous( | $response = $conduit->callMethodSynchronous( | ||||
| 'conduit.connect', | 'conduit.connect', | ||||
| array( | array( | ||||
| 'client' => 'PhabricatorBot', | 'client' => __CLASS__, | ||||
| 'clientVersion' => '1.0', | 'clientVersion' => '1.0', | ||||
| 'clientDescription' => php_uname('n').':'.$nick, | 'clientDescription' => php_uname('n').':'.$nick, | ||||
| 'host' => $conduit_host, | 'host' => $conduit_host, | ||||
| 'user' => $conduit_user, | 'user' => $conduit_user, | ||||
| 'certificate' => $conduit_cert, | 'certificate' => $conduit_cert, | ||||
| )); | )); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines | |||||