From 7f1307bf05f14ca14905fc27bbcceaaf8efd0868 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Sun, 31 May 2026 08:02:31 -0500 Subject: [PATCH] fix(cli): auto-detect org/repo in updates_xml_build from manifest and git remote When --org/--repo are not provided and env vars are unset, the tool now reads and from .mokogitea/manifest.xml, with a final fallback to parsing the git remote URL. Fixes broken URLs with empty org/repo segments in generated updates.xml. Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) --- cli/updates_xml_build.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cli/updates_xml_build.php b/cli/updates_xml_build.php index 3d8b94c..4de0cae 100644 --- a/cli/updates_xml_build.php +++ b/cli/updates_xml_build.php @@ -103,6 +103,35 @@ if (file_exists($mokoManifest)) { // is the human-friendly name for releases and updates.xml $detectedDisplayName = (string)($mokoXml->identity->{"display-name"} ?? ''); $detectedPackageType = (string)($mokoXml->build->{"package-type"} ?? ''); + + // Auto-detect org from manifest if not provided via CLI/env + if (empty($org)) { + $manifestOrg = (string)($mokoXml->identity->org ?? ''); + if ($manifestOrg !== '') { + $org = $manifestOrg; + } + } + // Auto-detect repo from manifest if not provided via CLI/env + if (empty($repo)) { + $manifestName = (string)($mokoXml->identity->name ?? ''); + if ($manifestName !== '') { + $repo = $manifestName; + } + } + } +} + +// -- Fallback: detect org/repo from git remote -------------------------------- +if (empty($org) || empty($repo)) { + $remoteUrl = trim(shell_exec("git -C " . escapeshellarg($root) . " remote get-url origin 2>/dev/null") ?? ''); + // Match patterns: https://host/org/repo.git or git@host:org/repo.git + if (preg_match('#[/:]([^/:]+)/([^/]+?)(?:\.git)?$#', $remoteUrl, $m)) { + if (empty($org)) { + $org = $m[1]; + } + if (empty($repo)) { + $repo = $m[2]; + } } }