mob
This commit is contained in:
parent
c6ef13ca7c
commit
975de636ed
5 changed files with 79 additions and 79 deletions
27
domain.py
27
domain.py
|
@ -1,5 +1,11 @@
|
|||
from enum import Enum
|
||||
|
||||
|
||||
class Config():
|
||||
def __init__(self, main_branch):
|
||||
pass
|
||||
|
||||
|
||||
class ReleaseType(Enum):
|
||||
MAJOR = 0
|
||||
MINOR = 1
|
||||
|
@ -10,7 +16,8 @@ class ReleaseType(Enum):
|
|||
|
||||
class Version():
|
||||
|
||||
def __init__(self, version_list: list):
|
||||
def __init__(self, id: Path, version_list: list):
|
||||
self.id = id
|
||||
self.version_list = version_list
|
||||
self.version_string = None
|
||||
self.is_snapshot = None
|
||||
|
@ -55,6 +62,22 @@ class Version():
|
|||
|
||||
|
||||
class Release():
|
||||
def __init__(self, release_type: ReleaseType, version: Version):
|
||||
def __init__(self, release_type: ReleaseType, version: Version, current_branch: str):
|
||||
self.release_type = release_type
|
||||
self.version = version
|
||||
self.current_branch = current_branch
|
||||
|
||||
def release_version(self):
|
||||
return self.version.create_release_version(self.release_type)
|
||||
|
||||
def bump_version(self):
|
||||
return self.version.create_bump_version()
|
||||
|
||||
def validate(self, main_branch):
|
||||
result = []
|
||||
if self.release_type is not None and main_branch != self.current_branch:
|
||||
result.append(f"Releases are allowed only on {main_branch}")
|
||||
return result
|
||||
|
||||
def is_valid(self, main_branch):
|
||||
return self.validate(main_branch).count < 1
|
||||
|
|
|
@ -54,5 +54,5 @@ class ReleaseRepository():
|
|||
self.version_repository = version_repository
|
||||
self.release_type_repository = release_type_repository
|
||||
|
||||
def get_current_release(self) -> Release:
|
||||
def get_release(self) -> Release:
|
||||
return Release(self.release_type_repository.get_release_type(), self.version_repository.get_version())
|
||||
|
|
39
services.py
39
services.py
|
@ -1,43 +1,22 @@
|
|||
from pathlib import Path
|
||||
from infrastructure import VersionRepository, GitRepository
|
||||
from infrastructure import ReleaseRepository
|
||||
from domain import Version, ReleaseType
|
||||
|
||||
|
||||
# Todo: can be removed
|
||||
class InitReleaseService():
|
||||
|
||||
def __init__(self, version_repo: VersionRepository):
|
||||
if version_repo is 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):
|
||||
if commit_string is None:
|
||||
return GitRepository().get_release_type_from_latest_commit()
|
||||
else:
|
||||
return GitRepository.create_from_commit_string(commit_string).get_release_type_from_latest_commit()
|
||||
|
||||
def __init__(self, release_repo: ReleaseRepository):
|
||||
self.release_repo = release_repo
|
||||
|
||||
def get_version(self):
|
||||
return self.version_repo.get_version()
|
||||
|
||||
def create_release_version(self, commit_string = None):
|
||||
release_type = self.__calculate_release_type(commit_string)
|
||||
version = self.get_version().create_release_version(release_type)
|
||||
return version
|
||||
|
||||
def create_bump_version(self):
|
||||
version = self.get_version().create_bump_version()
|
||||
return version
|
||||
return self.release_repo.get_release().version
|
||||
|
||||
|
||||
class PrepareReleaseService():
|
||||
|
||||
def __init__(self, version_repository: VersionRepository, git_repository: GitRepository, config_file: Path, main_branch: str):
|
||||
self.version_repository = version_repository
|
||||
self.git_repository = git_repository
|
||||
self.main_branch = main_branch
|
||||
self.config_file = config_file
|
||||
|
||||
def run_tests(self): # maybe auto?
|
||||
raise NotImplementedError
|
||||
def __init__(self, release_repo: ReleaseRepository):
|
||||
self.release_repo = release_repo
|
||||
|
||||
def __write_and_commit_version(self, version: Version, commit_message: str):
|
||||
if self.main_branch != self.git_repository.get_current_branch():
|
||||
|
|
|
@ -29,49 +29,6 @@ class TestGitApi(GitApi):
|
|||
return self.commit_string
|
||||
|
||||
|
||||
def test_git_repository():
|
||||
|
||||
# init
|
||||
commit_string = "Major bla"
|
||||
repo = GitRepository.create_from_commit_string(commit_string)
|
||||
release_type = repo.get_release_type_from_latest_commit()
|
||||
|
||||
# test
|
||||
assert release_type == ReleaseType.MAJOR
|
||||
|
||||
# init
|
||||
commit_string = "MINOR bla"
|
||||
repo = GitRepository.create_from_commit_string(commit_string)
|
||||
release_type = repo.get_release_type_from_latest_commit()
|
||||
|
||||
# test
|
||||
assert release_type == ReleaseType.MINOR
|
||||
|
||||
# init
|
||||
commit_string = "PATCH bla"
|
||||
repo = GitRepository.create_from_commit_string(commit_string)
|
||||
release_type = repo.get_release_type_from_latest_commit()
|
||||
|
||||
# test
|
||||
assert release_type == ReleaseType.PATCH
|
||||
|
||||
# init
|
||||
commit_string = "SNAPSHOT bla"
|
||||
repo = GitRepository.create_from_commit_string(commit_string)
|
||||
release_type = repo.get_release_type_from_latest_commit()
|
||||
|
||||
# test
|
||||
assert release_type == ReleaseType.SNAPSHOT
|
||||
|
||||
# init
|
||||
commit_string = "bla"
|
||||
repo = GitRepository.create_from_commit_string(commit_string)
|
||||
release_type = repo.get_release_type_from_latest_commit()
|
||||
|
||||
# test
|
||||
assert release_type == None
|
||||
|
||||
|
||||
def test_gradle(tmp_path):
|
||||
# init
|
||||
file_name = 'config.gradle'
|
||||
|
@ -159,12 +116,32 @@ def test_release_repository(tmp_path):
|
|||
|
||||
# test
|
||||
sut = ReleaseRepository(VersionRepository(f), ReleaseTypeRepository(TestGitApi('MINOR test')))
|
||||
release = sut.get_current_release()
|
||||
release = sut.get_release()
|
||||
|
||||
assert release is not None
|
||||
|
||||
assert release.version is not None
|
||||
|
||||
def test_release_type_repository():
|
||||
sut = ReleaseTypeRepository(TestGitApi('MINOR test'))
|
||||
release_type = sut.get_release_type()
|
||||
|
||||
assert release_type is ReleaseType.MINOR
|
||||
|
||||
sut = ReleaseTypeRepository(TestGitApi('MINOR bla'))
|
||||
release_type = sut.get_release_type()
|
||||
assert release_type is ReleaseType.MINOR
|
||||
|
||||
sut = ReleaseTypeRepository(TestGitApi('Major bla'))
|
||||
release_type = sut.get_release_type()
|
||||
assert release_type == ReleaseType.MAJOR
|
||||
|
||||
sut = ReleaseTypeRepository(TestGitApi('PATCH bla'))
|
||||
release_type = sut.get_release_type()
|
||||
assert release_type == ReleaseType.PATCH
|
||||
|
||||
sut = ReleaseTypeRepository(TestGitApi('SNAPSHOT bla'))
|
||||
release_type = sut.get_release_type()
|
||||
assert release_type == ReleaseType.SNAPSHOT
|
||||
|
||||
sut = ReleaseTypeRepository(TestGitApi('bla'))
|
||||
release_type = sut.get_release_type()
|
||||
assert release_type == None
|
||||
|
|
21
test/test_infrastructure_api.py
Normal file
21
test/test_infrastructure_api.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from pathlib import Path
|
||||
import sys
|
||||
import os
|
||||
|
||||
# getting the name of the directory
|
||||
# where the this file is present.
|
||||
current = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
# Getting the parent directory name
|
||||
# where the current directory is present.
|
||||
parent = os.path.dirname(current)
|
||||
|
||||
# adding the parent directory to
|
||||
# the sys.path.
|
||||
sys.path.append(parent)
|
||||
|
||||
# now we can import the module in the parent
|
||||
# directory.
|
||||
|
||||
from infrastructure_api import GitApi
|
||||
|
Loading…
Reference in a new issue