From 1c8a83effc8a1227f781665f23624c2f79900c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Bachmann?= Date: Thu, 15 Jan 2026 12:05:24 +0000 Subject: [PATCH] Test --- custom_components/bahmcloud_store/metadata.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/custom_components/bahmcloud_store/metadata.py b/custom_components/bahmcloud_store/metadata.py index eeaa89e..7fe0f9b 100644 --- a/custom_components/bahmcloud_store/metadata.py +++ b/custom_components/bahmcloud_store/metadata.py @@ -3,7 +3,6 @@ from __future__ import annotations import json import logging from dataclasses import dataclass -from typing import Any from urllib.parse import urlparse from homeassistant.core import HomeAssistant @@ -46,9 +45,13 @@ def _is_github(repo_url: str) -> bool: return "github.com" in urlparse(repo_url).netloc.lower() +def _is_gitlab(repo_url: str) -> bool: + return "gitlab" in urlparse(repo_url).netloc.lower() + + def _is_gitea(repo_url: str) -> bool: host = urlparse(repo_url).netloc.lower() - return host and ("github.com" not in host) and ("gitlab.com" not in host) + return host and ("github.com" not in host) and ("gitlab" not in host) async def _fetch_text(hass: HomeAssistant, url: str) -> str | None: @@ -86,14 +89,10 @@ def _parse_meta_hacs_json(raw: str) -> RepoMetadata: if not isinstance(data, dict): return RepoMetadata(source="hacs.json") - # HACS metadata is not standardized for description/category across all repos, - # but we support common fields and keep them optional. name = data.get("name") description = data.get("description") author = data.get("author") maintainer = data.get("maintainer") - - # Optional: some repos use "category" or "type" for store grouping category = data.get("category") or data.get("type") return RepoMetadata( @@ -128,6 +127,14 @@ async def fetch_repo_metadata(hass: HomeAssistant, repo_url: str, default_branch for fn in filenames: candidates.append((fn, f"{base}/{fn}")) + elif _is_gitlab(repo_url): + u = urlparse(repo_url.rstrip("/")) + root = f"{u.scheme}://{u.netloc}/{owner}/{repo}" + # GitLab raw format + # https://gitlab.com///-/raw// + for fn in filenames: + candidates.append((fn, f"{root}/-/raw/{branch}/{fn}")) + elif _is_gitea(repo_url): u = urlparse(repo_url.rstrip("/")) root = f"{u.scheme}://{u.netloc}/{owner}/{repo}" @@ -158,4 +165,4 @@ async def fetch_repo_metadata(hass: HomeAssistant, repo_url: str, default_branch if meta.source: return meta - return RepoMetadata() + return RepoMetadata() \ No newline at end of file