terraformDummyRepo/version.py

45 lines
1.7 KiB
Python

from release_type import ReleaseType
from file_handlers import FileHandler
class Version():
def __init__(self, version_list: list, release_type: ReleaseType):
self.version_list = version_list
self.release_type = release_type
self.version_string = None
self.is_snapshot = is_snapshot
def increment(self):
self.is_snapshot = False
match self.release_type:
case ReleaseType.BUMP:
self.is_snapshot = True
self.version_list[ReleaseType.PATCH.value] += 1
case ReleaseType.SNAPSHOT:
self.is_snapshot = True
case ReleaseType.PATCH:
self.version_list[ReleaseType.PATCH.value] += 1
case ReleaseType.MINOR:
self.version_list[ReleaseType.PATCH.value] = 0
self.version_list[ReleaseType.MINOR.value] += 1
case ReleaseType.MAJOR:
self.version_list[ReleaseType.PATCH.value] = 0
self.version_list[ReleaseType.MINOR.value] = 0
self.version_list[ReleaseType.MAJOR.value] += 1
case None
raise Exception("Release Type was not set!")
def get_version_string(self) -> str:
self.version_string = ".".join([str(x) for x in self.version_list])
if self.is_snapshot:
self.version_string += "-SNAPSHOT"
return self.version_string
def create_release_version(self):
if self.release_type == ReleaseType.PATCH:
self.is_snapshot = False
else:
self.increment(release_type)
def create_bump_version(self):
self.increment(ReleaseType.BUMP)