Compare commits
No commits in common. "d5d8b8e7e1cc82bcef335ccc838de7ee1ece3318" and "58e6473747fcb72198aa6965f8f5e7f5d6d65a62" have entirely different histories.
d5d8b8e7e1
...
58e6473747
2 changed files with 18 additions and 46 deletions
|
@ -192,46 +192,42 @@ class SystemAPI():
|
||||||
class GitApi():
|
class GitApi():
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.system_api = SystemAPI()
|
self.system_repository = SystemAPI()
|
||||||
|
|
||||||
def get_latest_n_commits(self, n: int):
|
def get_latest_n_commits(self, n: int):
|
||||||
self.system_api.run_checked(
|
self.system_repository.run_checked(
|
||||||
'git', 'log', '--oneline', '--format="%s %b"', f'-n {n}')
|
'git', 'log', '--oneline', '--format="%s %b"', f'-n {n}')
|
||||||
return self.system_api.stdout
|
return self.system_repository.stdout
|
||||||
|
|
||||||
def get_latest_commit(self):
|
def get_latest_commit(self):
|
||||||
output = self.get_latest_n_commits(1)
|
output = self.get_latest_n_commits(1)
|
||||||
return " ".join(output)
|
return " ".join(output)
|
||||||
|
|
||||||
def tag_annotated(self, annotation: str, message: str, count: int):
|
def tag_annotated(self, annotation: str, message: str, count: int):
|
||||||
self.system_api.run_checked(
|
self.system_repository.run_checked(
|
||||||
'git', 'tag', '-a', annotation, '-m', message, f'HEAD~{count}')
|
'git', 'tag', '-a', annotation, '-m', message, f'HEAD~{count}')
|
||||||
return self.system_api.stdout
|
return self.system_repository.stdout
|
||||||
|
|
||||||
def get_latest_tag(self):
|
|
||||||
self.system_api.run_checked('git', 'describe', '--tags', '--abbrev=0')
|
|
||||||
return self.system_api.stdout
|
|
||||||
|
|
||||||
def get_current_branch(self):
|
def get_current_branch(self):
|
||||||
self.system_api.run_checked('git', 'branch', '--show-current')
|
self.system_repository.run_checked('git', 'branch', '--show-current')
|
||||||
return ''.join(self.system_api.stdout).rstrip()
|
return ''.join(self.system_repository.stdout).rstrip()
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
self.system_api.run_checked('git', 'init')
|
self.system_repository.run_checked('git', 'init')
|
||||||
|
|
||||||
def add_file(self, file_path: Path):
|
def add_file(self, file_path: Path):
|
||||||
self.system_api.run_checked('git', 'add', file_path)
|
self.system_repository.run_checked('git', 'add', file_path)
|
||||||
return self.system_api.stdout
|
return self.system_repository.stdout
|
||||||
|
|
||||||
def commit(self, commit_message: str):
|
def commit(self, commit_message: str):
|
||||||
self.system_api.run_checked(
|
self.system_repository.run_checked(
|
||||||
'git', 'commit', '-m', commit_message)
|
'git', 'commit', '-m', commit_message)
|
||||||
return self.system_api.stdout
|
return self.system_repository.stdout
|
||||||
|
|
||||||
def push(self):
|
def push(self):
|
||||||
self.system_api.run_checked('git', 'push')
|
self.system_repository.run_checked('git', 'push')
|
||||||
return self.system_api.stdout
|
return self.system_repository.stdout
|
||||||
|
|
||||||
def checkout(self, branch: str):
|
def checkout(self, branch: str):
|
||||||
self.system_api.run_checked('git', 'checkout', branch)
|
self.system_repository.run_checked('git', 'checkout', branch)
|
||||||
return self.system_api.stdout
|
return self.system_repository.stdout
|
||||||
|
|
|
@ -18,7 +18,8 @@ sys.path.append(parent)
|
||||||
# now we can import the module in the parent
|
# now we can import the module in the parent
|
||||||
# directory.
|
# directory.
|
||||||
|
|
||||||
from services import PrepareReleaseService, TagAndPushReleaseService
|
from services import PrepareReleaseService
|
||||||
|
from domain import ReleaseType
|
||||||
from infrastructure import VersionRepository, ReleaseRepository, ReleaseTypeRepository
|
from infrastructure import VersionRepository, ReleaseRepository, ReleaseTypeRepository
|
||||||
from infrastructure_api import GitApi
|
from infrastructure_api import GitApi
|
||||||
|
|
||||||
|
@ -52,28 +53,3 @@ def test_prepare_release_service(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
||||||
latest_commit = git_api.get_latest_commit()
|
latest_commit = git_api.get_latest_commit()
|
||||||
|
|
||||||
assert '"Version bump "\n' in latest_commit
|
assert '"Version bump "\n' in latest_commit
|
||||||
|
|
||||||
def test_tag_and_push_release_service(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
|
||||||
# init
|
|
||||||
file_name = 'config.json'
|
|
||||||
with open(f'test/resources/{file_name}', 'r') as json_file:
|
|
||||||
contents = json_file.read()
|
|
||||||
f = tmp_path / file_name
|
|
||||||
f.write_text(contents)
|
|
||||||
change_test_dir(tmp_path, monkeypatch) # change the context of the script execution to tmp_path
|
|
||||||
|
|
||||||
git_api = GitApi()
|
|
||||||
git_api.init()
|
|
||||||
git_api.add_file(file_name)
|
|
||||||
git_api.commit("MINOR release")
|
|
||||||
|
|
||||||
repo = ReleaseRepository(VersionRepository(f), ReleaseTypeRepository(GitApi()), 'main')
|
|
||||||
|
|
||||||
prepare_release_service = PrepareReleaseService(repo)
|
|
||||||
prepare_release_service.main_branch = "main"
|
|
||||||
prepare_release_service.write_and_commit_release()
|
|
||||||
|
|
||||||
tag_and_push_release_service = TagAndPushReleaseService(git_api)
|
|
||||||
tag_and_push_release_service.tag_release(repo.get_release())
|
|
||||||
|
|
||||||
assert 'v123.124.0\n' in git_api.get_latest_tag()
|
|
||||||
|
|
Loading…
Reference in a new issue