Skip to content

Commit

Permalink
Only grab the defined file for zip releases (#3274)
Browse files Browse the repository at this point in the history
* Only grab the defined file for zip releases

* typo

* move validation

* lint
  • Loading branch information
ludeeus authored Sep 25, 2023
1 parent 6f2ba69 commit 98eeb42
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
9 changes: 9 additions & 0 deletions custom_components/hacs/repositories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,17 @@ async def download_zip_files(self, validate) -> None:
download_queue = QueueManager(hass=self.hacs.hass)

for content in contents or []:
if (
self.repository_manifest.zip_release
and content.name != self.repository_manifest.filename
):
continue
download_queue.add(self.async_download_zip_file(content, validate))

if download_queue.pending_tasks == 0:
validate.errors.append("Nothing to download")
return

await download_queue.execute()
except BaseException: # lgtm [py/catch-base-exception] pylint: disable=broad-except
validate.errors.append("Download was not completed")
Expand Down
10 changes: 7 additions & 3 deletions custom_components/hacs/validate/hacsjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from voluptuous.error import Invalid

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

Expand All @@ -25,6 +25,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

if self.repository.data.category == HacsCategory.INTEGRATION:
if hacsjson.zip_release and not hacsjson.filename:
raise ValidationException("zip_release is True, but filename is not set")
23 changes: 23 additions & 0 deletions tests/validate/test_hacsjson_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,26 @@ async def _async_get_hacs_json(_):
check = Validator(repository)
await check.execute_validation()
assert check.failed


@pytest.mark.asyncio
async def test_hacs_manifest_with_missing_filename(repository, caplog):
repository.tree = [
AIOGitHubAPIRepositoryTreeContent(
{"path": "hacs.json", "type": "file"}, "test/test", "main"
)
]
repository.data.category = "integration"

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

repository.async_get_hacs_json = _async_get_hacs_json

check = Validator(repository)
await check.execute_validation()
assert check.failed
assert (
"<Validation hacsjson> failed: zip_release is True, but filename is not set (More info: https://hacs.xyz/docs/publish/include#check-hacs-manifest )"
in caplog.text
)

0 comments on commit 98eeb42

Please sign in to comment.