actions->listWorkflowsTyped($owner, $repo); echo " Total workflows: {$workflows->count()}\n"; echo " Active workflows: " . count($workflows->active()) . "\n"; echo " Disabled workflows: " . count($workflows->disabled()) . "\n\n"; foreach ($workflows as $workflow) { $statusIcon = $workflow->isActive() ? '✅' : '❌'; echo " {$statusIcon} Workflow: {$workflow->name}\n"; echo " ID: {$workflow->id}\n"; echo " Path: {$workflow->path}\n"; echo " File: {$workflow->getFileName()}\n"; echo " State: {$workflow->state}\n"; echo "\n"; } // ===================================================================== // Test 2: List Workflow Runs (Typed) // ===================================================================== echo "🏃 Test 2: Listing Recent Workflow Runs (Type-Safe)\n"; echo str_repeat('─', 60) . "\n"; $runs = $giteaClient->actions->listRunsTyped($owner, $repo, ['limit' => 10]); echo " Total runs: {$runs->count()}\n"; echo " Running: " . count($runs->running()) . "\n"; $successRate = $runs->successRate() * 100; echo " Successful: {$runs->successCount()} ({$successRate}%)\n"; echo " Failed: {$runs->failureCount()}\n\n"; foreach ($runs as $run) { echo " {$run->getStatusSummary()} Run #{$run->id}\n"; echo " Title: {$run->displayTitle}\n"; echo " Status: {$run->status->value}\n"; echo " Branch: {$run->headBranch}\n"; echo " Started: {$run->startedAt->format('Y-m-d H:i:s')}\n"; if ($run->isCompleted() && $run->getDuration() !== null) { $duration = $run->getDuration(); echo " Duration: {$duration->toSeconds()}s\n"; } elseif ($run->isRunning()) { $elapsed = $run->getElapsedTime(); echo " Elapsed: {$elapsed->toSeconds()}s (still running)\n"; } echo "\n"; } // ===================================================================== // Test 3: Get Specific Run Details (Typed) // ===================================================================== if (!$runs->isEmpty()) { echo "🔍 Test 3: Detailed Run Information (Type-Safe)\n"; echo str_repeat('─', 60) . "\n"; $latestRun = $runs->latest(); echo " Run ID: {$latestRun->id}\n"; echo " Title: {$latestRun->displayTitle}\n"; echo " Status: {$latestRun->getStatusSummary()}\n"; echo " Branch: {$latestRun->headBranch}\n"; echo " Commit: " . substr($latestRun->headSha, 0, 8) . "\n"; echo " Triggered by: {$latestRun->event}\n"; echo " Run Number: {$latestRun->runNumber}\n"; echo "\n"; echo " Business Logic Methods:\n"; echo " - isSuccessful(): " . ($latestRun->isSuccessful() ? 'true' : 'false') . "\n"; echo " - isFailed(): " . ($latestRun->isFailed() ? 'true' : 'false') . "\n"; echo " - isRunning(): " . ($latestRun->isRunning() ? 'true' : 'false') . "\n"; echo " - wasCancelled(): " . ($latestRun->wasCancelled() ? 'true' : 'false') . "\n"; if ($latestRun->getDuration() !== null) { $duration = $latestRun->getDuration(); echo " - getDuration(): {$duration->toSeconds()}s\n"; } echo "\n"; } // ===================================================================== // Test 4: Collection Methods Demo // ===================================================================== echo "📊 Test 4: Collection Methods Demo\n"; echo str_repeat('─', 60) . "\n"; // Filter by branch $mainBranchRuns = $runs->forBranch('main'); echo " Runs on 'main' branch: " . count($mainBranchRuns) . "\n"; // Find by ID if (!$runs->isEmpty()) { $firstRunId = $runs->latest()->id; $foundRun = $runs->findById($firstRunId); echo " Found run by ID: " . ($foundRun !== null ? 'Yes' : 'No') . "\n"; } echo "\n"; // ===================================================================== // Test 5: Backward Compatibility Check // ===================================================================== echo "🔄 Test 5: Backward Compatibility (Raw Arrays Still Work)\n"; echo str_repeat('─', 60) . "\n"; // Old API still works $rawWorkflows = $giteaClient->actions->listWorkflows($owner, $repo); echo " Raw array method works: Yes\n"; echo " Raw workflows count: " . count($rawWorkflows['workflows'] ?? []) . "\n"; $rawRuns = $giteaClient->actions->listRuns($owner, $repo, ['limit' => 5]); echo " Raw runs method works: Yes\n"; echo " Raw runs count: " . count($rawRuns['workflow_runs'] ?? []) . "\n"; echo "\n"; echo "✅ All Tests SUCCESSFUL!\n\n"; // ===================================================================== // Insights // ===================================================================== echo "╔═══════════════════════════════════════════════════════════════════╗\n"; echo "║ ★ Insights ─────────────────────────────────────────────────────║\n"; echo "╠═══════════════════════════════════════════════════════════════════╣\n"; echo "║ ║\n"; echo "║ Value Objects bieten mehrere Vorteile: ║\n"; echo "║ ║\n"; echo "║ 1. Type Safety - IDE erkennt Fehler zur Compile-Zeit ║\n"; echo "║ \$run->id (RunId) statt \$run['id'] (mixed) ║\n"; echo "║ ║\n"; echo "║ 2. Business Logic - Methoden wie isSuccessful(), getDuration() ║\n"; echo "║ direkt am Objekt statt externe Helper-Funktionen ║\n"; echo "║ ║\n"; echo "║ 3. Collection Methods - Filtern, Suchen, Aggregieren ║\n"; echo "║ \$runs->successful(), \$runs->successRate() etc. ║\n"; echo "║ ║\n"; echo "║ 4. API Evolution - Änderungen in Gitea API isoliert ║\n"; echo "║ fromApiResponse() mappt API-Änderungen transparent ║\n"; echo "║ ║\n"; echo "║ 5. Backward Compatible - Raw arrays funktionieren weiterhin ║\n"; echo "║ listWorkflows() (array) + listWorkflowsTyped() (VOs) ║\n"; echo "║ ║\n"; echo "╚═══════════════════════════════════════════════════════════════════╝\n\n"; } catch (\Exception $e) { echo "\n❌ Error: " . $e->getMessage() . "\n"; echo "File: " . $e->getFile() . "\n"; echo "Line: " . $e->getLine() . "\n"; exit(1); }