Skip to content

Commit

Permalink
Handle repository renames of downloaded repositories (#2285)
Browse files Browse the repository at this point in the history
* Handle repository renames of downloaded repositories

* Retry with new name if changed
  • Loading branch information
ludeeus authored Nov 13, 2021
1 parent fc15c8a commit b0732b1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
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 comments on commit b0732b1

Please sign in to comment.