plugin forge: Check that repository exist before returning counters.

This commit is contained in:
Goffi 2026-03-18 10:54:59 +01:00
commit 04d53ebe10

View file

@ -190,8 +190,14 @@ class Forge:
return defer.succeed(repositories.model_dump_json())
def repositories_get(
self, client: SatXMPPEntity, target_profile: str, data: dict | None = None
self, client: SatXMPPEntity, target_profile: str
) -> Repositories:
"""Retrieve repositories of a profile.
@param client: Client instance.
@param target_profile: Profile to retrieve repositories from.
@return: List of repositories.
@raise exceptions.NotFound: No repository found.
"""
try:
return self.settings.repositories[target_profile]
except KeyError:
@ -270,7 +276,15 @@ class Forge:
@param repository_name: Name of the repository.
@param request: Which counters to retrieve.
@return: List of clone counters.
@raise exceptions.NotFound: The requested repository can't be found.
"""
repositories = self.repositories_get(client, target_profile)
try:
next(r for r in repositories if r.name == repository_name)
except StopIteration:
raise exceptions.NotFound(
f"{target_profile} has not repository named {repository_name}."
)
namespace = PLUGIN_INFO[C.PI_NAME]
profile_id = G.storage.profiles[target_profile]
key_prefix = f"counter:{repository_name}:"