ofborg/php/web/index.php

44 lines
1.1 KiB
PHP
Raw Normal View History

2017-10-29 21:10:26 +00:00
<?php
require_once __DIR__ . '/../config.php';
use PhpAmqpLib\Message\AMQPMessage;
$connection = rabbitmq_conn();
$channel = $connection->channel();
2017-10-31 08:09:06 +00:00
$raw = file_get_contents('php://input');
$input = json_decode($raw);
if (!isset($input->repository->full_name)) {
2017-10-29 21:10:26 +00:00
echo "no full_name set?";
2017-10-31 08:09:06 +00:00
exit();
} else {
echo "full_name present\n";
2017-10-29 21:10:26 +00:00
}
2017-10-31 08:09:06 +00:00
$name = strtolower($input->repository->full_name);
2017-10-29 21:10:26 +00:00
if (!GHE\ACL::isRepoEligible($name)) {
2017-10-31 08:09:06 +00:00
echo "repo not in ok name list";
exit(1);
} else {
echo "full_name ok\n";
2017-10-29 21:10:26 +00:00
}
2017-10-31 08:09:06 +00:00
$dec = $channel->exchange_declare('github-events', 'topic', false, true, false);
2017-10-29 21:10:26 +00:00
$message = new AMQPMessage(json_encode($input),
2017-10-31 08:09:06 +00:00
array(
'content_type' => 'application/json',
'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,
));
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);
2017-10-29 21:10:26 +00:00
2017-10-31 08:09:06 +00:00
echo "ok";