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.config_file = release_mixin_config['config_file']
self.main_branch = release_mixin_config['main_branch'] self.main_branch = release_mixin_config['main_branch']
self.version_repo = VersionRepository(self.config_file) self.version_repo = VersionRepository(self.config_file)
self.git_repo = GitRepository()
self.release_version = None self.release_version = None
self.bump_version = None self.bump_version = None
self.commit_string = None self.commit_string = None
def init(self): def init_release(self):
init_service = InitReleaseService(self.version_repo) init_service = InitReleaseService(self.version_repo)
self.release_version = init_service.create_release_version(self.commit_string) self.release_version = init_service.create_release_version(self.commit_string)
self.bump_version = self.release_version.create_bump_version() self.bump_version = self.release_version.create_bump_version()
def prepare(self, version): def prepare_release(self):
git_repository = GitRepository() prepare_release_service = PrepareReleaseService(self.version_repo, self.config_file, self.main_branch)
if self.main_branch not in git_repository.get_current_branch(): if self.release_version is None or self.bump_version is None:
raise Exception('Trying to release while not on main branch') raise Exception('prepare_release was called before init_release')
self.version_repo.write_file(version.get_version_string()) # prepare_release_service.run_tests() # not implemented
git_repository.add_file(self.config_file) prepare_release_service.write_and_commit_release(self.release_version)
match version.release_type: prepare_release_service.write_and_commit_bump(self.bump_version)
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()}')
def tag_and_push(self, version): def tag_and_push(self, version):
git_repository = GitRepository() git_repository = GitRepository()

View file

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

View file

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