Refactoring around add-on store Repository classes (#5990)

* Rename repository fixture to test_repository

Also don't remove the built-in repositories. The list was incomplete,
and tests don't seem to require that anymore.

* Get rid of StoreType

The type doesn't have much value, we have constant strings anyways.

* Introduce types.py

* Use slug to determine which repository urls to return

* Simplify BuiltinRepository enum

* Mock GitRepo load

* Improve URL handling and repository creation logic

* Refactor update_repositories

* Get rid of get_from_url

It is no longer used in production code.

* More refactoring

* Address pylint

* Introduce is_git_based property to Repository class

Return all git based URLs, including the Core repository.

* Revert "Introduce is_git_based property to Repository class"

This reverts commit dfd5ad79bf.

* Fold type.py into const.py

Align more with how Supervisor code is typically structured.

* Update supervisor/store/__init__.py

Co-authored-by: Mike Degatano <michael.degatano@gmail.com>

* Apply repository remove suggestion

* Fix tests

---------

Co-authored-by: Mike Degatano <michael.degatano@gmail.com>
This commit is contained in:
Stefan Agner
2025-07-10 11:07:53 +02:00
committed by GitHub
parent 7873c457d5
commit baf9695cf7
16 changed files with 247 additions and 235 deletions

View File

@@ -591,7 +591,7 @@ def run_supervisor_state(request: pytest.FixtureRequest) -> Generator[MagicMock]
@pytest.fixture
def store_addon(coresys: CoreSys, tmp_path, repository):
def store_addon(coresys: CoreSys, tmp_path, test_repository):
"""Store add-on fixture."""
addon_obj = AddonStore(coresys, "test_store_addon")
@@ -604,18 +604,11 @@ def store_addon(coresys: CoreSys, tmp_path, repository):
@pytest.fixture
async def repository(coresys: CoreSys):
"""Repository fixture."""
coresys.store._data[ATTR_REPOSITORIES].remove(
"https://github.com/hassio-addons/repository"
)
coresys.store._data[ATTR_REPOSITORIES].remove(
"https://github.com/esphome/home-assistant-addon"
)
async def test_repository(coresys: CoreSys):
"""Test add-on store repository fixture."""
coresys.config._data[ATTR_ADDONS_CUSTOM_LIST] = []
with (
patch("supervisor.store.validate.BUILTIN_REPOSITORIES", {"local", "core"}),
patch("supervisor.store.git.GitRepo.load", return_value=None),
):
await coresys.store.load()
@@ -633,7 +626,7 @@ async def repository(coresys: CoreSys):
@pytest.fixture
async def install_addon_ssh(coresys: CoreSys, repository):
async def install_addon_ssh(coresys: CoreSys, test_repository):
"""Install local_ssh add-on."""
store = coresys.addons.store[TEST_ADDON_SLUG]
await coresys.addons.data.install(store)
@@ -645,7 +638,7 @@ async def install_addon_ssh(coresys: CoreSys, repository):
@pytest.fixture
async def install_addon_example(coresys: CoreSys, repository):
async def install_addon_example(coresys: CoreSys, test_repository):
"""Install local_example add-on."""
store = coresys.addons.store["local_example"]
await coresys.addons.data.install(store)