Pass VersionRepo to InitReleaseService
Update Tests.
This commit is contained in:
parent
1d2cb7882e
commit
821e06f82a
2 changed files with 40 additions and 20 deletions
40
services.py
40
services.py
|
@ -1,12 +1,14 @@
|
||||||
from version_repository import VersionRepository
|
from version_repository import VersionRepository
|
||||||
from release_type import ReleaseType
|
from release_type import ReleaseType
|
||||||
from git_repository import GitRepository
|
from git_repository import GitRepository
|
||||||
|
from version import Version
|
||||||
|
|
||||||
class InitReleaseService():
|
class InitReleaseService():
|
||||||
|
|
||||||
def __init__(self, file):
|
def __init__(self, version_repo: VersionRepository):
|
||||||
self.file = file
|
if version_repo is None:
|
||||||
self.version_repo = None
|
raise Exception('VersionRepo was not created. Did you run create_release_version()?')
|
||||||
|
self.version_repo = version_repo
|
||||||
|
|
||||||
def __calculate_release_type(self, commit_string = None):
|
def __calculate_release_type(self, commit_string = None):
|
||||||
if commit_string is None:
|
if commit_string is None:
|
||||||
|
@ -15,26 +17,42 @@ class InitReleaseService():
|
||||||
return GitRepository.create_from_commit_string(commit_string).get_release_type_from_latest_commit()
|
return GitRepository.create_from_commit_string(commit_string).get_release_type_from_latest_commit()
|
||||||
|
|
||||||
def get_version(self, release_type):
|
def get_version(self, release_type):
|
||||||
self.version_repo = VersionRepository(self.file)
|
|
||||||
return self.version_repo.get_version(release_type)
|
return self.version_repo.get_version(release_type)
|
||||||
|
|
||||||
def create_release_version(self, commit_string = None):
|
def create_release_version(self, commit_string = None):
|
||||||
release_type = self.__calculate_release_type(commit_string)
|
release_type = self.__calculate_release_type(commit_string)
|
||||||
version = self.get_version(release_type).create_release_version()
|
version = self.get_version(release_type).create_release_version()
|
||||||
|
return version
|
||||||
self.version_repo.write_file(version.get_version_string())
|
|
||||||
|
|
||||||
def create_bump_version(self):
|
def create_bump_version(self):
|
||||||
if self.version_repo == None:
|
|
||||||
raise Exception('VersionRepo was not created. Did you run create_release_version()?')
|
|
||||||
version = self.get_version(ReleaseType.BUMP).create_bump_version()
|
version = self.get_version(ReleaseType.BUMP).create_bump_version()
|
||||||
|
return version
|
||||||
self.version_repo.write_file(version.get_version_string())
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PrepareReleaseService():
|
class PrepareReleaseService():
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.version_repo
|
||||||
|
pass
|
||||||
|
|
||||||
|
def run_tests(self): # maybe auto?
|
||||||
|
pass
|
||||||
|
|
||||||
|
def prepare_release(self, version: Version):
|
||||||
|
# self.version_repo.write_file(version.get_version_string()) # side effect
|
||||||
|
pass
|
||||||
|
|
||||||
|
def prepare_bump(self, version: Version):
|
||||||
|
# self.version_repo.write_file(version.get_version_string()) # side effect
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# write
|
||||||
|
|
||||||
|
|
||||||
|
# add
|
||||||
|
# commit
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class TagAndPushReleaseService():
|
class TagAndPushReleaseService():
|
||||||
|
|
|
@ -19,6 +19,7 @@ sys.path.append(parent)
|
||||||
|
|
||||||
from services import InitReleaseService
|
from services import InitReleaseService
|
||||||
from release_type import ReleaseType
|
from release_type import ReleaseType
|
||||||
|
from version_repository import VersionRepository
|
||||||
|
|
||||||
def test_init_release_service(tmp_path):
|
def test_init_release_service(tmp_path):
|
||||||
# init
|
# init
|
||||||
|
@ -29,11 +30,12 @@ def test_init_release_service(tmp_path):
|
||||||
f = tmp_path / file_name
|
f = tmp_path / file_name
|
||||||
f.write_text(contents)
|
f.write_text(contents)
|
||||||
|
|
||||||
release_service = InitReleaseService(f)
|
repo = VersionRepository(f)
|
||||||
release_service.create_release_version(commit_string='Release MINOR')
|
release_service = InitReleaseService(repo)
|
||||||
|
version = release_service.create_release_version(commit_string='Release MINOR')
|
||||||
|
|
||||||
assert '"version": "123.124.0"' in f.read_text()
|
assert "123.124.0" in version.get_version_string()
|
||||||
|
|
||||||
release_service.create_bump_version()
|
version = release_service.create_bump_version()
|
||||||
|
|
||||||
assert '"version": "123.124.1-SNAPSHOT"' in f.read_text()
|
assert "123.123.457-SNAPSHOT" in version.get_version_string()
|
Loading…
Reference in a new issue