Test
This commit is contained in:
@@ -3,7 +3,6 @@ from __future__ import annotations
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any
|
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
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()
|
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:
|
def _is_gitea(repo_url: str) -> bool:
|
||||||
host = urlparse(repo_url).netloc.lower()
|
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:
|
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):
|
if not isinstance(data, dict):
|
||||||
return RepoMetadata(source="hacs.json")
|
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")
|
name = data.get("name")
|
||||||
description = data.get("description")
|
description = data.get("description")
|
||||||
author = data.get("author")
|
author = data.get("author")
|
||||||
maintainer = data.get("maintainer")
|
maintainer = data.get("maintainer")
|
||||||
|
|
||||||
# Optional: some repos use "category" or "type" for store grouping
|
|
||||||
category = data.get("category") or data.get("type")
|
category = data.get("category") or data.get("type")
|
||||||
|
|
||||||
return RepoMetadata(
|
return RepoMetadata(
|
||||||
@@ -128,6 +127,14 @@ async def fetch_repo_metadata(hass: HomeAssistant, repo_url: str, default_branch
|
|||||||
for fn in filenames:
|
for fn in filenames:
|
||||||
candidates.append((fn, f"{base}/{fn}"))
|
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/<owner>/<repo>/-/raw/<branch>/<file>
|
||||||
|
for fn in filenames:
|
||||||
|
candidates.append((fn, f"{root}/-/raw/{branch}/{fn}"))
|
||||||
|
|
||||||
elif _is_gitea(repo_url):
|
elif _is_gitea(repo_url):
|
||||||
u = urlparse(repo_url.rstrip("/"))
|
u = urlparse(repo_url.rstrip("/"))
|
||||||
root = f"{u.scheme}://{u.netloc}/{owner}/{repo}"
|
root = f"{u.scheme}://{u.netloc}/{owner}/{repo}"
|
||||||
|
|||||||
Reference in New Issue
Block a user