terraformDummyRepo/services.py

40 lines
1.5 KiB
Python
Raw Normal View History

from pathlib import Path
from infrastructure import VersionRepository, ReleaseRepository, GitApi
2023-02-24 09:31:04 +00:00
from domain import Version, ReleaseType
2023-02-22 08:59:16 +00:00
class PrepareReleaseService():
2023-02-16 15:55:01 +00:00
2023-02-24 10:39:38 +00:00
def __init__(self, release_repo: ReleaseRepository):
self.release_repo = release_repo
self.release = release_repo.get_release()
self.git_api = GitApi()
self.main_branch = None
def __write_and_commit_version(self, version: Version, commit_message: str):
if self.main_branch != self.git_api.get_current_branch():
raise Exception('Trying to release while not on main branch')
self.release_repo.version_repository.write_file(version.get_version_string())
self.git_api.add_file(self.release_repo.version_repository.file)
self.git_api.commit(commit_message)
def write_and_commit_release(self):
self.__write_and_commit_version(self.release.release_version(), commit_message=f'Release {self.release.release_version().get_version_string()}')
def write_and_commit_bump(self):
self.__write_and_commit_version(self.release.bump_version(), commit_message=f'Version bump')
2023-02-16 15:55:01 +00:00
class TagAndPushReleaseService():
2023-02-28 12:25:47 +00:00
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
2023-02-28 12:25:47 +00:00
self.git_api.tag_annotated(annotation, message, 1)
# self.git_api.push()
2023-02-16 15:55:01 +00:00