terraformDummyRepo/services.py
2023-02-28 13:25:47 +01:00

46 lines
1.6 KiB
Python

from pathlib import Path
from infrastructure import ReleaseRepository, GitApi
from domain import Version, ReleaseType
# Todo: can be removed
class InitReleaseService():
def __init__(self, release_repo: ReleaseRepository):
self.release_repo = release_repo
def get_version(self):
return self.release_repo.get_release().version
class PrepareReleaseService():
def __init__(self, release_repo: ReleaseRepository):
self.release_repo = release_repo
def __write_and_commit_version(self, version: Version, commit_message: str):
if self.main_branch != self.git_repository.get_current_branch():
raise Exception('Trying to release while not on main branch')
self.version_repository.write_file(version.get_version_string())
self.git_repository.add_file(self.config_file)
self.git_repository.commit(commit_message)
def write_and_commit_release(self, release_version: Version):
self.__write_and_commit_version(release_version, commit_message=f'Release {release_version.get_version_string()}')
def write_and_commit_bump(self, bump_version: Version):
self.__write_and_commit_version(bump_version, commit_message=f'Version bump')
class TagAndPushReleaseService():
def __init__(self, git_api: GitApi):
self.git_api = git_api
def tag_and_push_release(self, release_version: Version):
annotation = 'v' + release_version.get_version_string()
message = 'Release ' + annotation
self.git_api.tag_annotated(annotation, message, 1)
# self.git_repository.push()