diff --git a/web/index.php b/web/index.php index 5435e52..3af86bc 100644 --- a/web/index.php +++ b/web/index.php @@ -6,22 +6,39 @@ use PhpAmqpLib\Message\AMQPMessage; $connection = rabbitmq_conn(); $channel = $connection->channel(); -$input = json_decode(file_get_contents('php://input'), true); -if (!isset($input['repository']['full_name'])) { +$raw = file_get_contents('php://input'); +$input = json_decode($raw); +if (!isset($input->repository->full_name)) { echo "no full_name set?"; - exit(0); + exit(); +} else { + echo "full_name present\n"; } - -$name = strtolower($input['repository']['full_name']); +$name = strtolower($input->repository->full_name); if (!GHE\ACL::isRepoEligible($name)) { - echo "repo not in ok name list"; - exit(1); + echo "repo not in ok name list"; + exit(1); +} else { + echo "full_name ok\n"; } -$channel->exchange_declare($name, 'fanout', false, true, false); +$dec = $channel->exchange_declare('github-events', 'topic', false, true, false); $message = new AMQPMessage(json_encode($input), - array('content_type' => 'application/json')); + array( + 'content_type' => 'application/json', + 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT, + )); -$channel->basic_publish($message, $name); +try { + $etype = \GHE\EventClassifier::classifyEvent($input); +} catch (\GHE\EventClassifierUnknownException $e) { + $etype = "unknown"; +} + +$routing_key = "$etype.$name"; +var_dump($routing_key); +$rec = $channel->basic_publish($message, 'github-events', $routing_key); + +echo "ok"; \ No newline at end of file