diff --git a/src/app/Livewire/Admin/Versions.php b/src/app/Livewire/Admin/Versions.php index 6a6bad3..5a8d524 100644 --- a/src/app/Livewire/Admin/Versions.php +++ b/src/app/Livewire/Admin/Versions.php @@ -3,17 +3,21 @@ namespace App\Livewire\Admin; use App\Models\AppVersion; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Http; use Livewire\Component; class Versions extends Component { - public string $version = ''; - public string $name = ''; - public string $changelog = ''; - public string $status = 'draft'; - public string $platform = 'all'; - public bool $show_popup = true; - public ?string $editingId = null; + public string $version = ''; + public string $name = ''; + public string $changelog = ''; + public string $status = 'draft'; + public string $platform = 'all'; + public bool $show_popup = true; + public ?string $editingId = null; + public ?string $deployStatus = null; + public string $deployMessage = ''; public function getVersionsProperty() { @@ -75,6 +79,38 @@ class Versions extends Component AppVersion::find($id)->delete(); } + public function getGitInfoProperty(): array + { + $raw = shell_exec('git -C /aziros log -1 --pretty=format:"%h|%s|%ci" 2>/dev/null'); + if (!$raw) return ['hash' => '—', 'message' => '—', 'date' => '—']; + [$hash, $message, $date] = array_pad(explode('|', trim($raw), 3), 3, '—'); + return ['hash' => $hash, 'message' => $message, 'date' => $date]; + } + + public function triggerDeploy(): void + { + $secret = env('DEPLOY_WEBHOOK_SECRET', ''); + $url = 'http://10.10.90.103:9000/deploy'; + + try { + $response = Http::withHeaders(['X-Webhook-Secret' => $secret]) + ->timeout(10) + ->post($url); + + if ($response->successful()) { + $this->deployStatus = 'success'; + $this->deployMessage = $response->body() ?: 'Deploy gestartet'; + Cache::put('last_deploy_triggered_at', now()->toIso8601String(), 86400); + } else { + $this->deployStatus = 'error'; + $this->deployMessage = 'HTTP ' . $response->status(); + } + } catch (\Throwable $e) { + $this->deployStatus = 'error'; + $this->deployMessage = $e->getMessage(); + } + } + public function render() { return view('livewire.admin.versions') diff --git a/src/resources/views/livewire/admin/versions.blade.php b/src/resources/views/livewire/admin/versions.blade.php index 93b9761..3aaa50e 100644 --- a/src/resources/views/livewire/admin/versions.blade.php +++ b/src/resources/views/livewire/admin/versions.blade.php @@ -69,6 +69,74 @@ + {{-- Webhook --}} + @php + $lastTrigger = \Illuminate\Support\Facades\Cache::get('last_deploy_triggered_at'); + $git = $this->gitInfo; + @endphp +
Letzter Commit
+{{ $git['hash'] }}
+{{ $git['message'] }}
+Commit-Datum
+{{ $git['date'] !== '—' ? \Carbon\Carbon::parse($git['date'])->format('d.m.Y H:i') : '—' }}
+Letzter Deploy
++ {{ $lastTrigger ? \Carbon\Carbon::parse($lastTrigger)->format('d.m.Y H:i') : '—' }} +
+