From ad9c4ea42113a5009546b8fa40ca1f7587334a8e Mon Sep 17 00:00:00 2001 From: bahmcloud Date: Thu, 15 Jan 2026 08:32:58 +0000 Subject: [PATCH] custom_components/bahmcloud_store/providers.py aktualisiert --- .../bahmcloud_store/providers.py | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/custom_components/bahmcloud_store/providers.py b/custom_components/bahmcloud_store/providers.py index 2b7ab17..be6a1b5 100644 --- a/custom_components/bahmcloud_store/providers.py +++ b/custom_components/bahmcloud_store/providers.py @@ -16,6 +16,7 @@ class RepoInfo: repo_name: str | None = None description: str | None = None provider: str | None = None + default_branch: str | None = None def _split_owner_repo(repo_url: str) -> tuple[str | None, str | None]: @@ -27,13 +28,11 @@ def _split_owner_repo(repo_url: str) -> tuple[str | None, str | None]: def detect_provider(repo_url: str) -> str: - """Best-effort provider detection by hostname.""" host = urlparse(repo_url).netloc.lower() if "github.com" in host: return "github" if "gitlab.com" in host: return "gitlab" - # Default for self-hosted setups: assume Gitea when URL looks like owner/repo owner, repo = _split_owner_repo(repo_url) if owner and repo: return "gitea" @@ -41,14 +40,9 @@ def detect_provider(repo_url: str) -> str: async def fetch_repo_info(hass: HomeAssistant, repo_url: str) -> RepoInfo: - """ - Fetch owner/name/description from a provider API if possible. - This is best-effort and must never break the store if it fails. - """ provider = detect_provider(repo_url) owner, repo = _split_owner_repo(repo_url) - - info = RepoInfo(owner=owner, repo_name=repo, description=None, provider=provider) + info = RepoInfo(owner=owner, repo_name=repo, description=None, provider=provider, default_branch=None) if not owner or not repo: return info @@ -58,19 +52,14 @@ async def fetch_repo_info(hass: HomeAssistant, repo_url: str) -> RepoInfo: try: if provider == "github": api = f"https://api.github.com/repos/{owner}/{repo}" - async with session.get( - api, - timeout=15, - headers={"Accept": "application/vnd.github+json"}, - ) as resp: + async with session.get(api, timeout=15, headers={"Accept": "application/vnd.github+json"}) as resp: if resp.status != 200: _LOGGER.debug("GitHub repo info failed (%s): %s", resp.status, api) return info data = await resp.json() info.description = data.get("description") info.repo_name = data.get("name") or repo - - # Owner returned by API is canonical + info.default_branch = data.get("default_branch") or "main" if isinstance(data.get("owner"), dict) and data["owner"].get("login"): info.owner = data["owner"]["login"] return info @@ -86,12 +75,11 @@ async def fetch_repo_info(hass: HomeAssistant, repo_url: str) -> RepoInfo: data = await resp.json() info.description = data.get("description") info.repo_name = data.get("name") or repo - + info.default_branch = data.get("default_branch") or "main" if isinstance(data.get("owner"), dict) and data["owner"].get("login"): info.owner = data["owner"]["login"] return info - # GitLab and generic providers will be implemented later return info except Exception as e: