From 950d76c883d52622ecbf2f5ae4310bd0a753b1e5 Mon Sep 17 00:00:00 2001 From: bom Date: Thu, 2 Mar 2023 16:55:49 +0100 Subject: [PATCH] Add get_latest_tag to GitApi also rename system_repo to system_api --- infrastructure_api.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/infrastructure_api.py b/infrastructure_api.py index 125fb57..bd86de5 100644 --- a/infrastructure_api.py +++ b/infrastructure_api.py @@ -192,42 +192,46 @@ class SystemAPI(): class GitApi(): def __init__(self): - self.system_repository = SystemAPI() + self.system_api = SystemAPI() def get_latest_n_commits(self, n: int): - self.system_repository.run_checked( + self.system_api.run_checked( 'git', 'log', '--oneline', '--format="%s %b"', f'-n {n}') - return self.system_repository.stdout + return self.system_api.stdout def get_latest_commit(self): output = self.get_latest_n_commits(1) return " ".join(output) def tag_annotated(self, annotation: str, message: str, count: int): - self.system_repository.run_checked( + self.system_api.run_checked( 'git', 'tag', '-a', annotation, '-m', message, f'HEAD~{count}') - return self.system_repository.stdout + return self.system_api.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): - self.system_repository.run_checked('git', 'branch', '--show-current') - return ''.join(self.system_repository.stdout).rstrip() + self.system_api.run_checked('git', 'branch', '--show-current') + return ''.join(self.system_api.stdout).rstrip() def init(self): - self.system_repository.run_checked('git', 'init') + self.system_api.run_checked('git', 'init') def add_file(self, file_path: Path): - self.system_repository.run_checked('git', 'add', file_path) - return self.system_repository.stdout + self.system_api.run_checked('git', 'add', file_path) + return self.system_api.stdout def commit(self, commit_message: str): - self.system_repository.run_checked( + self.system_api.run_checked( 'git', 'commit', '-m', commit_message) - return self.system_repository.stdout + return self.system_api.stdout def push(self): - self.system_repository.run_checked('git', 'push') - return self.system_repository.stdout + self.system_api.run_checked('git', 'push') + return self.system_api.stdout def checkout(self, branch: str): - self.system_repository.run_checked('git', 'checkout', branch) - return self.system_repository.stdout + self.system_api.run_checked('git', 'checkout', branch) + return self.system_api.stdout