VCS service
This commit is contained in:
parent
1d615e9f7d
commit
a55628ce35
2 changed files with 29 additions and 0 deletions
|
|
@ -0,0 +1,28 @@
|
||||||
|
from git import Repo, Remote
|
||||||
|
|
||||||
|
from app.config import get_settings
|
||||||
|
|
||||||
|
|
||||||
|
class GitService:
|
||||||
|
def __init__(self):
|
||||||
|
self._settings = get_settings()
|
||||||
|
self._repo = Repo(self._settings.git.directory)
|
||||||
|
self._origin: Remote = self._repo.remotes.origin
|
||||||
|
|
||||||
|
def get_modified_compose(self) -> str | None:
|
||||||
|
self._update()
|
||||||
|
return self._diff()
|
||||||
|
|
||||||
|
def _update(self):
|
||||||
|
self._origin.pull()
|
||||||
|
|
||||||
|
def _diff(self) -> str | None:
|
||||||
|
diff = self._repo.head.commit.diff("HEAD~1")
|
||||||
|
composes = [f for f in diff if f.a_path.endswith("docker-compose.yml")]
|
||||||
|
match len(composes):
|
||||||
|
case 0:
|
||||||
|
return None
|
||||||
|
case 1:
|
||||||
|
return composes[0].a_path
|
||||||
|
case _:
|
||||||
|
raise Exception("Multiple compose files modified")
|
||||||
|
|
@ -11,6 +11,7 @@ dependencies = [
|
||||||
"jinja2>=3.1.4",
|
"jinja2>=3.1.4",
|
||||||
"pydantic-settings>=2.4.0",
|
"pydantic-settings>=2.4.0",
|
||||||
"pyyaml>=6.0.2",
|
"pyyaml>=6.0.2",
|
||||||
|
"gitpython>=3.1.45"
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue