Compare commits
5 commits
e578878b82
...
3bd8497522
Author | SHA1 | Date | |
---|---|---|---|
3bd8497522 | |||
9250d366b9 | |||
e2f562aa8c | |||
fea5720161 | |||
167eec4620 |
5 changed files with 62 additions and 18 deletions
17
services.py
17
services.py
|
@ -4,28 +4,29 @@ from git_repository import GitRepository
|
|||
|
||||
class InitReleaseService():
|
||||
|
||||
def __init__(self, commit_id, file):
|
||||
self.commit_id = commit_id
|
||||
def __init__(self, file):
|
||||
self.file = file
|
||||
self.version_repo = None
|
||||
|
||||
def __calculate_release_type(self):
|
||||
return GitRepository().get_release_type_from_latest_commit()
|
||||
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 get_version(self, release_type):
|
||||
self.version_repo = VersionRepository(self.file)
|
||||
return self.version_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)
|
||||
def create_release_version(self, commit_string = None):
|
||||
release_type = self.__calculate_release_type(commit_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()?')
|
||||
raise Exception('VersionRepo was not created. Did you run create_release_version()?')
|
||||
version = self.get_version(ReleaseType.BUMP).create_bump_version()
|
||||
|
||||
self.version_repo.write_file(version.get_version_string())
|
||||
|
|
|
@ -17,7 +17,7 @@ sys.path.append(parent)
|
|||
# now we can import the module in the parent
|
||||
# directory.
|
||||
|
||||
from git_repository import *
|
||||
from git_repository import GitRepository
|
||||
from release_type import ReleaseType
|
||||
|
||||
def test_git_repository():
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
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 services import InitReleaseService
|
||||
from release_type import ReleaseType
|
||||
|
||||
def test_init_release_service(tmp_path):
|
||||
# init
|
||||
file_name = 'config.json'
|
||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
||||
contents = gradle_file.read()
|
||||
|
||||
f = tmp_path / file_name
|
||||
f.write_text(contents)
|
||||
|
||||
release_service = InitReleaseService(f)
|
||||
release_service.create_release_version(commit_string='Release MINOR')
|
||||
|
||||
assert '"version": "123.124.1"' in f.read_text()
|
||||
|
||||
release_service.create_bump_version()
|
||||
|
||||
assert '"version": "123.124.2-SNAPSHOT"' in f.read_text()
|
|
@ -66,7 +66,7 @@ def test_gradle(tmp_path):
|
|||
# test
|
||||
repo = VersionRepository(f)
|
||||
version = repo.get_version(ReleaseType.SNAPSHOT)
|
||||
version.create_release_version()
|
||||
version = version.create_release_version()
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
|
@ -84,7 +84,7 @@ def test_json(tmp_path):
|
|||
# test
|
||||
repo = VersionRepository(f)
|
||||
version = repo.get_version(ReleaseType.SNAPSHOT)
|
||||
version.create_release_version()
|
||||
version = version.create_release_version()
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
|
@ -102,7 +102,7 @@ def test_clojure(tmp_path):
|
|||
# test
|
||||
repo = VersionRepository(f)
|
||||
version = repo.get_version(ReleaseType.SNAPSHOT)
|
||||
version.create_release_version()
|
||||
version = version.create_release_version()
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
|
@ -120,7 +120,7 @@ def test_python(tmp_path):
|
|||
# test
|
||||
repo = VersionRepository(f)
|
||||
version = repo.get_version(ReleaseType.SNAPSHOT)
|
||||
version.create_release_version()
|
||||
version = version.create_release_version()
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
|
|
14
version.py
14
version.py
|
@ -36,10 +36,14 @@ class Version():
|
|||
return self.version_string
|
||||
|
||||
def create_release_version(self):
|
||||
if self.release_type == ReleaseType.PATCH:
|
||||
self.is_snapshot = False
|
||||
else:
|
||||
self.increment()
|
||||
release_version = Version(self.version_list, self.release_type)
|
||||
release_version.is_snapshot = self.is_snapshot
|
||||
release_version.increment()
|
||||
return release_version
|
||||
|
||||
def create_bump_version(self):
|
||||
self.increment(ReleaseType.BUMP)
|
||||
bump_version = Version(self.version_list, self.release_type)
|
||||
bump_version.is_snapshot = self.is_snapshot
|
||||
bump_version.release_type = ReleaseType.BUMP
|
||||
bump_version.increment()
|
||||
return bump_version
|
||||
|
|
Loading…
Reference in a new issue