Move commit logic to prepare_release_service

This commit is contained in:
bom 2023-02-23 15:07:22 +01:00
parent c58ddf70da
commit fa6beebc4e
3 changed files with 28 additions and 32 deletions

View file

@ -30,29 +30,24 @@ class ReleaseMixin(DevopsBuild):
self.config_file = release_mixin_config['config_file']
self.main_branch = release_mixin_config['main_branch']
self.version_repo = VersionRepository(self.config_file)
self.git_repo = GitRepository()
self.release_version = None
self.bump_version = None
self.commit_string = None
def init(self):
def init_release(self):
init_service = InitReleaseService(self.version_repo)
self.release_version = init_service.create_release_version(self.commit_string)
self.bump_version = self.release_version.create_bump_version()
def prepare(self, version):
git_repository = GitRepository()
if self.main_branch not in git_repository.get_current_branch():
raise Exception('Trying to release while not on main branch')
def prepare_release(self):
prepare_release_service = PrepareReleaseService(self.version_repo, self.config_file, self.main_branch)
if self.release_version is None or self.bump_version is None:
raise Exception('prepare_release was called before init_release')
self.version_repo.write_file(version.get_version_string())
git_repository.add_file(self.config_file)
match version.release_type:
case None:
raise Exception('Release type not set but trying to commit.')
case ReleaseType.BUMP:
git_repository.commit(f'Version bump')
case _:
git_repository.commit(f'Release {version.get_version_string()}')
# prepare_release_service.run_tests() # not implemented
prepare_release_service.write_and_commit_release(self.release_version)
prepare_release_service.write_and_commit_bump(self.bump_version)
def tag_and_push(self, version):
git_repository = GitRepository()

View file

@ -1,3 +1,4 @@
from pathlib import Path
from version_repository import VersionRepository
from release_type import ReleaseType
from git_repository import GitRepository
@ -31,28 +32,28 @@ class InitReleaseService():
class PrepareReleaseService():
def __init__(self, version_repo: VersionRepository):
self.version_repo = version_repo
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?
pass
raise NotImplementedError
def prepare_release(self, version: Version):
# self.version_repo.write_file(version.get_version_string()) # side effect
pass
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')
def prepare_bump(self, version: Version):
# self.version_repo.write_file(version.get_version_string()) # side effect
pass
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()}')
# write
# add
# commit
pass
def write_and_commit_bump(self, bump_version: Version):
self.__write_and_commit_version(bump_version, commit_message=f'Version bump')
class TagAndPushReleaseService():
pass

View file

@ -56,7 +56,7 @@ def test_release_mixin(tmp_path):
# init
build = initialize(project, CONFIG_FILE)
build.commit_string = "MAJOR bla"
build.init()
build.init_release()
release_version = build.release_version
# test