Skip to content

Commit

Permalink
Fix downloading spesific version for non-zip release assets (#3327)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Oct 29, 2023
1 parent 8c56abe commit 63b2c41
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
33 changes: 30 additions & 3 deletions custom_components/hacs/repositories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,9 @@ def cleanup_temp_dir():
except BaseException: # lgtm [py/catch-base-exception] pylint: disable=broad-except
validate.errors.append("Download was not completed")

async def download_content(self) -> None:
async def download_content(self, version: string | None = None) -> None:
"""Download the content of a directory."""
contents: list[FileInformation] | None = None
if self.hacs.configuration.experimental:
if (
not self.repository_manifest.zip_release
Expand All @@ -672,9 +673,15 @@ async def download_content(self) -> None:
except HacsException as exception:
self.logger.exception(exception)

contents = self.gather_files_to_download()
if self.repository_manifest.filename:
self.logger.debug("%s %s", self.string, self.repository_manifest.filename)

if self.content.path.remote == "release" and version is not None:
contents = await self.release_contents(version)

if not contents:
contents = self.gather_files_to_download()

if not contents:
raise HacsException("No content to download")

Expand Down Expand Up @@ -1036,6 +1043,7 @@ async def async_install_repository(self, *, version: str | None = None, **_) ->

self.hacs.log.debug("%s Local path is set to %s", self.string, self.content.path.local)
self.hacs.log.debug("%s Remote path is set to %s", self.string, self.content.path.remote)
self.hacs.log.debug("%s Version to install: %s", self.string, version_to_install)

self.hacs.async_dispatch(
HacsDispatchEvent.REPOSITORY_DOWNLOAD_PROGRESS,
Expand All @@ -1045,7 +1053,7 @@ async def async_install_repository(self, *, version: str | None = None, **_) ->
if self.repository_manifest.zip_release and version_to_install != self.data.default_branch:
await self.download_zip_files(self.validate)
else:
await self.download_content()
await self.download_content(version_to_install)

self.hacs.async_dispatch(
HacsDispatchEvent.REPOSITORY_DOWNLOAD_PROGRESS,
Expand Down Expand Up @@ -1294,6 +1302,25 @@ def gather_files_to_download(self) -> list[FileInformation]:
files.append(FileInformation(path.download_url, path.full_path, path.filename))
return files

async def release_contents(self, version: str | None = None) -> list[FileInformation] | None:
"""Gather the contents of a release."""
release = await self.hacs.async_github_api_method(
method=self.hacs.githubapi.generic,
endpoint=f"/repos/{self.data.full_name}/releases/tags/{version}",
raise_exception=False,
)
if release is None:
return None

return [
FileInformation(
url=asset.get("browser_download_url"),
path=asset.get("name"),
name=asset.get("name"),
)
for asset in release.data.get("assets", [])
]

@concurrent(concurrenttasks=10)
async def dowload_repository_content(self, content: FileInformation) -> None:
"""Download content."""
Expand Down
11 changes: 9 additions & 2 deletions custom_components/hacs/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .const import DOMAIN
from .entity import HacsRepositoryEntity
from .enums import HacsCategory, HacsDispatchEvent
from .exceptions import HacsException


async def async_setup_entry(hass, _config_entry, async_add_devices):
Expand Down Expand Up @@ -99,8 +100,14 @@ async def async_install(self, version: str | None, backup: bool, **kwargs: Any)
self.repository.force_branch = version is not None
self._update_in_progress(progress=20)

await self.repository.async_install(version=version)
self._update_in_progress(progress=False)
try:
await self.repository.async_install(version=version)
except HacsException as exception:
raise HomeAssistantError(
f"{exception} for {version}" if version else exception
) from exception
finally:
self._update_in_progress(progress=False)

async def async_release_notes(self) -> str | None:
"""Return the release notes."""
Expand Down

0 comments on commit 63b2c41

Please sign in to comment.