Merge branch 'develop' into di

# Conflicts:
#	app/main.py
#	app/services/vcs.py
#	config/config.yaml
This commit is contained in:
Piotr Dec 2025-10-16 00:13:38 +02:00
commit 1eab4cd6fc
Signed by: stawros
GPG key ID: 74B18A3F0F1E99C0
10 changed files with 162 additions and 44 deletions

View file

@ -1,23 +1,35 @@
from git import Repo, Remote
from injectable import injectable
from app.config import get_settings
from app.config import GitConfig, get_settings
@injectable(singleton=True)
class GitService:
def __init__(self):
self._settings = get_settings()
try: # TODO: clone if not exists
self._repo = Repo(self._settings.git.directory)
self._origin: Remote = self._repo.remotes.origin
except:
self._repo = None
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()