diff --git a/custom_components/bahmcloud_store/core.py b/custom_components/bahmcloud_store/core.py index 3da7574..3028c3c 100644 --- a/custom_components/bahmcloud_store/core.py +++ b/custom_components/bahmcloud_store/core.py @@ -39,18 +39,15 @@ class RepoItem: url: str source: str # "index" | "custom" - # Provider enrichment owner: str | None = None provider: str | None = None provider_repo_name: str | None = None provider_description: str | None = None default_branch: str | None = None - # Latest version best-effort latest_version: str | None = None latest_version_source: str | None = None # "release" | "tag" | None - # Metadata resolver meta_source: str | None = None meta_name: str | None = None meta_description: str | None = None @@ -122,7 +119,6 @@ class BCSCore: r.provider = detect_provider(r.url) await self._enrich_and_resolve(merged) - self.repos = merged async def _enrich_and_resolve(self, merged: dict[str, RepoItem]) -> None: @@ -149,11 +145,6 @@ class BCSCore: r.meta_author = md.author r.meta_maintainer = md.maintainer - # Display name priority: - # 1) metadata name - # 2) store/user provided name - # 3) provider repo name (fallback) - # 4) url has_user_or_index_name = bool(r.name) and (r.name != r.url) and (not str(r.name).startswith("http")) if r.meta_name: r.name = r.meta_name @@ -253,15 +244,25 @@ class BCSCore: return out # ---------------------------- - # README fetching (0.4.0) + # README fetching # ---------------------------- + def _normalize_repo_name(self, name: str | None) -> str | None: + if not name: + return None + n = name.strip() + if n.endswith(".git"): + n = n[:-4] + return n or None + def _split_owner_repo(self, repo_url: str) -> tuple[str | None, str | None]: u = urlparse(repo_url.rstrip("/")) parts = [p for p in u.path.strip("/").split("/") if p] if len(parts) < 2: return None, None - return parts[0], parts[1] + owner = parts[0].strip() or None + repo = self._normalize_repo_name(parts[1]) + return owner, repo def _is_github(self, repo_url: str) -> bool: return "github.com" in urlparse(repo_url).netloc.lower() @@ -295,17 +296,22 @@ class BCSCore: candidates: list[str] = [] if self._is_github(repo.url): + # raw github content base = f"https://raw.githubusercontent.com/{owner}/{name}/{branch}" candidates.extend([f"{base}/{fn}" for fn in filenames]) + elif self._is_gitea(repo.url): u = urlparse(repo.url.rstrip("/")) root = f"{u.scheme}://{u.netloc}/{owner}/{name}" + + # gitea raw endpoints (both common forms) bases = [ f"{root}/raw/branch/{branch}", f"{root}/raw/{branch}", ] for b in bases: candidates.extend([f"{b}/{fn}" for fn in filenames]) + else: return None