From 15fb754801143e3d1db922c18bb1edcb752e55b1 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sat, 30 Jan 2016 21:42:21 +0100 Subject: [PATCH] HTTP Code issue, response message --- event.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/event.php b/event.php index b30d3b1..815e241 100644 --- a/event.php +++ b/event.php @@ -6,23 +6,23 @@ function httpCode($code) { } function response(array $content, $code = 200) { - httpCode($code); header('Content-type: application/json'); + httpCode($code); echo json_encode($content); - exit; } function badSecret() { - httpCode(403); - response([ - 'error' => 'Invalid secret', - ]); + response( + [ + 'error' => 'Invalid secret', + ], + 403 + ); } function badRequest(array $content = []) { - httpCode(400); - response($content); + response($content, 404); } function requiredBagVar($bag, $index) { @@ -45,9 +45,7 @@ requiredBagVar($_POST, 'payload'); $payload = json_decode($_POST['payload'], true); requiredBagVar($payload, 'secret'); - $accounts = require 'accounts.php'; - if (!isValidSecret($payload['secret'], $accounts)) { badSecret(); } @@ -59,7 +57,7 @@ $command = 'sudo -u git $HOME/bin/webhook-project '.escapeshellarg($repository); $execute = shell_exec($command); response([ - 'data' => $repository, - 'exec' => $command, + 'action' => 'Gitnet project push event', + 'output' => $execute, ]);