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

Move get_tree to HacsRepository #2404

Merged
merged 1 commit into from
Dec 28, 2021
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
8 changes: 8 additions & 0 deletions custom_components/hacs/repositories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,3 +892,11 @@ async def async_get_legacy_repository_object(

def update_filenames(self) -> None:
"""Get the filename to target."""

async def get_tree(self, ref: str):
"""Return the repository tree."""
try:
tree = await self.repository_object.get_tree(ref)
return tree
except (ValueError, AIOGitHubAPIException) as exception:
raise HacsException(exception) from exception
9 changes: 0 additions & 9 deletions custom_components/hacs/utils/information.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
from ..exceptions import HacsException


async def get_tree(repository, ref):
"""Return the repository tree."""
try:
tree = await repository.get_tree(ref)
return tree
except (ValueError, AIOGitHubAPIException) as exception:
raise HacsException(exception)


async def get_releases(repository, prerelease=False, returnlimit=5):
"""Return the repository releases."""
try:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/hacs/utils/validate_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
HacsRepositoryArchivedException,
HacsRepositoryExistException,
)
from ..utils.information import get_releases, get_tree
from ..utils.information import get_releases
from ..utils.version import version_to_download

if TYPE_CHECKING:
Expand Down Expand Up @@ -92,7 +92,7 @@ async def common_update_data(
)

try:
repository.tree = await get_tree(repository.repository_object, repository.ref)
repository.tree = await repository.get_tree(repository.ref)
if not repository.tree:
raise HacsException("No files in tree")
repository.treefiles = []
Expand Down
21 changes: 14 additions & 7 deletions tests/helpers/information/test_get_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
# pylint: disable=missing-docstring
import json

import aiohttp
import pytest

from custom_components.hacs.exceptions import HacsException
from custom_components.hacs.utils.information import get_tree

from tests.common import TOKEN
from tests.sample_data import (
repository_data,
response_rate_limit_header,
Expand Down Expand Up @@ -44,8 +41,13 @@ async def test_get_tree(aresponses, repository_integration):
aresponses.Response(body=json.dumps(tree_files_base), headers=response_rate_limit_header),
)

repository, _ = await repository_integration.async_get_legacy_repository_object()
tree = await get_tree(repository, repository.default_branch)
(
repository_integration.repository_object,
_,
) = await repository_integration.async_get_legacy_repository_object()
tree = await repository_integration.get_tree(
repository_integration.repository_object.default_branch
)
assert "hacs.json" in [x.full_path for x in tree]


Expand Down Expand Up @@ -79,6 +81,11 @@ async def test_get_tree_exception(aresponses, repository_integration):
status=403,
),
)
repository, _ = await repository_integration.async_get_legacy_repository_object()
(
repository_integration.repository_object,
_,
) = await repository_integration.async_get_legacy_repository_object()
with pytest.raises(HacsException):
await get_tree(repository, repository.default_branch)
await repository_integration.get_tree(
repository_integration.repository_object.default_branch
)
12 changes: 7 additions & 5 deletions tests/helpers/information/tree/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
# pylint: disable=missing-docstring
import json

import aiohttp
import pytest

from custom_components.hacs.utils.information import get_tree

from tests.sample_data import (
repository_data,
response_rate_limit_header,
Expand Down Expand Up @@ -43,6 +40,11 @@ async def test_base(aresponses, repository_integration):
aresponses.Response(body=json.dumps(tree_files_base), headers=response_rate_limit_header),
)

repository, _ = await repository_integration.async_get_legacy_repository_object()
tree = await get_tree(repository, repository.default_branch)
(
repository_integration.repository_object,
_,
) = await repository_integration.async_get_legacy_repository_object()
tree = await repository_integration.get_tree(
repository_integration.repository_object.default_branch
)
assert "hacs.json" in [x.full_path for x in tree]
12 changes: 7 additions & 5 deletions tests/helpers/information/tree/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
# pylint: disable=missing-docstring
import json

import aiohttp
import pytest

from custom_components.hacs.utils.information import get_tree

from tests.sample_data import (
repository_data,
response_rate_limit_header,
Expand Down Expand Up @@ -46,8 +43,13 @@ async def test_base(aresponses, repository_integration):
),
)

repository, _ = await repository_integration.async_get_legacy_repository_object()
tree = await get_tree(repository, repository.default_branch)
(
repository_integration.repository_object,
_,
) = await repository_integration.async_get_legacy_repository_object()
tree = await repository_integration.get_tree(
repository_integration.repository_object.default_branch
)
filestocheck = [
"custom_components/test/__init__.py",
"custom_components/test/translations/en.json",
Expand Down