From 0b1f39a75c67a29089627bc379e1f3fa4023a71d Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Fri, 19 Jun 2026 03:13:31 -0500 Subject: [PATCH 1/2] fix: rename package_type to extension_type, remove display_name validation (#259) - API endpoint updated from /manifest to /metadata - Removed dead .mokogitea/manifest.xml local file fallback - display_name is now server-computed, no longer validated - package_type renamed to extension_type throughout --- cli/joomla_metadata_validate.php | 63 +++++--------------------------- 1 file changed, 10 insertions(+), 53 deletions(-) diff --git a/cli/joomla_metadata_validate.php b/cli/joomla_metadata_validate.php index a43d577..31934c5 100644 --- a/cli/joomla_metadata_validate.php +++ b/cli/joomla_metadata_validate.php @@ -165,39 +165,13 @@ class JoomlaMetadataValidateCli extends CliFramework } // ================================================================= - // Load metadata (from .mokogitea/manifest.xml or API) + // Load metadata (from API) // ================================================================= private function loadMetadata(string $root, string $org, string $repoName, string $token, string $apiBase): ?array { - // Try local .mokogitea/manifest.xml first - $localManifest = "{$root}/.mokogitea/manifest.xml"; - - if (is_file($localManifest)) { - $xml = @simplexml_load_file($localManifest); - - if ($xml !== false) { - $identity = $xml->identity ?? $xml; - $governance = $xml->governance ?? $xml; - $build = $xml->build ?? $xml; - - return [ - 'name' => (string) ($identity->name ?? ''), - 'display_name' => (string) ($identity->{'display-name'} ?? ''), - 'description' => (string) ($identity->description ?? ''), - 'version' => (string) ($identity->version ?? ''), - 'platform' => (string) ($governance->platform ?? ''), - 'package_type' => (string) ($build->{'package-type'} ?? ''), - 'language' => (string) ($build->language ?? ''), - 'entry_point' => (string) ($build->{'entry-point'} ?? ''), - 'source' => 'local', - ]; - } - } - - // Fall back to API if ($token !== '') { - $url = "{$apiBase}/repos/{$org}/{$repoName}/manifest"; + $url = "{$apiBase}/repos/{$org}/{$repoName}/metadata"; $ctx = stream_context_create([ 'http' => [ 'header' => "Authorization: token {$token}\r\nAccept: application/json\r\n", @@ -229,10 +203,10 @@ class JoomlaMetadataValidateCli extends CliFramework $xml = $joomlaXml['xml']; $type = $joomlaXml['type']; - // 1. Extension type vs package_type - $metaType = $this->normalizePackageType($metadata['package_type'] ?? ''); + // 1. Extension type + $metaType = $this->normalizeExtensionType($metadata['extension_type'] ?? ''); $results[] = [ - 'field' => 'package_type', + 'field' => 'extension_type', 'metadata' => $metaType, 'joomla' => $type, 'status' => ($metaType === $type) ? 'ok' : 'error', @@ -257,24 +231,7 @@ class JoomlaMetadataValidateCli extends CliFramework : "metadata derives \"{$metaElement}\" but Joomla uses \"{$joomlaElement}\"", ]; - // 3. Display name - $metaDisplay = $metadata['display_name'] ?? ''; - $joomlaName = (string) ($xml->name ?? ''); - - if ($metaDisplay !== '' && $joomlaName !== '') { - $displayMatch = ($metaDisplay === $joomlaName); - $results[] = [ - 'field' => 'display_name', - 'metadata' => $metaDisplay, - 'joomla' => $joomlaName, - 'status' => $displayMatch ? 'ok' : 'warn', - 'message' => $displayMatch - ? 'matches' - : "metadata has \"{$metaDisplay}\" but Joomla has \"{$joomlaName}\"", - ]; - } - - // 4. Version + // 3. Version $metaVersion = $metadata['version'] ?? ''; $joomlaVersion = (string) ($xml->version ?? ''); @@ -295,7 +252,7 @@ class JoomlaMetadataValidateCli extends CliFramework ]; } - // 5. PHP minimum (from composer.json) + // 4. PHP minimum (from composer.json) $composerPhp = $this->readComposerPhpRequirement($root); $metaPhp = $metadata['php_minimum'] ?? ''; @@ -312,7 +269,7 @@ class JoomlaMetadataValidateCli extends CliFramework ]; } - // 6. Description + // 5. Description $metaDesc = $metadata['description'] ?? ''; $joomlaDesc = (string) ($xml->description ?? ''); @@ -336,9 +293,9 @@ class JoomlaMetadataValidateCli extends CliFramework // ================================================================= /** - * Normalize package_type — map MokoGitea types to Joomla types. + * Normalize extension_type — map MokoGitea types to Joomla types. */ - private function normalizePackageType(string $type): string + private function normalizeExtensionType(string $type): string { return match (strtolower($type)) { 'joomla-extension' => 'package', // legacy mapping -- 2.52.0 From dc7f6c9eeb2b247ede7cc4223d705930814fad1b Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Fri, 19 Jun 2026 04:03:11 -0500 Subject: [PATCH 2/2] fix: improve error handling, add extension_type fallback (#259) - Surface HTTP errors instead of suppressing with @file_get_contents - Add specific messages for 401/403/404 and missing token - Fall back to package_type if extension_type not in API response - Log warnings for malformed XML candidates - Fix platform_detect.php endpoint from /manifest to /metadata --- cli/joomla_metadata_validate.php | 75 +++++++++++++++++++++++--------- cli/platform_detect.php | 2 +- 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/cli/joomla_metadata_validate.php b/cli/joomla_metadata_validate.php index 31934c5..acb3361 100644 --- a/cli/joomla_metadata_validate.php +++ b/cli/joomla_metadata_validate.php @@ -146,6 +146,9 @@ class JoomlaMetadataValidateCli extends CliFramework if (preg_match('/]*type=["\']([^"\']+)["\']/', $content, $typeMatch)) { $xml = @simplexml_load_string($content); if ($xml === false) { + $relPath = str_replace($root . '/', '', $file); + $relPath = str_replace($root . '\\', '', $relPath); + $this->log('WARN', "Skipping {$relPath}: malformed XML"); continue; } @@ -170,27 +173,57 @@ class JoomlaMetadataValidateCli extends CliFramework private function loadMetadata(string $root, string $org, string $repoName, string $token, string $apiBase): ?array { - if ($token !== '') { - $url = "{$apiBase}/repos/{$org}/{$repoName}/metadata"; - $ctx = stream_context_create([ - 'http' => [ - 'header' => "Authorization: token {$token}\r\nAccept: application/json\r\n", - 'timeout' => 10, - ], - ]); - - $body = @file_get_contents($url, false, $ctx); - - if ($body !== false) { - $data = json_decode($body, true); - if (is_array($data)) { - $data['source'] = 'api'; - return $data; - } - } + if ($token === '') { + $this->log('ERROR', 'No API token provided (use --token or set GITEA_TOKEN env var)'); + return null; } - return null; + $url = "{$apiBase}/repos/{$org}/{$repoName}/metadata"; + $ctx = stream_context_create([ + 'http' => [ + 'header' => "Authorization: token {$token}\r\nAccept: application/json\r\n", + 'timeout' => 10, + 'ignore_errors' => true, + ], + ]); + + $body = file_get_contents($url, false, $ctx); + + // Extract HTTP status from response headers + $httpCode = 0; + if (isset($http_response_header[0]) && preg_match('/\d{3}/', $http_response_header[0], $m)) { + $httpCode = (int) $m[0]; + } + + if ($body === false) { + $this->log('ERROR', "Failed to connect to {$url} — check network or TLS configuration"); + return null; + } + + if ($httpCode === 404) { + $this->log('ERROR', "API endpoint not found: {$url}"); + $this->log('ERROR', 'Server may need MokoGitea-Fork >= #650 (metadata endpoint rename)'); + return null; + } + + if ($httpCode === 401 || $httpCode === 403) { + $this->log('ERROR', "Authentication failed (HTTP {$httpCode}) — check your API token"); + return null; + } + + if ($httpCode >= 400) { + $this->log('ERROR', "API returned HTTP {$httpCode}: " . substr($body, 0, 200)); + return null; + } + + $data = json_decode($body, true); + if (!is_array($data)) { + $this->log('ERROR', "API returned invalid JSON from {$url}"); + return null; + } + + $data['source'] = 'api'; + return $data; } // ================================================================= @@ -204,7 +237,9 @@ class JoomlaMetadataValidateCli extends CliFramework $type = $joomlaXml['type']; // 1. Extension type - $metaType = $this->normalizeExtensionType($metadata['extension_type'] ?? ''); + $metaType = $this->normalizeExtensionType( + $metadata['extension_type'] ?? $metadata['package_type'] ?? '' + ); $results[] = [ 'field' => 'extension_type', 'metadata' => $metaType, diff --git a/cli/platform_detect.php b/cli/platform_detect.php index 4dddc70..237e738 100644 --- a/cli/platform_detect.php +++ b/cli/platform_detect.php @@ -82,7 +82,7 @@ class PlatformDetectCli extends CliFramework $giteaUrl, $token, 'PATCH', - "/api/v1/repos/{$owner}/{$repo}/manifest", + "/api/v1/repos/{$owner}/{$repo}/metadata", json_encode(['platform' => $platform]) ); -- 2.52.0