fix: rename package_type to extension_type, remove display_name (#259) #281

Merged
jmiller merged 2 commits from fix/259-cherry-pick into main 2026-06-20 17:15:51 +00:00
2 changed files with 60 additions and 68 deletions
+59 -67
View File
@@ -146,6 +146,9 @@ class JoomlaMetadataValidateCli extends CliFramework
if (preg_match('/<extension\s[^>]*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;
}
@@ -165,58 +168,62 @@ 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',
];
}
if ($token === '') {
$this->log('ERROR', 'No API token provided (use --token or set GITEA_TOKEN env var)');
return null;
}
// Fall back to API
if ($token !== '') {
$url = "{$apiBase}/repos/{$org}/{$repoName}/manifest";
$ctx = stream_context_create([
'http' => [
'header' => "Authorization: token {$token}\r\nAccept: application/json\r\n",
'timeout' => 10,
],
]);
$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);
$body = file_get_contents($url, false, $ctx);
if ($body !== false) {
$data = json_decode($body, true);
if (is_array($data)) {
$data['source'] = 'api';
return $data;
}
}
// 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];
}
return null;
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;
}
// =================================================================
@@ -229,10 +236,12 @@ 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'] ?? $metadata['package_type'] ?? ''
);
$results[] = [
'field' => 'package_type',
'field' => 'extension_type',
'metadata' => $metaType,
'joomla' => $type,
'status' => ($metaType === $type) ? 'ok' : 'error',
@@ -257,24 +266,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 +287,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 +304,7 @@ class JoomlaMetadataValidateCli extends CliFramework
];
}
// 6. Description
// 5. Description
$metaDesc = $metadata['description'] ?? '';
$joomlaDesc = (string) ($xml->description ?? '');
@@ -336,9 +328,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
+1 -1
View File
@@ -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])
);