<?php
// комментарий
$key = "developer@zachem.info";
$payload = trim(file_get_contents("php://input"));

$hash = hash_hmac('sha256', $payload, $key, false);

$signature = $_SERVER['HTTP_X_GITEA_SIGNATURE']?? '';

// check payload signature against header signature
if ($hash !== $signature)
{
	error_log('FAILED - payload signature mismatch');
	exit("wrong signature");
}

$json = json_decode($payload, true);

if (json_last_error() !== JSON_ERROR_NONE)
{
	error_log('FAILED - json decode - '. json_last_error());
	exit(json_last_error());
}

if($json['total_commits'] > 0)
{ 
	//$result = shell_exec("cd /var/www/lk && git reset --hard HEAD && git pull && npm run build"); 
	$result = shell_exec("cd /var/www/lk && git reset --hard HEAD && git pull && composer update && composer install && php artisan migrate && npm run build && php artisan optimize:clear");
	echo "<p>$result</p>" ; 
}

