Finish refactoring for ExecutionAPI

This commit is contained in:
bom 2023-04-21 14:51:17 +02:00
parent 5fe58e95cd
commit 54f3938088

View file

@ -221,58 +221,49 @@ class GitApi():
self.execution_api = ExecutionApi() self.execution_api = ExecutionApi()
def get_latest_n_commits(self, n: int): def get_latest_n_commits(self, n: int):
self.execution_api.execute( return self.execution_api.execute(
f'git log --oneline --format="%s %b" -n {n}') f'git log --oneline --format="%s %b" -n {n}')
return self.execution_api.stdout
def get_latest_commit(self): def get_latest_commit(self):
output = self.get_latest_n_commits(1) return self.get_latest_n_commits(1)
return " ".join(output)
def tag_annotated(self, annotation: str, message: str, count: int): def tag_annotated(self, annotation: str, message: str, count: int):
self.execution_api.execute( return self.execution_api.execute(
'git', 'tag', '-a', annotation, '-m', message, f'HEAD~{count}') f'git tag -a {annotation} -m {message} HEAD~{count}')
return self.execution_api.stdout
def tag_annotated_second_last(self, annotation: str, message:str): def tag_annotated_second_last(self, annotation: str, message:str):
self.tag_annotated(annotation, message, 1) return self.tag_annotated(annotation, message, 1)
return self.execution_api.stdout
def get_latest_tag(self): def get_latest_tag(self):
self.execution_api.execute('git', 'describe', '--tags', '--abbrev=0') return self.execution_api.execute('git describe --tags --abbrev=0')
return self.execution_api.stdout
def get_current_branch(self): def get_current_branch(self):
self.execution_api.execute('git', 'branch', '--show-current') self.execution_api.execute('git branch --show-current')
return ''.join(self.execution_api.stdout).rstrip() return ''.join(self.execution_api.stdout).rstrip()
def init(self, default_branch: str = "main"): def init(self, default_branch: str = "main"):
self.execution_api.execute('git', 'init', '-b', default_branch) self.execution_api.execute(f'git init')
self.execution_api.execute(f'git checkout -b {default_branch}')
def set_user_config(self, email: str, name: str): def set_user_config(self, email: str, name: str):
self.execution_api.execute('git', 'config', 'user.email', email) self.execution_api.execute(f'git config user.email {email}')
self.execution_api.execute('git', 'config', 'user.name', name) self.execution_api.execute(f'git config user.name {name}')
def add_file(self, file_path: Path): def add_file(self, file_path: Path):
self.execution_api.execute('git', 'add', file_path) return self.execution_api.execute(f'git add {file_path}')
return self.execution_api.stdout
def add_remote(self, origin: str, url: str): def add_remote(self, origin: str, url: str):
self.execution_api.execute('git', 'remote', 'add', origin, url) return self.execution_api.execute(f'git remote add {origin} {url}')
return self.execution_api.stdout
def commit(self, commit_message: str): def commit(self, commit_message: str):
self.execution_api.execute( return self.execution_api.execute(
'git', 'commit', '-m', commit_message) f'git commit -m "{commit_message}"')
return self.execution_api.stdout
def push(self): def push(self):
self.execution_api.execute('git', 'push') return self.execution_api.execute('git push')
return self.execution_api.stdout
def checkout(self, branch: str): def checkout(self, branch: str):
self.execution_api.execute('git', 'checkout', branch) return self.execution_api.execute(f'git checkout {branch}')
return self.execution_api.stdout
class EnvironmentApi(): class EnvironmentApi():