Skip to content

Commit

Permalink
Always use ref for validation (#3429)
Browse files Browse the repository at this point in the history
* Always use ref for validation

* Update test
  • Loading branch information
ludeeus authored May 23, 2024
1 parent 69e197c commit 44e253e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
23 changes: 13 additions & 10 deletions custom_components/hacs/repositories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ async def async_get_hacs_json(self, ref: str = None) -> dict[str, Any] | None:
except BaseException: # lgtm [py/catch-base-exception] pylint: disable=broad-except
pass

async def async_get_info_file_contents(self) -> str:
async def async_get_info_file_contents(self, *, version: str | None = None, **kwargs) -> str:
"""Get the content of the info.md file."""

def _info_file_variants() -> tuple[str, ...]:
Expand All @@ -739,7 +739,7 @@ def _info_file_variants() -> tuple[str, ...]:
if not info_files:
return ""

return await self.get_documentation(filename=info_files[0]) or ""
return await self.get_documentation(filename=info_files[0], version=version) or ""

def remove(self) -> None:
"""Run remove tasks."""
Expand Down Expand Up @@ -1317,28 +1317,31 @@ async def get_documentation(
self,
*,
filename: str | None = None,
version: str | None = None,
**kwargs,
) -> str | None:
"""Get the documentation of the repository."""
if filename is None:
return None

version = (
(self.data.installed_version or self.data.installed_commit)
if self.data.installed
else (self.data.last_version or self.data.last_commit or self.ref)
)
if version is not None:
target_version = version
elif self.data.installed:
target_version = self.data.installed_version or self.data.installed_commit
else:
target_version = self.data.last_version or self.data.last_commit or self.ref

self.logger.debug(
"%s Getting documentation for version=%s,filename=%s",
self.string,
version,
target_version,
filename,
)
if version is None:
if target_version is None:
return None

result = await self.hacs.async_download_file(
f"https://raw.githubusercontent.com/{self.data.full_name}/{version}/{filename}",
f"https://raw.githubusercontent.com/{self.data.full_name}/{target_version}/{filename}",
nolog=True,
)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/validate/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Validator(ActionValidationBase):

async def async_validate(self) -> None:
"""Validate the repository."""
info = await self.repository.async_get_info_file_contents()
info = await self.repository.async_get_info_file_contents(version=self.repository.ref)
for line in info.split("\n"):
if "<img" in line or "![" in line:
if [ignore for ignore in IGNORED if ignore in line]:
Expand Down
4 changes: 2 additions & 2 deletions tests/repositories/test_get_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ async def test_validate_repository(
setattr(repository.data, key, value)

hacs.session = await client_session_proxy(hacs.hass)
docs = await repository.get_documentation(filename="README.md")
docs = await repository.get_documentation(filename="README.md", version=None)

if result:
assert result in docs
else:
assert result is None
assert docs is None

0 comments on commit 44e253e

Please sign in to comment.