From d45fe704b6f8de9b7b065f2006d62b4489c7b51a Mon Sep 17 00:00:00 2001 From: Piotr Dec Date: Tue, 14 Oct 2025 19:55:43 +0200 Subject: [PATCH] VCS fix for non-existing code base --- app/config/__init__.py | 6 ++++++ app/config/settings.py | 3 ++- app/services/vcs.py | 19 +++++++++++++++++-- config/config.yaml | 3 +++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/config/__init__.py b/app/config/__init__.py index 1fb2e97..7829e5c 100644 --- a/app/config/__init__.py +++ b/app/config/__init__.py @@ -1 +1,7 @@ +from .settings import AppConfig +from .settings import GitConfig +from .settings import KeePassConfig +from .settings import Settings from .settings import get_settings + +__all__ = [AppConfig, GitConfig, KeePassConfig, Settings, get_settings] diff --git a/app/config/settings.py b/app/config/settings.py index c831957..06f75e3 100644 --- a/app/config/settings.py +++ b/app/config/settings.py @@ -13,7 +13,8 @@ class AppConfig(BaseModel): class GitConfig(BaseModel): - directory: str = "/opt/repo/sample" + path: Path = Path("/opt/repo/sample") + url: str = "ssh://git@hattori.ztsh.eu:29418/paas/heimdall.git" branch: str = "master" remote: str = "origin" diff --git a/app/services/vcs.py b/app/services/vcs.py index c137108..2f0a1a2 100644 --- a/app/services/vcs.py +++ b/app/services/vcs.py @@ -1,18 +1,33 @@ from git import Repo, Remote -from app.config import get_settings +from app.config import GitConfig, get_settings class GitService: def __init__(self): self._settings = get_settings() - self._repo = Repo(self._settings.git.directory) + self._repo = self._check_preconditions(self._settings.git) + if self._repo.head.ref.name != self._settings.git.branch: + self._repo.git.checkout(self._settings.git.branch) self._origin: Remote = self._repo.remotes.origin + def get_modified_compose(self) -> str | None: self._update() return self._diff() + @staticmethod + def _check_preconditions(config: GitConfig) -> Repo: + def clone(): + return Repo.clone_from(config.url, config.path, branch=config.branch) + import os + if not config.path.exists(): + return clone() + if not (config.path / ".git").exists(): + os.rmdir(config.path) + return clone() + return Repo(config.path) + def _update(self): self._origin.pull() diff --git a/config/config.yaml b/config/config.yaml index 5b47197..6d4400f 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -2,6 +2,9 @@ app: host: "127.0.0.1" port: 8000 reload: true +git: + path: "F:/IdeaProjects/paas/karl/.compose_repository" + branch: "main" kp: file: "config/kp.kdbx" secret: "config/secret.txt"