8000 Handle repository renames of downloaded repositories by ludeeus · Pull Request #2285 · hacs/integration · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Handle repository renames of downloaded repositories #2285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions custom_components/hacs/hacsbase/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ async def restore(self):
self.hacs.common.archived_repositories = hacs.get("archived_repositories", [])
self.hacs.common.renamed_repositories = hacs.get("renamed_repositories", {})

# Repositories
hass = self.hacs.hass
stores = {}

Expand All @@ -148,6 +147,10 @@ async def restore(self):
def _load_from_storage():
for entry, store in stores.items():
if os.path.exists(store.path) and (data := store.load()):
if (full_name := data.get("full_name")) and (
renamed := self.hacs.common.renamed_repositories.get(full_name)
) is not None:
data["full_name"] = renamed
update_repository_from_storage(self.hacs.get_by_id(entry), data)

await hass.async_add_executor_job(_load_from_storage)
Expand Down Expand Up @@ -201,7 +204,7 @@ def async_restore_repository(self, entry, repository_data):
if repository.data.installed:
repository.status.first_install = False

if repository_data["full_name"] == "hacs/integration":
if full_name == "hacs/integration":
repository.data.installed_version = self.hacs.version
repository.data.installed = True

Expand Down
13 changes: 11 additions & 2 deletions custom_components/hacs/helpers/classes/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

from aiogithubapi import AIOGitHubAPIException

from custom_components.hacs.exceptions import HacsException, HacsNotModifiedException
from custom_components.hacs.exceptions import (
HacsException,
HacsNotModifiedException,
HacsRepositoryExistException,
)
from custom_components.hacs.helpers import RepositoryHelpers
from custom_components.hacs.helpers.classes.manifest import HacsManifest
from custom_components.hacs.helpers.classes.repositorydata import RepositoryData
Expand Down Expand Up @@ -267,7 +271,12 @@ async def common_update(self, ignore_issues=False, force=False):

# Attach repository
current_etag = self.data.etag_repository
await common_update_data(self, ignore_issues, force)
try:
await common_update_data(self, ignore_issues, force)
except HacsRepositoryExistException:
self.data.full_name = self.hacs.common.renamed_repositories[self.data.full_name]
await common_update_data(self, ignore_issues, force)

if not self.data.installed and (current_etag == self.data.etag_repository) and not force:
self.logger.debug("Did not update %s, content was not modified", self.data.full_name)
return False
Expand Down
1 change: 1 addition & 0 deletions custom_components/hacs/helpers/functions/download.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Helpers to download repository content."""
from __future__ import annotations

import asyncio
import os
import pathlib
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ async def register_repository(full_name, category, check=True, ref=None):
if category not in RERPOSITORY_CLASSES:
raise HacsException(f"{category} is not a valid repository category.")

if (renamed := hacs.common.renamed_repositories.get(full_name)) is not None:
full_name = renamed

repository: HacsRepository = RERPOSITORY_CLASSES[category](full_name)
if check:
try:
Expand Down
0