custom_components/bahmcloud_store/core.py aktualisiert

This commit is contained in:
2026-01-15 10:13:13 +00:00
parent acb01b9768
commit 64835b719f

View File

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