2024-02-25 19:17:44 +01:00
|
|
|
<?php
|
|
|
|
# https://docs.gitea.com/usage/webhooks
|
|
|
|
|
|
|
|
// check for POST request
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
|
|
|
error_log('FAILED - not POST - '. $_SERVER['REQUEST_METHOD']);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// get content type
|
|
|
|
$content_type = isset($_SERVER['CONTENT_TYPE']) ? strtolower(trim($_SERVER['CONTENT_TYPE'])) : '';
|
|
|
|
|
|
|
|
if ($content_type != 'application/json') {
|
|
|
|
error_log('FAILED - not application/json - '. $content_type);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// get payload
|
|
|
|
$payload = trim(file_get_contents("php://input"));
|
|
|
|
|
|
|
|
if (empty($payload)) {
|
|
|
|
error_log('FAILED - no payload');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert json to array
|
|
|
|
$decoded = json_decode($payload, true);
|
|
|
|
|
|
|
|
// check for json decode errors
|
|
|
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
|
error_log('FAILED - json decode - '. json_last_error());
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// success, do something
|
2024-02-26 12:34:20 +01:00
|
|
|
$repo_name = $decoded['repository']['name'];
|
2024-02-25 22:18:51 +01:00
|
|
|
echo "launching hook script ";
|
2024-02-27 16:57:10 +01:00
|
|
|
echo shell_exec('bash ../webhook/webhook.sh ' . $repo_name . ' >> ../webhook/webhook.log 2>&1');
|
2024-02-25 19:17:44 +01:00
|
|
|
?>
|