Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only grab the defined file for zip releases #3274

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)