diff --git a/cli/workflow_sync.php b/cli/workflow_sync.php index a20ecbf..0860314 100644 --- a/cli/workflow_sync.php +++ b/cli/workflow_sync.php @@ -45,9 +45,6 @@ class WorkflowSyncCli extends CliFramework /** Prefix for custom workflows preserved during orphan cleanup. */ private const CUSTOM_PREFIX = 'custom-'; - /** Subdirectory name for custom workflows preserved during orphan cleanup. */ - private const CUSTOM_DIR = 'custom'; - private int $updated = 0; private int $created = 0; private int $skipped = 0; @@ -283,14 +280,15 @@ class WorkflowSyncCli extends CliFramework foreach ($workflows as $workflow) { $filename = $workflow['name']; + $destPath = '.mokogitea/workflows/' . $filename; + $label = "{$repoFullName}/{$filename}"; + // Skip platform-excluded workflows if (in_array($filename, self::PLATFORM_EXCLUDES[$platform] ?? [], true)) { fprintf(STDERR, "%-45s | %s\n", $label, 'EXCLUDED (platform)'); $this->skipped++; continue; } - $destPath = '.mokogitea/workflows/' . $filename; - $label = "{$repoFullName}/{$filename}"; // Get source content from template $sourceContent = $this->getFileContent( @@ -316,7 +314,7 @@ class WorkflowSyncCli extends CliFramework if ($this->getArgument('--delete-orphans', false)) { $templateNames = array_map(fn($w) => $w['name'], $workflows); $this->deleteOrphanWorkflows( - $giteaUrl, $token, $org, $repoName, $branch, $templateNames + $giteaUrl, $token, $org, $repoName, $branch, $templateNames, $platform ); } } @@ -437,15 +435,15 @@ class WorkflowSyncCli extends CliFramework string $org, string $repoName, string $branch, - array $templateNames + array $templateNames, + string $platform ): void { $repoWorkflows = $this->listWorkflows($giteaUrl, $token, $org, $repoName, $branch); if ($repoWorkflows === null) { return; } - // Also list directories so we can preserve custom/ - $allEntries = $this->listWorkflowEntries($giteaUrl, $token, $org, $repoName, $branch); + $platformExcludes = self::PLATFORM_EXCLUDES[$platform] ?? []; foreach ($repoWorkflows as $workflow) { $name = $workflow['name']; @@ -462,6 +460,13 @@ class WorkflowSyncCli extends CliFramework continue; } + // Keep if it's platform-excluded (legitimately skipped during sync) + if (in_array($name, $platformExcludes, true)) { + $label = "{$org}/{$repoName}/{$name}"; + fprintf(STDERR, "%-45s | %s\n", $label, 'KEPT (platform-excluded)'); + continue; + } + // Delete orphan $filePath = '.mokogitea/workflows/' . $name; $label = "{$org}/{$repoName}/{$name}"; @@ -525,28 +530,6 @@ class WorkflowSyncCli extends CliFramework return $response['code'] === 200; } - /** - * List all entries (files + dirs) in .mokogitea/workflows/. - */ - private function listWorkflowEntries( - string $giteaUrl, - string $token, - string $org, - string $repoName, - string $branch - ): array { - $response = $this->apiRequest( - $giteaUrl, $token, 'GET', - "/api/v1/repos/{$org}/{$repoName}/contents/.mokogitea/workflows?ref={$branch}" - ); - - if ($response['code'] !== 200) { - return []; - } - - return json_decode($response['body'], true) ?: []; - } - /** * List workflow files in a repo's .mokogitea/workflows/ directory. */