Merge pull request 'VCS fix for non-existing code base' (#6) from vcs into develop
Reviewed-on: https://hattori.ztsh.eu/paas/karl/pulls/6
This commit is contained in:
commit
1653e141ee
4 changed files with 28 additions and 3 deletions
|
|
@ -1 +1,7 @@
|
||||||
|
from .settings import AppConfig
|
||||||
|
from .settings import GitConfig
|
||||||
|
from .settings import KeePassConfig
|
||||||
|
from .settings import Settings
|
||||||
from .settings import get_settings
|
from .settings import get_settings
|
||||||
|
|
||||||
|
__all__ = [AppConfig, GitConfig, KeePassConfig, Settings, get_settings]
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ class AppConfig(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class GitConfig(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"
|
branch: str = "master"
|
||||||
remote: str = "origin"
|
remote: str = "origin"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,33 @@
|
||||||
from git import Repo, Remote
|
from git import Repo, Remote
|
||||||
|
|
||||||
from app.config import get_settings
|
from app.config import GitConfig, get_settings
|
||||||
|
|
||||||
|
|
||||||
class GitService:
|
class GitService:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._settings = get_settings()
|
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
|
self._origin: Remote = self._repo.remotes.origin
|
||||||
|
|
||||||
|
|
||||||
def get_modified_compose(self) -> str | None:
|
def get_modified_compose(self) -> str | None:
|
||||||
self._update()
|
self._update()
|
||||||
return self._diff()
|
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):
|
def _update(self):
|
||||||
self._origin.pull()
|
self._origin.pull()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ app:
|
||||||
host: "127.0.0.1"
|
host: "127.0.0.1"
|
||||||
port: 8000
|
port: 8000
|
||||||
reload: true
|
reload: true
|
||||||
|
git:
|
||||||
|
path: "F:/IdeaProjects/paas/karl/.compose_repository"
|
||||||
|
branch: "main"
|
||||||
kp:
|
kp:
|
||||||
file: "config/kp.kdbx"
|
file: "config/kp.kdbx"
|
||||||
secret: "config/secret.txt"
|
secret: "config/secret.txt"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue