From ecdea88a6be013f234753be2cb27ca437eb740e9 Mon Sep 17 00:00:00 2001 From: erik Date: Mon, 20 Feb 2023 13:47:14 +0100 Subject: [PATCH] Refactor version variable Avoid ambiguous variable names. We are handling a version list and a version string. --- services.py | 6 +++--- version.py | 8 ++++---- version_repository.py | 18 +++++++++--------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/services.py b/services.py index 6074e4b..74cfa99 100644 --- a/services.py +++ b/services.py @@ -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) diff --git a/version.py b/version.py index a90a281..c1e4c59 100644 --- a/version.py +++ b/version.py @@ -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 \ No newline at end of file diff --git a/version_repository.py b/version_repository.py index a018e65..28d46ce 100644 --- a/version_repository.py +++ b/version_repository.py @@ -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