Public Access
b491241a58
Universal: Sync Feature Branch Versions / Sync feature branches with dev (push) Has been skipped
# Conflicts: # .mokogitea/CLAUDE.md # .mokogitea/ISSUE_TEMPLATE/config.yml # .mokogitea/ISSUE_TEMPLATE/documentation.md # .mokogitea/ISSUE_TEMPLATE/feature_request.md # .mokogitea/ISSUE_TEMPLATE/security.md # .mokogitea/branch-protection.yml # .mokogitea/bulk-repo-sync.yml # .mokogitea/pr-branch-check.yml # .mokogitea/renovate.yml # .mokogitea/sync-wikis.yml # .mokogitea/workflows/auto-bump.yml # .mokogitea/workflows/auto-release.yml # .mokogitea/workflows/ci-platform.yml # .mokogitea/workflows/cleanup.yml # .mokogitea/workflows/gitleaks.yml # .mokogitea/workflows/issue-branch.yml # .mokogitea/workflows/notify.yml # .mokogitea/workflows/pre-release.yml # .mokogitea/workflows/repo-health.yml # .mokogitea/workflows/security-audit.yml # .script-registry.json # CHANGELOG.md # PLUGIN_SCRIPTS.md # README.md # analysis/index.md # automation/bulk_joomla_template.php # automation/bulk_sync.php # automation/enrich_manifest_xml.php # automation/enrich_mokostandards_xml.php # automation/index.md # automation/migrate_to_gitea.php # automation/push_files.php # automation/push_manifest_xml.php # automation/push_mokostandards_xml.php # automation/repo_cleanup.php # bin/moko # cli/archive_repo.php # cli/audit_query.php # cli/badge_update.php # cli/branch_rename.php # cli/bulk_workflow_push.php # cli/bulk_workflow_trigger.php # cli/changelog_promote.php # cli/changelog_prune.php # cli/client_dashboard.php # cli/client_health_check.php # cli/client_inventory.php # cli/client_provision.php # cli/completion.php # cli/create_project.php # cli/create_repo.php # cli/deploy_joomla.php # cli/dev_branch_reset.php # cli/grafana_dashboard.php # cli/joomla_build.php # cli/joomla_compat_check.php # cli/joomla_metadata_validate.php # cli/joomla_release.php # cli/license_manage.php # cli/manifest_element.php # cli/manifest_licensing.php # cli/manifest_read.php # cli/package_build.php # cli/platform_detect.php # cli/release.php # cli/release_body_update.php # cli/release_cascade.php # cli/release_create.php # cli/release_manage.php # cli/release_mirror.php # cli/release_notes.php # cli/release_package.php # cli/release_promote.php # cli/release_publish.php # cli/release_validate.php # cli/release_verify.php # cli/scaffold_client.php # cli/sync_rulesets.php # cli/theme_lint.php # cli/updates_xml_build.php # cli/updates_xml_sync.php # cli/version_auto_bump.php # cli/version_bump.php # cli/version_bump_remote.php # cli/version_check.php # cli/version_read.php # cli/version_reset_dev.php # cli/version_set_platform.php # cli/wiki_sync.php # cli/workflow_sync.php # composer.json # deploy/backup-before-deploy.php # deploy/deploy-dolibarr.php # deploy/deploy-joomla.php # deploy/deploy-sftp.php # deploy/health-check.php # deploy/rollback-joomla.php # deploy/sync-joomla.php # fix/fix_line_endings.php # fix/fix_permissions.php # fix/fix_tabs.php # fix/fix_trailing_spaces.php # fix/index.md # index.md # lib/CliBase.php # lib/Common.php # lib/Enterprise/AbstractProjectPlugin.php # lib/Enterprise/ApiClient.php # lib/Enterprise/AuditLogger.php # lib/Enterprise/CheckpointManager.php # lib/Enterprise/CliFramework.php # lib/Enterprise/Config.php # lib/Enterprise/ConfigValidator.php # lib/Enterprise/EnterpriseReadinessValidator.php # lib/Enterprise/ErrorRecovery.php # lib/Enterprise/FileFixUtility.php # lib/Enterprise/GitHubAdapter.php # lib/Enterprise/GitPlatformAdapter.php # lib/Enterprise/InputValidator.php # lib/Enterprise/ManifestParser.php # lib/Enterprise/ManifestReader.php # lib/Enterprise/MetricsCollector.php # lib/Enterprise/MokoGiteaAdapter.php # lib/Enterprise/PackageBuilder.php # lib/Enterprise/PlatformAdapterFactory.php # lib/Enterprise/PluginFactory.php # lib/Enterprise/PluginRegistry.php # lib/Enterprise/Plugins/ApiPlugin.php # lib/Enterprise/Plugins/DocumentationPlugin.php # lib/Enterprise/Plugins/DolibarrPlugin.php # lib/Enterprise/Plugins/GenericPlugin.php # lib/Enterprise/Plugins/JoomlaPlugin.php # lib/Enterprise/Plugins/McpServerPlugin.php # lib/Enterprise/Plugins/MobilePlugin.php # lib/Enterprise/Plugins/NodeJsPlugin.php # lib/Enterprise/Plugins/PythonPlugin.php # lib/Enterprise/Plugins/TerraformPlugin.php # lib/Enterprise/Plugins/WordPressPlugin.php # lib/Enterprise/ProjectConfigValidator.php # lib/Enterprise/ProjectMetricsCollector.php # lib/Enterprise/ProjectPluginInterface.php # lib/Enterprise/ProjectTypeDetector.php # lib/Enterprise/RecoveryError.php # lib/Enterprise/RecoveryManager.php # lib/Enterprise/RepositoryHealthChecker.php # lib/Enterprise/RepositorySynchronizer.php # lib/Enterprise/RetryHelper.php # lib/Enterprise/SecurityValidator.php # lib/Enterprise/SourceResolver.php # lib/Enterprise/SynchronizationException.php # lib/Enterprise/TransactionManager.php # lib/Enterprise/UnifiedValidation.php # lib/index.md # lib/plugins/Joomla/UpdateXmlGenerator.php # maintenance/index.md # maintenance/pin_action_shas.php # maintenance/repo_inventory.php # maintenance/rotate_secrets.php # maintenance/setup_labels.php # maintenance/sync_dolibarr_readmes.php # maintenance/update_repo_inventory.php # maintenance/update_sha_hashes.php # maintenance/update_version_from_readme.php # mcp/config.example.json # mcp/package.json # mcp/src/config.ts # mcp/src/index.ts # mcp/src/runner.ts # mcp/src/types.ts # phpcs.xml # plugin_health_check.php # plugin_list.php # plugin_metrics.php # plugin_readiness.php # plugin_validate.php # release/generate_dolibarr_version_txt.php # release/generate_joomla_update_xml.php # src/functions.php # templates/configs/README.md # templates/configs/index.md # templates/configs/manifest.xml.template # templates/configs/manifest.yml.template # templates/configs/mokostandards.xml.template # templates/configs/mokostandards.yml.template # templates/configs/phpcs.xml # templates/docs/README.md # templates/docs/extra/README.md # templates/docs/extra/index.md # templates/docs/index.md # templates/docs/required/GOVERNANCE.md # templates/docs/required/README.md # templates/docs/required/index.md # templates/docs/required/template-CONTRIBUTING.md # templates/docs/required/template-README.md # templates/docs/required/template-SECURITY.md # templates/index.md # templates/licenses/README.md # templates/licenses/index.md # templates/makefiles/README.md # templates/mokogitea/CLAUDE.dolibarr.md.template # templates/mokogitea/CLAUDE.joomla.md.template # templates/mokogitea/CLAUDE.md.template # templates/mokogitea/ISSUE_TEMPLATE/config.yml # templates/mokogitea/ISSUE_TEMPLATE/documentation.md # templates/mokogitea/ISSUE_TEMPLATE/dolibarr_module_id_request.md # templates/mokogitea/ISSUE_TEMPLATE/feature_request.md # templates/mokogitea/ISSUE_TEMPLATE/security.md # templates/mokogitea/README.md # templates/mokogitea/copilot-instructions.dolibarr.md.template # templates/mokogitea/copilot-instructions.joomla.md.template # templates/mokogitea/copilot-instructions.md.template # templates/mokogitea/dependabot.yml.template # templates/mokogitea/override.tf.template # templates/required/README.md # templates/schemas/README.md # templates/schemas/manifest-schema.xsd # templates/schemas/moko-platform-schema.xsd # templates/schemas/mokostandards-schema.xsd # templates/schemas/schemas/README.md # templates/schemas/template-repository-structure.xml # templates/scripts/README.md # templates/scripts/common/CliBase.template.php # templates/scripts/fix/index.md # templates/scripts/index.md # templates/scripts/release/index.md # templates/scripts/release/package_dolibarr.php # templates/scripts/release/package_joomla.php # templates/scripts/sftp-config/README.md # templates/scripts/validate/dolibarr_module.php # templates/scripts/validate/index.md # templates/scripts/validate/validate_manifest.php # templates/scripts/validate/validate_structure.php # templates/security/README.md # templates/security/index.php # templates/stubs/dolibarr.php # templates/stubs/joomla.php # templates/web/index.php # tests/Enterprise/GitPlatformAdapterTest.php # tests/Unit/VersionBumpTest.php # tests/Unit/VersionReadTest.php # tests/index.md # tests/test_circuit_breaker_handling.php # tests/test_enterprise_libraries.php # validate/SECURITY_SCANNING.md # validate/auto_detect_platform.php # validate/check_changelog.php # validate/check_client_theme.php # validate/check_composer_deps.php # validate/check_dolibarr_module.php # validate/check_enterprise_readiness.php # validate/check_file_integrity.php # validate/check_joomla_manifest.php # validate/check_language_structure.php # validate/check_license_headers.php # validate/check_no_secrets.php # validate/check_paths.php # validate/check_php_syntax.php # validate/check_repo_health.php # validate/check_structure.php # validate/check_tabs.php # validate/check_version_consistency.php # validate/check_wiki_health.php # validate/check_xml_wellformed.php # validate/index.md # validate/scan_drift.php # wrappers/auto_detect_platform.php # wrappers/bulk_sync.php # wrappers/check_changelog.php # wrappers/check_dolibarr_module.php # wrappers/check_enterprise_readiness.php # wrappers/check_joomla_manifest.php # wrappers/check_language_structure.php # wrappers/check_license_headers.php # wrappers/check_no_secrets.php # wrappers/check_paths.php # wrappers/check_php_syntax.php # wrappers/check_repo_health.php # wrappers/check_structure.php # wrappers/check_tabs.php # wrappers/check_version_consistency.php # wrappers/check_xml_wellformed.php # wrappers/deploy_sftp.php # wrappers/fix_line_endings.php # wrappers/fix_permissions.php # wrappers/fix_tabs.php # wrappers/fix_trailing_spaces.php # wrappers/gen_wrappers.php # wrappers/index.md # wrappers/pin_action_shas.php # wrappers/plugin_health_check.php # wrappers/plugin_list.php # wrappers/plugin_metrics.php # wrappers/plugin_readiness.php # wrappers/plugin_validate.php # wrappers/scan_drift.php # wrappers/setup_labels.php # wrappers/sync_dolibarr_readmes.php # wrappers/update_sha_hashes.php # wrappers/update_version_from_readme.php
492 lines
18 KiB
PHP
492 lines
18 KiB
PHP
#!/usr/bin/env php
|
|
<?php
|
|
|
|
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
* FILE INFORMATION
|
|
<<<<<<< HEAD
|
|
* DEFGROUP: MokoCLI.CLI
|
|
* INGROUP: MokoCLI
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokocli
|
|
* PATH: /cli/manifest_read.php
|
|
* VERSION: 09.25.05
|
|
* BRIEF: Parse .manifest.xml and output requested field(s) for CI consumption
|
|
=======
|
|
* DEFGROUP: mokocli.CLI
|
|
* INGROUP: mokocli
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokocli
|
|
* PATH: /cli/manifest_read.php
|
|
* VERSION: 09.32.00
|
|
* BRIEF: Read repo metadata from Gitea manifest API, auto-detect the rest
|
|
>>>>>>> main
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
|
|
|
use MokoCli\CliFramework;
|
|
|
|
class ManifestReadCli extends CliFramework
|
|
{
|
|
/** Joomla extension XML element names searched in root and source/ dirs. */
|
|
private const JOOMLA_XML_ROOTS = ['extension', 'install'];
|
|
|
|
protected function configure(): void
|
|
{
|
|
$this->setDescription('Read repo metadata from Gitea API with auto-detection fallback');
|
|
$this->addArgument('--path', 'Repository root path', '.');
|
|
$this->addArgument('--field', 'Single field name to output', '');
|
|
$this->addArgument('--all', 'Print all fields as KEY=VALUE lines', false);
|
|
$this->addArgument('--github-output', 'Append all fields to $GITHUB_OUTPUT', false);
|
|
$this->addArgument('--json', 'Output all fields as JSON', false);
|
|
}
|
|
|
|
protected function run(): int
|
|
{
|
|
$path = $this->getArgument('--path');
|
|
$field = $this->getArgument('--field');
|
|
$showAll = $this->getArgument('--all');
|
|
$ghOut = $this->getArgument('--github-output');
|
|
$jsonMode = $this->getArgument('--json');
|
|
|
|
$mode = match (true) {
|
|
(bool) $ghOut => 'github-output',
|
|
(bool) $showAll => 'all',
|
|
(bool) $jsonMode => 'json',
|
|
default => 'field',
|
|
};
|
|
|
|
$root = realpath($path) ?: $path;
|
|
|
|
// ── 1. Resolve org/repo ──────────────────────────────────────────
|
|
[$org, $repo] = $this->resolveOrgRepo($root);
|
|
|
|
// ── 2. Primary: Gitea manifest API ───────────────────────────────
|
|
$fields = null;
|
|
if ($org !== '' && $repo !== '') {
|
|
$fields = $this->fetchFromApi($org, $repo);
|
|
}
|
|
|
|
// ── 3. Fallback: auto-detect from source tree ────────────────────
|
|
if ($fields === null) {
|
|
$this->log('INFO', 'API unavailable — falling back to source-tree detection');
|
|
$fields = $this->autoDetect($root, $repo);
|
|
}
|
|
|
|
<<<<<<< HEAD
|
|
// Priority: manifest.xml (current standard)
|
|
$candidates = [
|
|
"{$root}/.mokogitea/manifest.xml",
|
|
"{$root}/.mokogitea/.manifest.xml", // legacy (dot-prefixed)
|
|
"{$root}/.mokogitea/.MokoCLI", // legacy v4
|
|
=======
|
|
if (empty($fields)) {
|
|
$this->log('ERROR', "Could not resolve metadata for {$root}");
|
|
return 1;
|
|
}
|
|
|
|
// Provide backward-compatible aliases (hyphenated → underscore)
|
|
$fields = $this->addAliases($fields);
|
|
|
|
// Strip empty values
|
|
$fields = array_filter($fields, fn($v) => $v !== '' && $v !== null);
|
|
|
|
// ── 4. Output ────────────────────────────────────────────────────
|
|
return $this->outputFields($fields, $mode, $field);
|
|
}
|
|
|
|
// ── Gitea manifest API ───────────────────────────────────────────────
|
|
|
|
private function fetchFromApi(string $org, string $repo): ?array
|
|
{
|
|
$token = getenv('GA_TOKEN') ?: getenv('GITEA_TOKEN') ?: '';
|
|
$baseUrl = getenv('GITEA_URL') ?: 'https://git.mokoconsulting.tech';
|
|
$baseUrl = rtrim($baseUrl, '/');
|
|
|
|
if ($token === '') {
|
|
return null;
|
|
}
|
|
|
|
$url = "{$baseUrl}/api/v1/repos/{$org}/{$repo}/manifest";
|
|
$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);
|
|
if ($body === false) {
|
|
return null;
|
|
}
|
|
|
|
// Check HTTP status from response headers
|
|
$status = 0;
|
|
if (isset($http_response_header[0])) {
|
|
preg_match('/\d{3}/', $http_response_header[0], $m);
|
|
$status = (int) ($m[0] ?? 0);
|
|
}
|
|
if ($status < 200 || $status >= 300) {
|
|
return null;
|
|
}
|
|
|
|
$data = json_decode($body, true);
|
|
if (!is_array($data) || empty($data)) {
|
|
return null;
|
|
}
|
|
|
|
$this->log('INFO', "Loaded metadata from Gitea manifest API ({$org}/{$repo})");
|
|
return $data;
|
|
}
|
|
|
|
// ── Auto-detection fallback ──────────────────────────────────────────
|
|
|
|
private function autoDetect(string $root, string $repoName): array
|
|
{
|
|
$fields = [
|
|
'name' => $repoName ?: basename($root),
|
|
'org' => 'MokoConsulting',
|
|
>>>>>>> main
|
|
];
|
|
|
|
// Resolve source directory (source/ or src/)
|
|
$srcDir = null;
|
|
foreach (['source', 'src'] as $candidate) {
|
|
if (is_dir("{$root}/{$candidate}")) {
|
|
$srcDir = $candidate;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// ── Try Joomla detection ─────────────────────────────────────
|
|
$joomlaResult = $this->detectJoomla($root, $srcDir);
|
|
if ($joomlaResult !== null) {
|
|
$fields = array_merge($fields, $joomlaResult);
|
|
$this->log('INFO', "Auto-detected platform: joomla ({$fields['extension_type']} — {$fields['element_name']})");
|
|
return $fields;
|
|
}
|
|
|
|
// ── Try Dolibarr detection ───────────────────────────────────
|
|
$dolibarrResult = $this->detectDolibarr($root);
|
|
if ($dolibarrResult !== null) {
|
|
$fields = array_merge($fields, $dolibarrResult);
|
|
$this->log('INFO', "Auto-detected platform: dolibarr");
|
|
return $fields;
|
|
}
|
|
|
|
// ── Generic fallback ─────────────────────────────────────────
|
|
$fields['platform'] = $this->detectGenericPlatform($root);
|
|
$fields['element_name'] = strtolower($fields['name']);
|
|
$fields['extension_type'] = 'application';
|
|
$fields['language'] = $this->detectLanguage($root);
|
|
if ($srcDir !== null) {
|
|
$fields['entry_point'] = "{$srcDir}/";
|
|
}
|
|
|
|
$this->log('INFO', "Auto-detected platform: {$fields['platform']}");
|
|
return $fields;
|
|
}
|
|
|
|
/**
|
|
* Detect Joomla platform by scanning for extension XML manifests.
|
|
*
|
|
* Searches root and source/ dirs for XML files containing <extension type="...">.
|
|
* Extracts element name from the filename (pkg_*, com_*, mod_*, plg_*, tpl_*) or
|
|
* from the <element> tag inside the manifest.
|
|
*/
|
|
private function detectJoomla(string $root, ?string $srcDir): ?array
|
|
{
|
|
$searchDirs = [$root];
|
|
if ($srcDir !== null) {
|
|
$searchDirs[] = "{$root}/{$srcDir}";
|
|
}
|
|
|
|
foreach ($searchDirs as $dir) {
|
|
$xmlFiles = glob("{$dir}/*.xml") ?: [];
|
|
foreach ($xmlFiles as $xmlFile) {
|
|
$content = @file_get_contents($xmlFile);
|
|
if ($content === false) {
|
|
continue;
|
|
}
|
|
|
|
// Match <extension type="component|module|plugin|package|template|file|library">
|
|
if (!preg_match('/<extension\s+[^>]*type="([^"]+)"/', $content, $typeMatch)) {
|
|
// Also try legacy <install type="...">
|
|
if (!preg_match('/<install\s+[^>]*type="([^"]+)"/', $content, $typeMatch)) {
|
|
continue;
|
|
}
|
|
}
|
|
|
|
$extType = strtolower($typeMatch[1]);
|
|
$basename = pathinfo($xmlFile, PATHINFO_FILENAME);
|
|
|
|
// Try to extract element name from XML <element> tag
|
|
$xml = @simplexml_load_string($content);
|
|
$element = '';
|
|
if ($xml !== false) {
|
|
// Package manifests have <files><file ...>element</file></files>
|
|
// Component/module manifests have <element> or use filename
|
|
$element = (string) ($xml->element ?? '');
|
|
if ($element === '') {
|
|
$element = strtolower($basename);
|
|
}
|
|
} else {
|
|
$element = strtolower($basename);
|
|
}
|
|
|
|
// Derive display name
|
|
$displayName = (string) ($xml->name ?? ucfirst(str_replace('_', ' ', $basename)));
|
|
|
|
return [
|
|
'platform' => 'joomla',
|
|
'extension_type' => $extType,
|
|
'element_name' => $element,
|
|
'display_name' => $displayName,
|
|
'language' => 'PHP',
|
|
'entry_point' => ($srcDir ?? '.') . '/',
|
|
];
|
|
}
|
|
|
|
// Also check for pkg_*.xml pattern specifically
|
|
$pkgFiles = glob("{$dir}/pkg_*.xml") ?: [];
|
|
if (!empty($pkgFiles)) {
|
|
$basename = pathinfo($pkgFiles[0], PATHINFO_FILENAME);
|
|
return [
|
|
'platform' => 'joomla',
|
|
'extension_type' => 'package',
|
|
'element_name' => strtolower($basename),
|
|
'display_name' => ucfirst(str_replace('_', ' ', $basename)),
|
|
'language' => 'PHP',
|
|
'entry_point' => ($srcDir ?? '.') . '/',
|
|
];
|
|
}
|
|
}
|
|
|
|
// Check for com_*/manifest.xml pattern (component subdirectory)
|
|
$comDirs = glob("{$root}/com_*", GLOB_ONLYDIR) ?: [];
|
|
foreach ($comDirs as $comDir) {
|
|
$comManifest = glob("{$comDir}/*.xml") ?: [];
|
|
foreach ($comManifest as $xmlFile) {
|
|
$content = @file_get_contents($xmlFile);
|
|
if ($content && preg_match('/<extension\s+[^>]*type="component"/', $content)) {
|
|
return [
|
|
'platform' => 'joomla',
|
|
'extension_type' => 'component',
|
|
'element_name' => strtolower(basename($comDir)),
|
|
'display_name' => ucfirst(str_replace('com_', '', basename($comDir))),
|
|
'language' => 'PHP',
|
|
'entry_point' => ($srcDir ?? '.') . '/',
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Detect Dolibarr platform by scanning for module descriptor files.
|
|
*/
|
|
private function detectDolibarr(string $root): ?array
|
|
{
|
|
// Look for mod*.class.php containing DolibarrModules
|
|
$searchPaths = [
|
|
"{$root}/core/modules/mod*.class.php",
|
|
"{$root}/*/core/modules/mod*.class.php",
|
|
];
|
|
|
|
foreach ($searchPaths as $pattern) {
|
|
$files = glob($pattern) ?: [];
|
|
foreach ($files as $file) {
|
|
$content = @file_get_contents($file);
|
|
if ($content && str_contains($content, 'DolibarrModules')) {
|
|
$modName = pathinfo($file, PATHINFO_FILENAME);
|
|
// modMyModule.class → mymodule
|
|
$element = strtolower(preg_replace('/^mod/', '', str_replace('.class', '', $modName)));
|
|
|
|
return [
|
|
'platform' => 'dolibarr',
|
|
'extension_type' => 'module',
|
|
'element_name' => $element,
|
|
'display_name' => ucfirst($element),
|
|
'language' => 'PHP',
|
|
'entry_point' => './',
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Secondary: check for update.txt (Dolibarr marker)
|
|
if (file_exists("{$root}/update.txt")) {
|
|
return [
|
|
'platform' => 'dolibarr',
|
|
'extension_type' => 'module',
|
|
'element_name' => strtolower(basename($root)),
|
|
'display_name' => basename($root),
|
|
'language' => 'PHP',
|
|
'entry_point' => './',
|
|
];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Detect generic platform type (php, nodejs, python, etc.) from project files.
|
|
*/
|
|
private function detectGenericPlatform(string $root): string
|
|
{
|
|
if (file_exists("{$root}/composer.json")) {
|
|
return 'php';
|
|
}
|
|
if (file_exists("{$root}/package.json")) {
|
|
return 'nodejs';
|
|
}
|
|
if (file_exists("{$root}/pyproject.toml") || file_exists("{$root}/setup.py")) {
|
|
return 'python';
|
|
}
|
|
if (file_exists("{$root}/go.mod")) {
|
|
return 'go';
|
|
}
|
|
if (file_exists("{$root}/Cargo.toml")) {
|
|
return 'rust';
|
|
}
|
|
return 'generic';
|
|
}
|
|
|
|
/**
|
|
* Detect primary language from project files.
|
|
*/
|
|
private function detectLanguage(string $root): string
|
|
{
|
|
if (file_exists("{$root}/composer.json")) {
|
|
return 'PHP';
|
|
}
|
|
if (file_exists("{$root}/tsconfig.json")) {
|
|
return 'TypeScript';
|
|
}
|
|
if (file_exists("{$root}/package.json")) {
|
|
return 'JavaScript';
|
|
}
|
|
if (file_exists("{$root}/pyproject.toml") || file_exists("{$root}/setup.py")) {
|
|
return 'Python';
|
|
}
|
|
return '';
|
|
}
|
|
|
|
// ── Org/repo resolution ──────────────────────────────────────────────
|
|
|
|
/**
|
|
* Resolve org and repo name from environment or git remote.
|
|
*
|
|
* @return array{0: string, 1: string} [org, repo]
|
|
*/
|
|
private function resolveOrgRepo(string $root): array
|
|
{
|
|
// 1. GITHUB_REPOSITORY env (set in Gitea Actions / GitHub Actions)
|
|
$envRepo = getenv('GITHUB_REPOSITORY') ?: '';
|
|
if ($envRepo !== '' && str_contains($envRepo, '/')) {
|
|
return explode('/', $envRepo, 2);
|
|
}
|
|
|
|
// 2. Parse git remote origin URL
|
|
$remoteUrl = trim((string) shell_exec(
|
|
'git -C ' . escapeshellarg($root) . ' remote get-url origin 2>/dev/null'
|
|
));
|
|
|
|
if ($remoteUrl !== '') {
|
|
// SSH: git@host:Org/Repo.git or HTTPS: https://host/Org/Repo.git
|
|
if (preg_match('#[/:]([^/]+)/([^/]+?)(?:\.git)?$#', $remoteUrl, $m)) {
|
|
return [$m[1], $m[2]];
|
|
}
|
|
}
|
|
|
|
return ['', basename($root)];
|
|
}
|
|
|
|
// ── Backward-compatible aliases ──────────────────────────────────────
|
|
|
|
/**
|
|
* Add hyphenated aliases for underscore fields (backward compat with old manifest.xml consumers).
|
|
* Also map old field names to new ones.
|
|
*/
|
|
private function addAliases(array $fields): array
|
|
{
|
|
// Map API field names → old manifest.xml hyphenated names
|
|
$aliases = [
|
|
'display_name' => 'display-name',
|
|
'license_spdx' => 'license-spdx',
|
|
'license_name' => 'license',
|
|
'standards_version' => 'standards-version',
|
|
'standards_source' => 'standards-source',
|
|
'extension_type' => 'package-type',
|
|
'entry_point' => 'entry-point',
|
|
'element_name' => 'name',
|
|
];
|
|
|
|
foreach ($aliases as $newKey => $oldKey) {
|
|
if (isset($fields[$newKey]) && !isset($fields[$oldKey])) {
|
|
$fields[$oldKey] = $fields[$newKey];
|
|
}
|
|
}
|
|
|
|
return $fields;
|
|
}
|
|
|
|
// ── Output ───────────────────────────────────────────────────────────
|
|
|
|
private function outputFields(array $fields, string $mode, string $field): int
|
|
{
|
|
switch ($mode) {
|
|
case 'field':
|
|
if ($field === '') {
|
|
$this->log('ERROR', "Usage: manifest:read --path <dir> --field <name>");
|
|
$this->log('ERROR', " manifest:read --path <dir> --all");
|
|
$this->log('ERROR', " manifest:read --path <dir> --json");
|
|
$this->log('ERROR', " manifest:read --path <dir> --github-output");
|
|
return 2;
|
|
}
|
|
echo ($fields[$field] ?? '') . "\n";
|
|
break;
|
|
|
|
case 'all':
|
|
foreach ($fields as $k => $v) {
|
|
echo "{$k}={$v}\n";
|
|
}
|
|
break;
|
|
|
|
case 'json':
|
|
echo json_encode($fields, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
|
break;
|
|
|
|
case 'github-output':
|
|
$outputFile = getenv('GITHUB_OUTPUT') ?: getenv('GITEA_OUTPUT') ?: '';
|
|
$lines = [];
|
|
foreach ($fields as $k => $v) {
|
|
$envKey = str_replace('-', '_', $k);
|
|
$lines[$envKey] = "{$envKey}={$v}\n";
|
|
}
|
|
// Deduplicate (aliases may collide after underscore conversion)
|
|
$output = implode('', $lines);
|
|
|
|
if ($outputFile === '') {
|
|
$this->log('WARNING', 'GITHUB_OUTPUT not set — printing to stdout');
|
|
echo $output;
|
|
} else {
|
|
file_put_contents($outputFile, $output, FILE_APPEND);
|
|
$this->log('INFO', "Wrote " . count($lines) . " fields to GITHUB_OUTPUT");
|
|
}
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
$app = new ManifestReadCli();
|
|
exit($app->execute());
|