diff --git a/public/assets/desktop/desktop.js b/public/assets/desktop/desktop.js index bb0a2199..370d37b1 100644 --- a/public/assets/desktop/desktop.js +++ b/public/assets/desktop/desktop.js @@ -519,10 +519,26 @@ if (payloadNode) { const nextPoll = Number(data.poll_seconds || 5); updateGiteaTrayUi(state, message); + emitDebug({ + type: 'gitea:deploy-status', + source: 'gitea-addon', + status: response.status, + ok: response.ok, + message, + state, + poll_seconds: nextPoll, + diagnostics: data.diagnostics || null, + running_jobs: Array.isArray(data.running_jobs) ? data.running_jobs.length : 0, + }); scheduleGiteaStatusPoll(nextPoll); return data; } catch (_error) { updateGiteaTrayUi('error', 'Gitea-Deploy-Status konnte nicht geladen werden.'); + emitDebug({ + type: 'gitea:deploy-status:error', + source: 'gitea-addon', + message: 'Gitea-Deploy-Status konnte nicht geladen werden.', + }); scheduleGiteaStatusPoll(5); return null; } diff --git a/src/App/ConfigLoader.php b/src/App/ConfigLoader.php index cb117a3a..c217d456 100644 --- a/src/App/ConfigLoader.php +++ b/src/App/ConfigLoader.php @@ -6,6 +6,11 @@ namespace App; final class ConfigLoader { + public static function currentEnvironment(): string + { + return self::detectEnvironment(); + } + /** * @return array */ @@ -14,7 +19,7 @@ final class ConfigLoader $basePath = $projectRoot . '/config/' . $name . '.php'; $config = is_file($basePath) ? require $basePath : []; - $appEnv = self::detectEnvironment(); + $appEnv = self::currentEnvironment(); $envPath = $projectRoot . '/config/' . $appEnv . '/' . $name . '.php'; if (!is_file($envPath)) { diff --git a/system/addons/gitea-deploy-status/GiteaDeployStatusService.php b/system/addons/gitea-deploy-status/GiteaDeployStatusService.php index 4652a683..74b20e40 100644 --- a/system/addons/gitea-deploy-status/GiteaDeployStatusService.php +++ b/system/addons/gitea-deploy-status/GiteaDeployStatusService.php @@ -38,6 +38,31 @@ final class GiteaDeployStatusService }; } + /** + * @return array + */ + public function diagnostics(): array + { + $repositories = array_values(array_filter(array_map(function (mixed $entry): ?string { + $normalized = $this->normalizeRepositoryEntry($entry); + + return $normalized['full_name'] ?? null; + }, (array) ($this->config['repositories'] ?? [])))); + + return [ + 'configured' => $this->isConfigured(), + 'visibility' => $this->visibility(), + 'base_url_present' => $this->baseUrl() !== '', + 'base_url' => $this->baseUrl(), + 'token_present' => $this->token() !== '', + 'token_length' => strlen($this->token()), + 'owner' => trim((string) ($this->config['owner'] ?? '')), + 'repositories_configured' => $repositories, + 'poll_idle_seconds' => max(1, (int) ($this->config['poll_idle_seconds'] ?? 5)), + 'poll_running_seconds' => max(1, (int) ($this->config['poll_running_seconds'] ?? 1)), + ]; + } + /** * @return array */ @@ -53,6 +78,7 @@ final class GiteaDeployStatusService 'message' => 'Gitea-Status ist noch nicht konfiguriert.', 'running_jobs' => [], 'repositories_checked' => 0, + 'diagnostics' => $this->diagnostics(), ]; } @@ -96,6 +122,7 @@ final class GiteaDeployStatusService 'message' => $message, 'running_jobs' => $runningJobs, 'repositories_checked' => count($repositories), + 'diagnostics' => $this->diagnostics(), ]; } @@ -105,6 +132,7 @@ final class GiteaDeployStatusService 'message' => sprintf('Kein laufendes Gitea-Deployment in %d Repositories.', count($repositories)), 'running_jobs' => [], 'repositories_checked' => count($repositories), + 'diagnostics' => $this->diagnostics(), ]; } catch (\Throwable $exception) { return [ @@ -113,6 +141,7 @@ final class GiteaDeployStatusService 'message' => 'Gitea-Status konnte nicht geladen werden: ' . $exception->getMessage(), 'running_jobs' => [], 'repositories_checked' => 0, + 'diagnostics' => $this->diagnostics(), ]; } } diff --git a/system/addons/gitea-deploy-status/api.php b/system/addons/gitea-deploy-status/api.php index e2614c7a..8122ab1d 100644 --- a/system/addons/gitea-deploy-status/api.php +++ b/system/addons/gitea-deploy-status/api.php @@ -15,6 +15,7 @@ $groups = array_values(array_map('strval', (array) ($authUser['groups'] ?? []))) $isAdmin = in_array('administrators', $groups, true); $projectRoot = dirname(__DIR__, 3); +$currentEnvironment = ConfigLoader::currentEnvironment(); $service = new GiteaDeployStatusService(ConfigLoader::load($projectRoot, 'gitea')); if (!$service->shouldShowInTray($isAdmin)) { @@ -24,8 +25,14 @@ if (!$service->shouldShowInTray($isAdmin)) { ], 403); } +$status = $service->status(); +$diagnostics = is_array($status['diagnostics'] ?? null) ? $status['diagnostics'] : []; +$diagnostics['environment'] = $currentEnvironment; +$diagnostics['host'] = (string) ($_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? ''); +$status['diagnostics'] = $diagnostics; + respond([ - 'data' => $service->status(), + 'data' => $status, ]); /**