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]; + } } }