2017-10-29 21:10:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require __DIR__ . '/config.php';
|
|
|
|
use PhpAmqpLib\Message\AMQPMessage;
|
|
|
|
|
|
|
|
# define('AMQP_DEBUG', true);
|
|
|
|
$connection = rabbitmq_conn();
|
|
|
|
$channel = $connection->channel();
|
|
|
|
$channel->basic_qos(null, 1, true);
|
|
|
|
|
|
|
|
list($queueName, , ) = $channel->queue_declare('build-results',
|
|
|
|
false, true, false, false);
|
|
|
|
|
|
|
|
function runner($msg) {
|
|
|
|
$body = json_decode($msg->body);
|
|
|
|
$in = $body->payload;
|
|
|
|
|
|
|
|
$num = $in->issue->number;
|
|
|
|
if ($body->success) {
|
|
|
|
echo "yay! $num passed!\n";
|
|
|
|
} else {
|
2017-11-04 15:57:34 +00:00
|
|
|
echo "Yikes, $num failed\n";
|
2017-10-29 21:10:26 +00:00
|
|
|
}
|
|
|
|
|
2017-10-29 21:48:48 +00:00
|
|
|
reply_to_issue($in, implode("\n", $body->output), $body->success, $body->system);
|
2017-10-29 21:10:26 +00:00
|
|
|
|
|
|
|
var_dump($body->success);
|
|
|
|
|
|
|
|
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
|
|
|
|
}
|
|
|
|
|
2017-10-29 21:48:48 +00:00
|
|
|
function reply_to_issue($issue, $output, $success, $system) {
|
2017-11-04 15:58:04 +00:00
|
|
|
$num = $issue->issue->number;
|
|
|
|
$owner = $issue->repository->owner->login;
|
|
|
|
$repo = $issue->repository->name;
|
|
|
|
$event = $success ? 'APPROVE' : 'COMMENT';
|
|
|
|
$passfail = $success ? "Success" : "Failure";
|
|
|
|
|
|
|
|
echo "Sending $event to $owner/$repo#$num with " . $passfail . " on $system\n";
|
|
|
|
|
2017-10-29 21:10:26 +00:00
|
|
|
$client = gh_client();
|
|
|
|
$pr = $client->api('pull_request')->show(
|
2017-11-04 15:58:04 +00:00
|
|
|
$owner,
|
|
|
|
$repo,
|
|
|
|
$num
|
2017-10-29 21:10:26 +00:00
|
|
|
);
|
2017-11-04 15:58:04 +00:00
|
|
|
|
|
|
|
if ($pr['state'] == 'closed') {
|
|
|
|
$event = 'COMMENT';
|
|
|
|
}
|
|
|
|
|
2017-10-29 21:10:26 +00:00
|
|
|
$sha = $pr['head']['sha'];
|
2017-11-04 15:58:04 +00:00
|
|
|
echo "Latest sha: $sha\n";
|
|
|
|
echo "Body:\n";
|
|
|
|
echo $output;
|
|
|
|
echo "\n\n";
|
2017-10-29 21:10:26 +00:00
|
|
|
|
|
|
|
$client->api('pull_request')->reviews()->create(
|
2017-11-04 15:58:04 +00:00
|
|
|
$owner,
|
|
|
|
$repo,
|
|
|
|
$num,
|
2017-10-29 21:10:26 +00:00
|
|
|
array(
|
2017-11-04 15:58:04 +00:00
|
|
|
'body' => "$passfail for system: $system\n\n```\n$output\n```",
|
|
|
|
'event' => $event,
|
2017-10-29 21:10:26 +00:00
|
|
|
'commit_id' => $sha,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function outrunner($msg) {
|
|
|
|
try {
|
|
|
|
return runner($msg);
|
2017-11-04 15:58:04 +00:00
|
|
|
} catch (GHE\ExecException $e) {
|
2017-10-29 21:10:26 +00:00
|
|
|
var_dump($e->getMessage());
|
|
|
|
var_dump($e->getCode());
|
|
|
|
var_dump($e->getOutput());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$consumerTag = 'consumer' . getmypid();
|
|
|
|
$channel->basic_consume($queueName, $consumerTag, false, false, false, false, 'outrunner');
|
|
|
|
while(count($channel->callbacks)) {
|
|
|
|
$channel->wait();
|
|
|
|
}
|