From 167eec4620fb673dda94e6236625991da3158825 Mon Sep 17 00:00:00 2001 From: bom Date: Wed, 22 Feb 2023 10:57:24 +0100 Subject: [PATCH] Make services testable --- services.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/services.py b/services.py index 8da851d..37445b2 100644 --- a/services.py +++ b/services.py @@ -4,28 +4,29 @@ from git_repository import GitRepository class InitReleaseService(): - def __init__(self, commit_id, file): - self.commit_id = commit_id + def __init__(self, file): self.file = file self.version_repo = None - def __calculate_release_type(self): - return GitRepository().get_release_type_from_latest_commit() + 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, release_type): self.version_repo = VersionRepository(self.file) return self.version_repo.get_version(release_type) - def create_release_version(self): - commit_message = self.read_commit_message(self.commit_id) - release_type = self.__calculate_release_type(commit_message) + def create_release_version(self, commit_string = None): + release_type = self.__calculate_release_type(commit_string) version = self.get_version(release_type).create_release_version() self.version_repo.write_file(version.get_version_string()) def create_bump_version(self): if self.version_repo == None: - raise Exception('VersionRepo was not created. Did you run create_lease_version()?') + raise Exception('VersionRepo was not created. Did you run create_release_version()?') version = self.get_version(ReleaseType.BUMP).create_bump_version() self.version_repo.write_file(version.get_version_string())