Refactor version variable

Avoid ambiguous variable names.
We are handling a version list and a version string.
This commit is contained in:
erik 2023-02-20 13:47:14 +01:00
parent 88c3acb73c
commit ecdea88a6b
3 changed files with 16 additions and 16 deletions

View file

@ -13,12 +13,12 @@ class InitReleaseService():
def get_version(self):
version_repo = VersionRepository.get_current_version(self.file)
version_repo = VersionRepository.get(self.file)
commit_message = self.read_commit_message(self.commit_id)
release_type = self.calculate_release_type(commit_message)
release_version = create_release_version(version_repo.version ,release_type)
bump_version = create_bump_version(version_repo.version,release_type)
release_version = create_release_version(version_repo.version_list, release_type)
bump_version = create_bump_version(version_repo.version_list, release_type)
release_and_bump_version = tuple(release_version, bump_version)

View file

@ -22,8 +22,8 @@ class ReleaseLevel(Enum):
class Version():
def __init__(self, version, is_snapshot):
self.version = version
def __init__(self, version_list, is_snapshot):
self.version_list = version_list
self.is_snapshot = is_snapshot
def increment(self, level: ReleaseLevel):
@ -41,8 +41,8 @@ class Version():
self.version[ReleaseLevel.MINOR.value] = 0
self.version[ReleaseLevel.MAJOR.value] += 1
def get(self) -> str:
version_string = ".".join([str(x) for x in self.version])
def get_version_string(self) -> str:
version_string = ".".join([str(x) for x in self.version_list])
if self.is_snapshot:
version_string += "-SNAPSHOT"
return version_string

View file

@ -5,33 +5,33 @@ class VersionRepository():
def __init__(self, file):
self.file = file
self.file_handler = None
self.version = None
self.version_list = None
self.is_snapshot = None
def load_file(self):
self.file_handler = FileHandler.from_file_path(self.file)
return file_handler
def write_file(self):
def write_file(self, version_string):
if self.file_handler is None:
raise Exception('Version was not created by load_file method.')
if self.version is None or self.is_snapshot is None:
if self.version_list is None or self.is_snapshot is None:
raise Exception('Version or is_snapshot attribute not set.')
else:
self.file_handler.write(self.version)
self.file_handler.write(version_string)
def parse_file(self, file_handler):
version, is_snapshot = file_handler.parse()
return version, is_snapshot
version_list, is_snapshot = file_handler.parse()
return version_list, is_snapshot
@classmethod
def get_current_version(cls, file):
def get(cls, file) -> VersionRepository:
inst = cls(file)
file_handler= inst.load_file(file)
version, is_snapshot = inst.parse_file(file_handler)
version_list, is_snapshot = inst.parse_file(file_handler)
inst.version = version
inst.version_list = version
inst.is_snapshot = is_snapshot
inst.file_handler = file_handler