Files
WMS/app/Http/Controllers/Git/GiteaWebhookController.php
T
2026-06-24 12:37:05 +01:00

68 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Git;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Log;
final class GiteaWebhookController extends Controller
{
/**
* Handle an incoming Gitea webhook delivery.
*/
public function __invoke(Request $request): JsonResponse
{
Log::info('Gitea webhook endpoint hit.', [
'event' => $request->header('X-Gitea-Event'),
'delivery' => $request->header('X-Gitea-Delivery'),
'authorization_present' => $request->headers->has('Authorization'),
'signature_present' => $request->headers->has('X-Gitea-Signature'),
]);
$event = (string) $request->header('X-Gitea-Event');
$payload = $request->json()->all();
if ($event !== 'push') {
return response()->json([
'message' => 'Gitea webhook ignored.',
'event' => $event,
]);
}
$commits = $request->input('commits', []);
Log::info('Gitea push webhook received.', [
'repository' => data_get($payload, 'repository.full_name'),
'ref' => data_get($payload, 'ref'),
'branch' => str_replace('refs/heads/', '', (string) data_get($payload, 'ref')),
'before' => data_get($payload, 'before'),
'after' => data_get($payload, 'after'),
'commit_count' => count($commits),
]);
foreach ($commits as $commit) {
Log::info('Gitea commit received.', [
'sha' => data_get($commit, 'id'),
'message' => data_get($commit, 'message'),
'url' => data_get($commit, 'url'),
'author_name' => data_get($commit, 'author.name'),
'author_email' => data_get($commit, 'author.email'),
'timestamp' => data_get($commit, 'timestamp'),
'added' => data_get($commit, 'added', []),
'modified' => data_get($commit, 'modified', []),
'removed' => data_get($commit, 'removed', []),
]);
}
return response()->json([
'message' => 'Gitea push processed.',
'repository' => data_get($payload, 'repository.full_name'),
'branch' => str_replace('refs/heads/', '', (string) data_get($payload, 'ref')),
'commit_count' => count($commits),
]);
}
}