custom_components/bahmcloud_store/core.py aktualisiert
This commit is contained in:
@@ -212,13 +212,32 @@ class BCSCore:
|
||||
await self.refresh()
|
||||
self.signal_updated()
|
||||
|
||||
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
|
||||
async def list_custom_repos(self) -> list[CustomRepo]:
|
||||
return await self.storage.list_custom_repos()
|
||||
|
||||
def list_repos_public(self) -> list[dict[str, Any]]:
|
||||
out: list[dict[str, Any]] = []
|
||||
for r in self.repos.values():
|
||||
out.append(
|
||||
{
|
||||
"id": r.id,
|
||||
"name": r.name,
|
||||
"url": r.url,
|
||||
"source": r.source,
|
||||
"owner": r.owner,
|
||||
"provider": r.provider,
|
||||
"repo_name": r.provider_repo_name,
|
||||
"description": r.provider_description or r.meta_description,
|
||||
"default_branch": r.default_branch,
|
||||
"latest_version": r.latest_version,
|
||||
"latest_version_source": r.latest_version_source,
|
||||
"category": r.meta_category,
|
||||
"meta_author": r.meta_author,
|
||||
"meta_maintainer": r.meta_maintainer,
|
||||
"meta_source": r.meta_source,
|
||||
}
|
||||
)
|
||||
return out
|
||||
|
||||
def _split_owner_repo(self, repo_url: str) -> tuple[str | None, str | None]:
|
||||
u = urlparse(repo_url.rstrip("/"))
|
||||
@@ -226,8 +245,11 @@ class BCSCore:
|
||||
if len(parts) < 2:
|
||||
return None, None
|
||||
owner = parts[0].strip() or None
|
||||
repo = self._normalize_repo_name(parts[1])
|
||||
return owner, repo
|
||||
name = parts[1].strip()
|
||||
if name.endswith(".git"):
|
||||
name = name[:-4]
|
||||
name = name.strip() or None
|
||||
return owner, name
|
||||
|
||||
def _is_github(self, repo_url: str) -> bool:
|
||||
return "github.com" in urlparse(repo_url).netloc.lower()
|
||||
@@ -236,12 +258,6 @@ class BCSCore:
|
||||
host = urlparse(repo_url).netloc.lower()
|
||||
return host and "github.com" not in host and "gitlab.com" not in host
|
||||
|
||||
def _is_gitlab(self, repo_url: str, provider: str | None = None) -> bool:
|
||||
host = urlparse(repo_url).netloc.lower()
|
||||
if provider and provider.strip().lower() == "gitlab":
|
||||
return True
|
||||
return "gitlab" in host
|
||||
|
||||
async def _fetch_text(self, url: str) -> str | None:
|
||||
session = async_get_clientsession(self.hass)
|
||||
try:
|
||||
@@ -279,6 +295,13 @@ class BCSCore:
|
||||
# Filename fallbacks
|
||||
filenames = ["README.md", "readme.md", "README.MD", "README.rst", "README"]
|
||||
|
||||
provider = (repo.provider or "").strip().lower()
|
||||
if not provider:
|
||||
provider = detect_provider(repo_url) or ""
|
||||
|
||||
u = urlparse(repo_url.rstrip("/"))
|
||||
host = (u.netloc or "").lower()
|
||||
|
||||
candidates: list[str] = []
|
||||
|
||||
if self._is_github(repo_url):
|
||||
@@ -289,21 +312,21 @@ class BCSCore:
|
||||
base = f"https://raw.githubusercontent.com/{owner}/{name}/{branch}"
|
||||
candidates.extend([f"{base}/{fn}" for fn in filenames])
|
||||
|
||||
elif self._is_gitlab(repo_url, repo.provider):
|
||||
elif provider == "gitlab" or "gitlab" in host:
|
||||
# GitLab can have nested groups: /group/subgroup/repo
|
||||
u = urlparse(repo_url.rstrip("/"))
|
||||
parts = [p for p in u.path.strip("/").split("/") if p]
|
||||
if len(parts) < 2:
|
||||
return None
|
||||
|
||||
repo_name = self._normalize_repo_name(parts[-1])
|
||||
repo_name = parts[-1].strip()
|
||||
if repo_name.endswith(".git"):
|
||||
repo_name = repo_name[:-4]
|
||||
group_path = "/".join(parts[:-1]).strip("/")
|
||||
if not group_path or not repo_name:
|
||||
return None
|
||||
|
||||
root = f"{u.scheme}://{u.netloc}/{group_path}/{repo_name}"
|
||||
for branch in branch_candidates:
|
||||
# Most common GitLab raw form
|
||||
bases = [
|
||||
f"{root}/-/raw/{branch}",
|
||||
# Some instances may expose /raw/<branch> as well
|
||||
@@ -317,11 +340,9 @@ class BCSCore:
|
||||
if not owner or not name:
|
||||
return None
|
||||
|
||||
u = urlparse(repo_url.rstrip("/"))
|
||||
root = f"{u.scheme}://{u.netloc}/{owner}/{name}"
|
||||
|
||||
for branch in branch_candidates:
|
||||
# gitea raw endpoints (both common forms)
|
||||
bases = [
|
||||
f"{root}/raw/branch/{branch}",
|
||||
f"{root}/raw/{branch}",
|
||||
|
||||
Reference in New Issue
Block a user