Introduce is_git_based property to Repository class

Return all git based URLs, including the Core repository.
This commit is contained in:
Stefan Agner
2025-07-04 16:52:17 +02:00
parent 301b7b947a
commit dfd5ad79bf
3 changed files with 18 additions and 9 deletions
+1 -7
View File
@@ -21,7 +21,6 @@ from .addon import AddonStore
from .const import FILE_HASSIO_STORE
from .data import StoreData
from .repository import Repository
from .types import BuiltinRepository
from .validate import SCHEMA_STORE_FILE, ensure_builtin_repositories
_LOGGER: logging.Logger = logging.getLogger(__name__)
@@ -50,12 +49,7 @@ class StoreManager(CoreSysAttributes, FileConfiguration):
@property
def repository_urls(self) -> list[str]:
"""Return source URL for all git repositories."""
return [
repository.source
for repository in self.all
if repository.slug
not in {BuiltinRepository.LOCAL.value, BuiltinRepository.CORE.value}
]
return [repository.source for repository in self.all if repository.is_git_based]
def get(self, slug: str) -> Repository:
"""Return Repository with slug."""
+15
View File
@@ -112,6 +112,11 @@ class Repository(CoreSysAttributes, ABC):
def is_builtin(self) -> bool:
"""Return True if this is a built-in repository."""
@property
@abstractmethod
def is_git_based(self) -> bool:
"""Return True if this is a git-based repository."""
@abstractmethod
async def validate(self) -> bool:
"""Check if store is valid."""
@@ -158,6 +163,11 @@ class RepositoryGit(Repository, ABC):
_git: GitRepo
@property
def is_git_based(self) -> bool:
"""Return True if this is a git-based repository."""
return True
async def load(self) -> None:
"""Load addon repository."""
await self._git.load()
@@ -210,6 +220,11 @@ class RepositoryLocal(RepositoryBuiltin):
super().__init__(coresys, BuiltinRepository.LOCAL.value, local_path, slug)
self._latest_mtime: float | None = None
@property
def is_git_based(self) -> bool:
"""Return True if this is a git-based repository."""
return False
async def load(self) -> None:
"""Load addon repository."""
self._latest_mtime, _ = await self.sys_run_in_executor(
+2 -2
View File
@@ -44,7 +44,7 @@ async def test_default_load(coresys: CoreSys):
assert isinstance(store_manager.get("core"), Repository)
assert isinstance(store_manager.get("local"), Repository)
assert len(store_manager.repository_urls) == 3
assert len(store_manager.repository_urls) == 4
assert (
"https://github.com/hassio-addons/repository" in store_manager.repository_urls
)
@@ -97,7 +97,7 @@ async def test_load_with_custom_repository(coresys: CoreSys):
assert isinstance(store_manager.get("core"), Repository)
assert isinstance(store_manager.get("local"), Repository)
assert len(store_manager.repository_urls) == 4
assert len(store_manager.repository_urls) == 5
assert (
"https://github.com/hassio-addons/repository" in store_manager.repository_urls
)