Refactor for code consistency
This commit is contained in:
parent
fce565d2d5
commit
6883435248
3 changed files with 32 additions and 46 deletions
25
services.py
25
services.py
|
@ -1,3 +1,5 @@
|
||||||
|
import version_repository
|
||||||
|
import release_type
|
||||||
class InitReleaseService():
|
class InitReleaseService():
|
||||||
|
|
||||||
def __init__(self, commit_id, file):
|
def __init__(self, commit_id, file):
|
||||||
|
@ -11,28 +13,23 @@ class InitReleaseService():
|
||||||
def __calculate_release_type(self):
|
def __calculate_release_type(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_version_repo(self):
|
def get_version(self, release_type):
|
||||||
self.version_repo = VersionRepository.get(self.file)
|
self.version_repo = VersionRepository(self.file)
|
||||||
|
return repo.get_version(release_type)
|
||||||
def get_version_list(self):
|
|
||||||
self.get_version_repo()
|
|
||||||
return self.version_repo.version_list
|
|
||||||
|
|
||||||
def create_release_version(self):
|
def create_release_version(self):
|
||||||
commit_message = self.read_commit_message(self.commit_id)
|
commit_message = self.read_commit_message(self.commit_id)
|
||||||
release_type = self.calculate_release_type(commit_message)
|
release_type = self.calculate_release_type(commit_message)
|
||||||
version_list = self.get_version_list()
|
version = self.get_version(release_type).create_release_version()
|
||||||
|
|
||||||
release_version = Version.create_release_version(version_list, release_type)
|
self.version_repo.write_file(version.get_version_string())
|
||||||
self.version_repo.write_file(release_version.get_version_string())
|
|
||||||
|
|
||||||
def create_bump_version(self):
|
def create_bump_version(self):
|
||||||
if self.version_repo == None:
|
if self.version_repo == None:
|
||||||
raise Exception('VersionRepo was not created. Did you run create_lease_version()?')
|
raise Exception('VersionRepo was not created. Did you run create_lease_version()?')
|
||||||
version_list = self.get_version_list()
|
version = self.get_version(ReleaseType.BUMP).create_bump_version()
|
||||||
|
|
||||||
bump_version = Version.create_bump_version(version_list)
|
self.version_repo.write_file(version.get_version_string())
|
||||||
self.version_repo.write_file(bump_version.get_version_string())
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
30
version.py
30
version.py
|
@ -7,11 +7,11 @@ class Version():
|
||||||
self.version_list = version_list
|
self.version_list = version_list
|
||||||
self.release_type = release_type
|
self.release_type = release_type
|
||||||
self.version_string = None
|
self.version_string = None
|
||||||
self.is_snapshot = None
|
self.is_snapshot = is_snapshot
|
||||||
|
|
||||||
def increment(self, release_type: ReleaseType):
|
def increment(self):
|
||||||
self.is_snapshot = False
|
self.is_snapshot = False
|
||||||
match release_type:
|
match self.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
|
||||||
|
@ -26,24 +26,20 @@ class Version():
|
||||||
self.version_list[ReleaseType.PATCH.value] = 0
|
self.version_list[ReleaseType.PATCH.value] = 0
|
||||||
self.version_list[ReleaseType.MINOR.value] = 0
|
self.version_list[ReleaseType.MINOR.value] = 0
|
||||||
self.version_list[ReleaseType.MAJOR.value] += 1
|
self.version_list[ReleaseType.MAJOR.value] += 1
|
||||||
|
case None
|
||||||
|
raise Exception("Release Type was not set!")
|
||||||
|
|
||||||
def get_version_string(self) -> str:
|
def get_version_string(self) -> str:
|
||||||
self.version_string = ".".join([str(x) for x in self.version_list])
|
self.version_string = ".".join([str(x) for x in self.version_list])
|
||||||
if self.is_snapshot:
|
if self.is_snapshot:
|
||||||
self.version_string += "-SNAPSHOT"
|
self.version_string += "-SNAPSHOT"
|
||||||
return self.version_string
|
return self.version_string
|
||||||
|
|
||||||
@classmethod
|
def create_release_version(self):
|
||||||
def create_release_version(cls, version_list, release_type):
|
if self.release_type == ReleaseType.PATCH:
|
||||||
inst = cls(version_list, release_type)
|
self.is_snapshot = False
|
||||||
if release_type == ReleaseType.PATCH:
|
|
||||||
inst.is_snapshot = False
|
|
||||||
else:
|
else:
|
||||||
inst.increment(release_type)
|
self.increment(release_type)
|
||||||
return inst
|
|
||||||
|
def create_bump_version(self):
|
||||||
@classmethod
|
self.increment(ReleaseType.BUMP)
|
||||||
def create_bump_version(cls, version_list):
|
|
||||||
inst = cls(version_list, ReleaseType.BUMP)
|
|
||||||
inst.increment(release_type)
|
|
||||||
return inst
|
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
from file_handlers import FileHandler
|
from file_handlers import FileHandler
|
||||||
|
from version import Version
|
||||||
|
|
||||||
class VersionRepository():
|
class VersionRepository():
|
||||||
|
|
||||||
def __init__(self, file):
|
def __init__(self, file):
|
||||||
self.file = file
|
self.file = file
|
||||||
self.file_handler = None
|
self.file_handler = None
|
||||||
self.version_list = None
|
|
||||||
self.is_snapshot = None
|
|
||||||
|
|
||||||
def load_file(self):
|
def load_file(self):
|
||||||
self.file_handler = FileHandler.from_file_path(self.file)
|
self.file_handler = FileHandler.from_file_path(self.file)
|
||||||
return self.file_handler
|
return file_handler
|
||||||
|
|
||||||
def write_file(self, version_string):
|
def write_file(self, version_string):
|
||||||
if self.file_handler is None:
|
if self.file_handler is None:
|
||||||
|
@ -23,16 +22,10 @@ class VersionRepository():
|
||||||
def parse_file(self, file_handler):
|
def parse_file(self, file_handler):
|
||||||
version_list, is_snapshot = file_handler.parse()
|
version_list, is_snapshot = file_handler.parse()
|
||||||
return version_list, is_snapshot
|
return version_list, is_snapshot
|
||||||
|
|
||||||
|
def get_version(self, release_type):
|
||||||
|
|
||||||
@classmethod
|
self.file_handler = self.load_file(self.file)
|
||||||
def get(cls, file):
|
version_list, is_snapshot = self.parse_file(file_handler)
|
||||||
inst = cls(file)
|
|
||||||
|
|
||||||
file_handler = inst.load_file()
|
return Version(version_list, release_type)
|
||||||
version_list, is_snapshot = inst.parse_file(file_handler)
|
|
||||||
|
|
||||||
inst.version_list = version_list
|
|
||||||
inst.is_snapshot = is_snapshot
|
|
||||||
inst.file_handler = file_handler
|
|
||||||
|
|
||||||
return inst
|
|
||||||
|
|
Loading…
Reference in a new issue