Skip to content

Commit

Permalink
Load HacsManifest during validation (#3302)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Oct 14, 2023
1 parent 50d9a19 commit da13faa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions custom_components/hacs/utils/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def _country_validator(values) -> list[str]:
vol.Optional("content_in_root"): bool,
vol.Optional("country"): _country_validator,
vol.Optional("filename"): str,
vol.Optional("hacs"): vol.Coerce(AwesomeVersion),
vol.Optional("hacs"): str,
vol.Optional("hide_default_branch"): bool,
vol.Optional("homeassistant"): vol.Coerce(AwesomeVersion),
vol.Optional("homeassistant"): str,
vol.Optional("persistent_directory"): str,
vol.Optional("render_readme"): bool,
vol.Optional("zip_release"): bool,
Expand Down
9 changes: 5 additions & 4 deletions custom_components/hacs/validate/hacsjson.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

from voluptuous.error import Invalid
from voluptuous.humanize import humanize_error

from ..enums import HacsCategory, RepositoryFile
from ..repositories.base import HacsRepository
from ..repositories.base import HacsManifest, HacsRepository
from ..utils.validate import HACS_MANIFEST_JSON_SCHEMA
from .base import ActionValidationBase, ValidationException

Expand All @@ -25,10 +26,10 @@ async def async_validate(self):

content = await self.repository.async_get_hacs_json(self.repository.ref)
try:
HACS_MANIFEST_JSON_SCHEMA(content)
hacsjson = HacsManifest.from_dict(HACS_MANIFEST_JSON_SCHEMA(content))
except Invalid as exception:
raise ValidationException(exception) from exception
raise ValidationException(humanize_error(content, exception)) from exception

if self.repository.data.category == HacsCategory.INTEGRATION:
if content.get("zip_release") and not content.get("filename"):
if hacsjson.zip_release and not hacsjson.filename:
raise ValidationException("zip_release is True, but filename is not set")
3 changes: 2 additions & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import homeassistant.util.dt as date_util
from homeassistant.util.unit_system import METRIC_SYSTEM

from custom_components.hacs.repositories.base import HacsRepository
from custom_components.hacs.repositories.base import HacsManifest, HacsRepository
from custom_components.hacs.utils.logger import LOGGER

from tests.async_mock import AsyncMock, Mock, patch
Expand Down Expand Up @@ -65,6 +65,7 @@ def dummy_repository_base(hacs, repository=None):
repository.integration_manifest = {"config_flow": False, "domain": "test"}
repository.data.published_tags = ["1", "2", "3"]
repository.data.update_data(fixture("repository_data.json", asjson=True))
repository.hacs_manifest = HacsManifest.from_dict({})

async def update_repository(*args, **kwargs):
pass
Expand Down
3 changes: 2 additions & 1 deletion tests/validate/test_hacsjson_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from aiogithubapi.objects.repository.content import AIOGitHubAPIRepositoryTreeContent
import pytest

from custom_components.hacs.repositories.base import HacsManifest
from custom_components.hacs.validate.hacsjson import Validator


Expand Down Expand Up @@ -57,7 +58,7 @@ async def test_hacs_manifest_with_missing_filename(repository, caplog):
repository.data.category = "integration"

async def _async_get_hacs_json(_):
return {"name": "test", "zip_release": True}
return {"name": "test", "zip_release": True, "hacs": "0.0.0"}

repository.async_get_hacs_json = _async_get_hacs_json

Expand Down

0 comments on commit da13faa

Please sign in to comment.