Remove release_type as requirement for Version

Require it in functions that actually use it instead
This commit is contained in:
bom 2023-02-23 14:38:54 +01:00
parent 992c72bda3
commit 1ce4bd9c55
4 changed files with 35 additions and 37 deletions

View file

@ -16,20 +16,19 @@ class InitReleaseService():
else:
return GitRepository.create_from_commit_string(commit_string).get_release_type_from_latest_commit()
def get_version(self, release_type):
return self.version_repo.get_version(release_type)
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(release_type).create_release_version()
version = self.get_version().create_release_version(release_type)
return version
def create_bump_version(self):
version = self.get_version(ReleaseType.BUMP).create_bump_version()
version = self.get_version().create_bump_version()
return version
class PrepareReleaseService():
def __init__(self, version_repo: VersionRepository):

View file

@ -22,33 +22,33 @@ from version_repository import VersionRepository
from release_type import ReleaseType
def test_version():
version = Version([1, 2, 3], ReleaseType.SNAPSHOT)
version = Version([1, 2, 3])
version.increment()
version.increment(ReleaseType.SNAPSHOT)
assert version.get_version_string() == "1.2.3-SNAPSHOT"
assert version.version_list == [1, 2, 3]
assert version.is_snapshot
version = Version([1, 2, 3], ReleaseType.BUMP)
version.increment()
version = Version([1, 2, 3])
version.increment(ReleaseType.BUMP)
assert version.get_version_string() == "1.2.4-SNAPSHOT"
assert version.version_list == [1, 2, 4]
assert version.is_snapshot
version = Version([1, 2, 3], ReleaseType.PATCH)
version.increment()
version = Version([1, 2, 3])
version.increment(ReleaseType.PATCH)
assert version.get_version_string() == "1.2.4"
assert version.version_list == [1, 2, 4]
assert not version.is_snapshot
version = Version([1, 2, 3], ReleaseType.MINOR)
version.increment()
version = Version([1, 2, 3])
version.increment(ReleaseType.MINOR)
assert version.get_version_string() == "1.3.0"
assert version.version_list == [1, 3, 0]
assert not version.is_snapshot
version = Version([1, 2, 3], ReleaseType.MAJOR)
version.increment()
version = Version([1, 2, 3])
version.increment(ReleaseType.MAJOR)
assert version.get_version_string() == "2.0.0"
assert version.version_list == [2, 0, 0]
assert not version.is_snapshot
@ -65,8 +65,8 @@ def test_gradle(tmp_path):
# test
repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT)
version = version.create_release_version()
version = repo.get_version()
version = version.create_release_version(ReleaseType.SNAPSHOT)
repo.write_file(version.get_version_string())
# check
@ -83,8 +83,8 @@ def test_json(tmp_path):
# test
repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT)
version = version.create_release_version()
version = repo.get_version()
version = version.create_release_version(ReleaseType.SNAPSHOT)
repo.write_file(version.get_version_string())
# check
@ -101,8 +101,8 @@ def test_clojure(tmp_path):
# test
repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT)
version = version.create_release_version()
version = repo.get_version()
version = version.create_release_version(ReleaseType.SNAPSHOT)
repo.write_file(version.get_version_string())
# check
@ -119,8 +119,8 @@ def test_python(tmp_path):
# test
repo = VersionRepository(f)
version = repo.get_version(ReleaseType.SNAPSHOT)
version = version.create_release_version()
version = repo.get_version()
version = version.create_release_version(ReleaseType.SNAPSHOT)
repo.write_file(version.get_version_string())
# check

View file

@ -3,15 +3,14 @@ from file_handlers import FileHandler
class Version():
def __init__(self, version_list: list, release_type: ReleaseType):
def __init__(self, version_list: list):
self.version_list = version_list
self.release_type = release_type
self.version_string = None
self.is_snapshot = None
def increment(self):
def increment(self, release_type: ReleaseType):
self.is_snapshot = False
match self.release_type:
match release_type:
case ReleaseType.BUMP:
self.is_snapshot = True
self.version_list[ReleaseType.PATCH.value] += 1
@ -35,14 +34,14 @@ class Version():
self.version_string += "-SNAPSHOT"
return self.version_string
def create_release_version(self):
release_version = Version(self.version_list.copy(), self.release_type)
def create_release_version(self, release_type: ReleaseType):
release_version = Version(self.version_list.copy())
release_version.is_snapshot = self.is_snapshot
release_version.increment()
release_version.increment(release_type)
return release_version
def create_bump_version(self):
bump_version = Version(self.version_list.copy(), ReleaseType.BUMP)
bump_version = Version(self.version_list.copy())
bump_version.is_snapshot = self.is_snapshot
bump_version.increment()
bump_version.increment(ReleaseType.BUMP)
return bump_version

View file

@ -21,11 +21,11 @@ class VersionRepository():
version_list, is_snapshot = self.file_handler.parse()
return version_list, is_snapshot
def get_version(self, release_type):
def get_version(self):
self.file_handler = self.load_file()
version_list, is_snapshot = self.parse_file()
version = Version(version_list, release_type)
version = Version(version_list)
version.is_snapshot = is_snapshot
return version