67 lines
2.6 KiB
Python
67 lines
2.6 KiB
Python
from pathlib import Path
|
|
from infrastructure import VersionRepository, GitRepository
|
|
from domain import Version, ReleaseType
|
|
|
|
class InitReleaseService():
|
|
|
|
def __init__(self, version_repo: VersionRepository):
|
|
if version_repo is None:
|
|
raise Exception('VersionRepo was not created. Did you run create_release_version()?')
|
|
self.version_repo = version_repo
|
|
|
|
def __calculate_release_type(self, commit_string = None):
|
|
if commit_string is None:
|
|
return GitRepository().get_release_type_from_latest_commit()
|
|
else:
|
|
return GitRepository.create_from_commit_string(commit_string).get_release_type_from_latest_commit()
|
|
|
|
def get_version(self):
|
|
return self.version_repo.get_version()
|
|
|
|
def create_release_version(self, commit_string = None):
|
|
release_type = self.__calculate_release_type(commit_string)
|
|
version = self.get_version().create_release_version(release_type)
|
|
return version
|
|
|
|
def create_bump_version(self):
|
|
version = self.get_version().create_bump_version()
|
|
return version
|
|
|
|
|
|
class PrepareReleaseService():
|
|
|
|
def __init__(self, version_repository: VersionRepository, git_repository: GitRepository, config_file: Path, main_branch: str):
|
|
self.version_repository = version_repository
|
|
self.git_repository = git_repository
|
|
self.main_branch = main_branch
|
|
self.config_file = config_file
|
|
|
|
def run_tests(self): # maybe auto?
|
|
raise NotImplementedError
|
|
|
|
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_repository: GitRepository):
|
|
self.git_repository = git_repository
|
|
|
|
def tag_and_push_release(self, release_version: Version):
|
|
annotation = 'v' + release_version.get_version_string()
|
|
message = 'Release ' + annotation
|
|
self.git_repository.tag_annotated(annotation, message, 1)
|
|
# self.git_repository.push()
|
|
|
|
|