From fa6beebc4e2e838b9681f6b37d67281c9d9b9458 Mon Sep 17 00:00:00 2001 From: bom Date: Thu, 23 Feb 2023 15:07:22 +0100 Subject: [PATCH] Move commit logic to prepare_release_service --- release_mixin.py | 23 +++++++++-------------- services.py | 35 ++++++++++++++++++----------------- test/test_release_mixin.py | 2 +- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/release_mixin.py b/release_mixin.py index 4b8dc38..b31e838 100644 --- a/release_mixin.py +++ b/release_mixin.py @@ -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() diff --git a/services.py b/services.py index 212f016..04eac74 100644 --- a/services.py +++ b/services.py @@ -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') + + 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): - # self.version_repo.write_file(version.get_version_string()) # side effect - pass + 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 diff --git a/test/test_release_mixin.py b/test/test_release_mixin.py index 4b129c6..67b25a9 100644 --- a/test/test_release_mixin.py +++ b/test/test_release_mixin.py @@ -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