HTTP Code issue, response message
This commit is contained in:
parent
08227b3802
commit
15fb754801
22
event.php
22
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,
|
||||
]);
|
||||
|
||||
|
|
Loading…
Reference in a new issue