repository CRUD

This commit is contained in:
2026-04-26 00:29:07 +02:00
parent 29e855e5b3
commit 6da0e8966b
6 changed files with 159 additions and 1 deletions

View File

@@ -82,6 +82,52 @@ class RegistryStore:
repository_id = int(cursor.lastrowid)
return self.get_repository(repository_id)
def update_repository(
self,
repository_id: int,
*,
name: str | None = None,
description: str | None = None,
branch: str | None = None,
) -> Repository:
self.get_repository(repository_id)
assignments: list[str] = []
values: list[str | int | None] = []
if name is not None:
assignments.append("name = ?")
values.append(name)
if description is not None:
assignments.append("description = ?")
values.append(description)
if branch is not None:
assignments.append("branch = ?")
values.append(branch)
if not assignments:
return self.get_repository(repository_id)
values.append(repository_id)
with self.connect() as connection:
cursor = connection.execute(
f"""
UPDATE repositories
SET {", ".join(assignments)}, updated_at = CURRENT_TIMESTAMP
WHERE id = ?
""",
values,
)
if cursor.rowcount == 0:
raise NotFoundError(f"repository {repository_id} was not found")
return self.get_repository(repository_id)
def delete_repository(self, repository_id: int) -> None:
with self.connect() as connection:
cursor = connection.execute(
"DELETE FROM repositories WHERE id = ?",
(repository_id,),
)
if cursor.rowcount == 0:
raise NotFoundError(f"repository {repository_id} was not found")
def update_repository_status(self, repository_id: int, status: str) -> None:
with self.connect() as connection:
cursor = connection.execute(