This commit is contained in:
2026-01-20 05:46:20 +00:00
parent 644e61aab0
commit 0e99c9c59e

View File

@@ -16,17 +16,6 @@ _LOGGER = logging.getLogger(__name__)
UA = "BahmcloudStore (Home Assistant)"
def _github_headers(github_token: str | None = None) -> dict[str, str]:
headers = {
"Accept": "application/vnd.github+json",
"User-Agent": UA,
}
token = (github_token or "").strip()
if token:
headers["Authorization"] = f"Bearer {token}"
return headers
@dataclass
class RepoInfo:
owner: str | None = None
@@ -331,6 +320,15 @@ async def _gitlab_latest_version(
return None, None
def _github_headers(github_token: str | None = None) -> dict:
headers = {"Accept": "application/vnd.github+json", "User-Agent": UA}
token = (github_token or "").strip()
if token:
# PAT or fine-grained token
headers["Authorization"] = f"Bearer {token}"
return headers
async def fetch_repo_info(hass: HomeAssistant, repo_url: str, *, github_token: str | None = None) -> RepoInfo:
provider = detect_provider(repo_url)
owner, repo = _split_owner_repo(repo_url)
@@ -557,6 +555,8 @@ async def fetch_repo_versions(
session = async_get_clientsession(hass)
headers = {"User-Agent": UA}
if prov == "github":
headers = _github_headers(github_token)
out: list[dict[str, str]] = []
seen: set[str] = set()
@@ -576,7 +576,7 @@ async def fetch_repo_versions(
try:
if prov == "github":
# Releases
gh_headers = _github_headers(github_token)
gh_headers = {"Accept": "application/vnd.github+json", "User-Agent": UA}
data, _ = await _safe_json(
session,
f"https://api.github.com/repos/{owner}/{repo}/releases?per_page={int(limit)}",