diff --git a/cli/workflow_sync.php b/cli/workflow_sync.php index f2dc323..72c29ec 100644 --- a/cli/workflow_sync.php +++ b/cli/workflow_sync.php @@ -593,8 +593,10 @@ class WorkflowSyncCli extends CliFramework } /** - * Read a repo's manifest.xml and extract the platform value. - * Returns 'generic' if the manifest is missing or has no platform field. + * Read a repo's platform from the MokoGitea metadata API. + * Returns 'generic' if metadata is missing or has no platform field. + * (Replaces the retired .mokogitea/manifest.xml lookup — platform now lives + * in the repo Metadata endpoint: GET /api/v1/repos/{owner}/{repo}/metadata.) */ private function getRepoPlatform( string $giteaUrl, @@ -607,7 +609,7 @@ class WorkflowSyncCli extends CliFramework $giteaUrl, $token, 'GET', - "/api/v1/repos/{$org}/{$repoName}/contents/.mokogitea/manifest.xml?ref={$branch}" + "/api/v1/repos/{$org}/{$repoName}/metadata" ); if ($response['code'] !== 200) { @@ -616,74 +618,11 @@ class WorkflowSyncCli extends CliFramework $data = json_decode($response['body'], true); - if (!is_array($data) || !isset($data['content'])) { + if (!is_array($data) || empty($data['platform'])) { return 'generic'; } - $xmlContent = base64_decode($data['content']); - - if ($xmlContent === false || $xmlContent === '') { - return 'generic'; - } - - // Suppress XML warnings for malformed manifests - $previous = libxml_use_internal_errors(true); - $xml = simplexml_load_string($xmlContent); - libxml_use_internal_errors($previous); - - if ($xml === false) { - return 'generic'; - } - - // Try (standard location) - $platform = ''; - - // Register namespace if present - $namespaces = $xml->getNamespaces(true); - - if (!empty($namespaces)) { - $ns = reset($namespaces); - $xml->registerXPathNamespace('mp', $ns); - - $nodes = $xml->xpath('//mp:governance/mp:platform'); - - if (!empty($nodes)) { - $platform = trim((string) $nodes[0]); - } - - // Fallback: - if ($platform === '') { - $nodes = $xml->xpath('//mp:identity/mp:platform'); - - if (!empty($nodes)) { - $platform = trim((string) $nodes[0]); - } - } - - // Fallback: top-level - if ($platform === '') { - $nodes = $xml->xpath('//mp:platform'); - - if (!empty($nodes)) { - $platform = trim((string) $nodes[0]); - } - } - } else { - // No namespace - if (isset($xml->governance->platform)) { - $platform = trim((string) $xml->governance->platform); - } elseif (isset($xml->identity->platform)) { - $platform = trim((string) $xml->identity->platform); - } elseif (isset($xml->platform)) { - $platform = trim((string) $xml->platform); - } - } - - if ($platform === '') { - return 'generic'; - } - - return strtolower($platform); + return strtolower(trim((string) $data['platform'])); } /**