Remove release_type as requirement for Version
Require it in functions that actually use it instead
This commit is contained in:
parent
992c72bda3
commit
1ce4bd9c55
4 changed files with 35 additions and 37 deletions
|
@ -16,20 +16,19 @@ class InitReleaseService():
|
||||||
else:
|
else:
|
||||||
return GitRepository.create_from_commit_string(commit_string).get_release_type_from_latest_commit()
|
return GitRepository.create_from_commit_string(commit_string).get_release_type_from_latest_commit()
|
||||||
|
|
||||||
def get_version(self, release_type):
|
def get_version(self):
|
||||||
return self.version_repo.get_version(release_type)
|
return self.version_repo.get_version()
|
||||||
|
|
||||||
def create_release_version(self, commit_string = None):
|
def create_release_version(self, commit_string = None):
|
||||||
release_type = self.__calculate_release_type(commit_string)
|
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
|
return version
|
||||||
|
|
||||||
def create_bump_version(self):
|
def create_bump_version(self):
|
||||||
version = self.get_version(ReleaseType.BUMP).create_bump_version()
|
version = self.get_version().create_bump_version()
|
||||||
return version
|
return version
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PrepareReleaseService():
|
class PrepareReleaseService():
|
||||||
|
|
||||||
def __init__(self, version_repo: VersionRepository):
|
def __init__(self, version_repo: VersionRepository):
|
||||||
|
|
|
@ -22,33 +22,33 @@ from version_repository import VersionRepository
|
||||||
from release_type import ReleaseType
|
from release_type import ReleaseType
|
||||||
|
|
||||||
def test_version():
|
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.get_version_string() == "1.2.3-SNAPSHOT"
|
||||||
assert version.version_list == [1, 2, 3]
|
assert version.version_list == [1, 2, 3]
|
||||||
assert version.is_snapshot
|
assert version.is_snapshot
|
||||||
|
|
||||||
version = Version([1, 2, 3], ReleaseType.BUMP)
|
version = Version([1, 2, 3])
|
||||||
version.increment()
|
version.increment(ReleaseType.BUMP)
|
||||||
assert version.get_version_string() == "1.2.4-SNAPSHOT"
|
assert version.get_version_string() == "1.2.4-SNAPSHOT"
|
||||||
assert version.version_list == [1, 2, 4]
|
assert version.version_list == [1, 2, 4]
|
||||||
assert version.is_snapshot
|
assert version.is_snapshot
|
||||||
|
|
||||||
version = Version([1, 2, 3], ReleaseType.PATCH)
|
version = Version([1, 2, 3])
|
||||||
version.increment()
|
version.increment(ReleaseType.PATCH)
|
||||||
assert version.get_version_string() == "1.2.4"
|
assert version.get_version_string() == "1.2.4"
|
||||||
assert version.version_list == [1, 2, 4]
|
assert version.version_list == [1, 2, 4]
|
||||||
assert not version.is_snapshot
|
assert not version.is_snapshot
|
||||||
|
|
||||||
version = Version([1, 2, 3], ReleaseType.MINOR)
|
version = Version([1, 2, 3])
|
||||||
version.increment()
|
version.increment(ReleaseType.MINOR)
|
||||||
assert version.get_version_string() == "1.3.0"
|
assert version.get_version_string() == "1.3.0"
|
||||||
assert version.version_list == [1, 3, 0]
|
assert version.version_list == [1, 3, 0]
|
||||||
assert not version.is_snapshot
|
assert not version.is_snapshot
|
||||||
|
|
||||||
version = Version([1, 2, 3], ReleaseType.MAJOR)
|
version = Version([1, 2, 3])
|
||||||
version.increment()
|
version.increment(ReleaseType.MAJOR)
|
||||||
assert version.get_version_string() == "2.0.0"
|
assert version.get_version_string() == "2.0.0"
|
||||||
assert version.version_list == [2, 0, 0]
|
assert version.version_list == [2, 0, 0]
|
||||||
assert not version.is_snapshot
|
assert not version.is_snapshot
|
||||||
|
@ -65,8 +65,8 @@ def test_gradle(tmp_path):
|
||||||
|
|
||||||
# test
|
# test
|
||||||
repo = VersionRepository(f)
|
repo = VersionRepository(f)
|
||||||
version = repo.get_version(ReleaseType.SNAPSHOT)
|
version = repo.get_version()
|
||||||
version = version.create_release_version()
|
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||||
repo.write_file(version.get_version_string())
|
repo.write_file(version.get_version_string())
|
||||||
|
|
||||||
# check
|
# check
|
||||||
|
@ -83,8 +83,8 @@ def test_json(tmp_path):
|
||||||
|
|
||||||
# test
|
# test
|
||||||
repo = VersionRepository(f)
|
repo = VersionRepository(f)
|
||||||
version = repo.get_version(ReleaseType.SNAPSHOT)
|
version = repo.get_version()
|
||||||
version = version.create_release_version()
|
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||||
repo.write_file(version.get_version_string())
|
repo.write_file(version.get_version_string())
|
||||||
|
|
||||||
# check
|
# check
|
||||||
|
@ -101,8 +101,8 @@ def test_clojure(tmp_path):
|
||||||
|
|
||||||
# test
|
# test
|
||||||
repo = VersionRepository(f)
|
repo = VersionRepository(f)
|
||||||
version = repo.get_version(ReleaseType.SNAPSHOT)
|
version = repo.get_version()
|
||||||
version = version.create_release_version()
|
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||||
repo.write_file(version.get_version_string())
|
repo.write_file(version.get_version_string())
|
||||||
|
|
||||||
# check
|
# check
|
||||||
|
@ -119,8 +119,8 @@ def test_python(tmp_path):
|
||||||
|
|
||||||
# test
|
# test
|
||||||
repo = VersionRepository(f)
|
repo = VersionRepository(f)
|
||||||
version = repo.get_version(ReleaseType.SNAPSHOT)
|
version = repo.get_version()
|
||||||
version = version.create_release_version()
|
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||||
repo.write_file(version.get_version_string())
|
repo.write_file(version.get_version_string())
|
||||||
|
|
||||||
# check
|
# check
|
||||||
|
|
17
version.py
17
version.py
|
@ -3,15 +3,14 @@ from file_handlers import FileHandler
|
||||||
|
|
||||||
class Version():
|
class Version():
|
||||||
|
|
||||||
def __init__(self, version_list: list, release_type: ReleaseType):
|
def __init__(self, version_list: list):
|
||||||
self.version_list = version_list
|
self.version_list = version_list
|
||||||
self.release_type = release_type
|
|
||||||
self.version_string = None
|
self.version_string = None
|
||||||
self.is_snapshot = None
|
self.is_snapshot = None
|
||||||
|
|
||||||
def increment(self):
|
def increment(self, release_type: ReleaseType):
|
||||||
self.is_snapshot = False
|
self.is_snapshot = False
|
||||||
match self.release_type:
|
match release_type:
|
||||||
case ReleaseType.BUMP:
|
case ReleaseType.BUMP:
|
||||||
self.is_snapshot = True
|
self.is_snapshot = True
|
||||||
self.version_list[ReleaseType.PATCH.value] += 1
|
self.version_list[ReleaseType.PATCH.value] += 1
|
||||||
|
@ -35,14 +34,14 @@ class Version():
|
||||||
self.version_string += "-SNAPSHOT"
|
self.version_string += "-SNAPSHOT"
|
||||||
return self.version_string
|
return self.version_string
|
||||||
|
|
||||||
def create_release_version(self):
|
def create_release_version(self, release_type: ReleaseType):
|
||||||
release_version = Version(self.version_list.copy(), self.release_type)
|
release_version = Version(self.version_list.copy())
|
||||||
release_version.is_snapshot = self.is_snapshot
|
release_version.is_snapshot = self.is_snapshot
|
||||||
release_version.increment()
|
release_version.increment(release_type)
|
||||||
return release_version
|
return release_version
|
||||||
|
|
||||||
def create_bump_version(self):
|
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.is_snapshot = self.is_snapshot
|
||||||
bump_version.increment()
|
bump_version.increment(ReleaseType.BUMP)
|
||||||
return bump_version
|
return bump_version
|
||||||
|
|
|
@ -21,11 +21,11 @@ class VersionRepository():
|
||||||
version_list, is_snapshot = self.file_handler.parse()
|
version_list, is_snapshot = self.file_handler.parse()
|
||||||
return version_list, is_snapshot
|
return version_list, is_snapshot
|
||||||
|
|
||||||
def get_version(self, release_type):
|
def get_version(self):
|
||||||
|
|
||||||
self.file_handler = self.load_file()
|
self.file_handler = self.load_file()
|
||||||
version_list, is_snapshot = self.parse_file()
|
version_list, is_snapshot = self.parse_file()
|
||||||
version = Version(version_list, release_type)
|
version = Version(version_list)
|
||||||
version.is_snapshot = is_snapshot
|
version.is_snapshot = is_snapshot
|
||||||
|
|
||||||
return version
|
return version
|
||||||
|
|
Loading…
Reference in a new issue