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():
|
||||
|
||||
def __init__(self, commit_id, file):
|
||||
|
@ -11,28 +13,23 @@ class InitReleaseService():
|
|||
def __calculate_release_type(self):
|
||||
pass
|
||||
|
||||
def get_version_repo(self):
|
||||
self.version_repo = VersionRepository.get(self.file)
|
||||
|
||||
def get_version_list(self):
|
||||
self.get_version_repo()
|
||||
return self.version_repo.version_list
|
||||
def get_version(self, release_type):
|
||||
self.version_repo = VersionRepository(self.file)
|
||||
return repo.get_version(release_type)
|
||||
|
||||
def create_release_version(self):
|
||||
commit_message = self.read_commit_message(self.commit_id)
|
||||
release_type = self.calculate_release_type(commit_message)
|
||||
version_list = self.get_version_list()
|
||||
|
||||
release_version = Version.create_release_version(version_list, release_type)
|
||||
self.version_repo.write_file(release_version.get_version_string())
|
||||
version = self.get_version(release_type).create_release_version()
|
||||
|
||||
self.version_repo.write_file(version.get_version_string())
|
||||
|
||||
def create_bump_version(self):
|
||||
if self.version_repo == None:
|
||||
raise Exception('VersionRepo was not created. Did you run create_lease_version()?')
|
||||
version_list = self.get_version_list()
|
||||
|
||||
bump_version = Version.create_bump_version(version_list)
|
||||
self.version_repo.write_file(bump_version.get_version_string())
|
||||
version = self.get_version(ReleaseType.BUMP).create_bump_version()
|
||||
|
||||
self.version_repo.write_file(version.get_version_string())
|
||||
|
||||
|
||||
|
||||
|
|
30
version.py
30
version.py
|
@ -7,11 +7,11 @@ class Version():
|
|||
self.version_list = version_list
|
||||
self.release_type = release_type
|
||||
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
|
||||
match release_type:
|
||||
match self.release_type:
|
||||
case ReleaseType.BUMP:
|
||||
self.is_snapshot = True
|
||||
self.version_list[ReleaseType.PATCH.value] += 1
|
||||
|
@ -26,24 +26,20 @@ class Version():
|
|||
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
|
||||
|
||||
@classmethod
|
||||
def create_release_version(cls, version_list, release_type):
|
||||
inst = cls(version_list, release_type)
|
||||
if release_type == ReleaseType.PATCH:
|
||||
inst.is_snapshot = False
|
||||
|
||||
def create_release_version(self):
|
||||
if self.release_type == ReleaseType.PATCH:
|
||||
self.is_snapshot = False
|
||||
else:
|
||||
inst.increment(release_type)
|
||||
return inst
|
||||
|
||||
@classmethod
|
||||
def create_bump_version(cls, version_list):
|
||||
inst = cls(version_list, ReleaseType.BUMP)
|
||||
inst.increment(release_type)
|
||||
return inst
|
||||
self.increment(release_type)
|
||||
|
||||
def create_bump_version(self):
|
||||
self.increment(ReleaseType.BUMP)
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
from file_handlers import FileHandler
|
||||
from version import Version
|
||||
|
||||
class VersionRepository():
|
||||
|
||||
def __init__(self, file):
|
||||
self.file = file
|
||||
self.file_handler = None
|
||||
self.version_list = None
|
||||
self.is_snapshot = None
|
||||
self.file_handler = None
|
||||
|
||||
def load_file(self):
|
||||
self.file_handler = FileHandler.from_file_path(self.file)
|
||||
return self.file_handler
|
||||
return file_handler
|
||||
|
||||
def write_file(self, version_string):
|
||||
if self.file_handler is None:
|
||||
|
@ -23,16 +22,10 @@ class VersionRepository():
|
|||
def parse_file(self, file_handler):
|
||||
version_list, is_snapshot = file_handler.parse()
|
||||
return version_list, is_snapshot
|
||||
|
||||
def get_version(self, release_type):
|
||||
|
||||
@classmethod
|
||||
def get(cls, file):
|
||||
inst = cls(file)
|
||||
self.file_handler = self.load_file(self.file)
|
||||
version_list, is_snapshot = self.parse_file(file_handler)
|
||||
|
||||
file_handler = inst.load_file()
|
||||
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
|
||||
return Version(version_list, release_type)
|
||||
|
|
Loading…
Reference in a new issue