|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
import json
|
|
|
|
|
import re
|
|
|
|
|
import subprocess as sub
|
|
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
from typing import Optional
|
|
|
|
|
from pathlib import Path
|
|
|
|
@ -26,7 +25,7 @@ class FileHandler(ABC):
|
|
|
|
|
case '.py':
|
|
|
|
|
file_handler = PythonFileHandler()
|
|
|
|
|
case _:
|
|
|
|
|
raise Exception(
|
|
|
|
|
raise RuntimeError(
|
|
|
|
|
f'The file type "{config_file_type}" is not implemented')
|
|
|
|
|
# TODO: Attribute is only set in classmethod. Should this be initialized outside of this class?
|
|
|
|
|
file_handler.config_file_path = file_path
|
|
|
|
@ -47,7 +46,7 @@ class JsonFileHandler(FileHandler):
|
|
|
|
|
def parse(self) -> tuple[list[int], bool]:
|
|
|
|
|
if self.config_file_path is None:
|
|
|
|
|
raise ValueError("No file name given.")
|
|
|
|
|
with open(self.config_file_path, 'r') as json_file:
|
|
|
|
|
with open(self.config_file_path, 'r', encoding='utf-8') as json_file:
|
|
|
|
|
json_version = json.load(json_file)['version']
|
|
|
|
|
is_snapshot = False
|
|
|
|
|
if '-SNAPSHOT' in json_version:
|
|
|
|
@ -57,7 +56,7 @@ class JsonFileHandler(FileHandler):
|
|
|
|
|
return version, is_snapshot
|
|
|
|
|
|
|
|
|
|
def write(self, version_string):
|
|
|
|
|
with open(self.config_file_path, 'r+') as json_file:
|
|
|
|
|
with open(self.config_file_path, 'r+', encoding='utf-8') as json_file:
|
|
|
|
|
json_data = json.load(json_file)
|
|
|
|
|
json_data['version'] = version_string
|
|
|
|
|
json_file.seek(0)
|
|
|
|
@ -70,7 +69,7 @@ class GradleFileHandler(FileHandler):
|
|
|
|
|
def parse(self) -> tuple[list[int], bool]:
|
|
|
|
|
if self.config_file_path is None:
|
|
|
|
|
raise ValueError("No file name given.")
|
|
|
|
|
with open(self.config_file_path, 'r') as gradle_file:
|
|
|
|
|
with open(self.config_file_path, 'r', encoding='utf-8') as gradle_file:
|
|
|
|
|
contents = gradle_file.read()
|
|
|
|
|
version_line = re.search("\nversion = .*", contents)
|
|
|
|
|
exception = Exception("Version not found in gradle file")
|
|
|
|
@ -94,7 +93,7 @@ class GradleFileHandler(FileHandler):
|
|
|
|
|
return version, is_snapshot
|
|
|
|
|
|
|
|
|
|
def write(self, version_string):
|
|
|
|
|
with open(self.config_file_path, 'r+') as gradle_file:
|
|
|
|
|
with open(self.config_file_path, 'r+', encoding='utf-8') as gradle_file:
|
|
|
|
|
contents = gradle_file.read()
|
|
|
|
|
version_substitute = re.sub(
|
|
|
|
|
'\nversion = "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?"', f'\nversion = "{version_string}"', contents)
|
|
|
|
@ -108,7 +107,7 @@ class PythonFileHandler(FileHandler):
|
|
|
|
|
def parse(self) -> tuple[list[int], bool]:
|
|
|
|
|
if self.config_file_path is None:
|
|
|
|
|
raise ValueError("No file name given.")
|
|
|
|
|
with open(self.config_file_path, 'r') as python_file:
|
|
|
|
|
with open(self.config_file_path, 'r', encoding='utf-8') as python_file:
|
|
|
|
|
contents = python_file.read()
|
|
|
|
|
version_line = re.search("\nversion = .*\n", contents)
|
|
|
|
|
exception = Exception("Version not found in gradle file")
|
|
|
|
@ -132,7 +131,7 @@ class PythonFileHandler(FileHandler):
|
|
|
|
|
return version, is_snapshot
|
|
|
|
|
|
|
|
|
|
def write(self, version_string):
|
|
|
|
|
with open(self.config_file_path, 'r+') as python_file:
|
|
|
|
|
with open(self.config_file_path, 'r+', encoding='utf-8') as python_file:
|
|
|
|
|
contents = python_file.read()
|
|
|
|
|
version_substitute = re.sub(
|
|
|
|
|
'\nversion = "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?"', f'\nversion = "{version_string}"', contents)
|
|
|
|
@ -146,7 +145,7 @@ class ClojureFileHandler(FileHandler):
|
|
|
|
|
def parse(self) -> tuple[list[int], bool]:
|
|
|
|
|
if self.config_file_path is None:
|
|
|
|
|
raise ValueError("No file name given.")
|
|
|
|
|
with open(self.config_file_path, 'r') as clj_file:
|
|
|
|
|
with open(self.config_file_path, 'r', encoding='utf-8') as clj_file:
|
|
|
|
|
contents = clj_file.read()
|
|
|
|
|
version_line = re.search("^\\(defproject .*\n", contents)
|
|
|
|
|
exception = Exception("Version not found in clj file")
|
|
|
|
@ -170,7 +169,7 @@ class ClojureFileHandler(FileHandler):
|
|
|
|
|
return version, is_snapshot
|
|
|
|
|
|
|
|
|
|
def write(self, version_string):
|
|
|
|
|
with open(self.config_file_path, 'r+') as clj_file:
|
|
|
|
|
with open(self.config_file_path, 'r+', encoding='utf-8') as clj_file:
|
|
|
|
|
clj_first = clj_file.readline()
|
|
|
|
|
clj_rest = clj_file.read()
|
|
|
|
|
version_substitute = re.sub(
|
|
|
|
@ -186,6 +185,7 @@ class GitApi():
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.execution_api = ExecutionApi()
|
|
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
|
|
|
|
def get_latest_n_commits(self, n: int):
|
|
|
|
|
return self.execution_api.execute(
|
|
|
|
|
f'git log --oneline --format="%s %b" -n {n}')
|
|
|
|
@ -204,11 +204,10 @@ class GitApi():
|
|
|
|
|
return self.execution_api.execute('git describe --tags --abbrev=0')
|
|
|
|
|
|
|
|
|
|
def get_current_branch(self):
|
|
|
|
|
self.execution_api.execute('git branch --show-current')
|
|
|
|
|
return ''.join(self.execution_api.stdout).rstrip()
|
|
|
|
|
return ''.join(self.execution_api.execute('git branch --show-current')).rstrip()
|
|
|
|
|
|
|
|
|
|
def init(self, default_branch: str = "main"):
|
|
|
|
|
self.execution_api.execute(f'git init')
|
|
|
|
|
self.execution_api.execute('git init')
|
|
|
|
|
self.execution_api.execute(f'git checkout -b {default_branch}')
|
|
|
|
|
|
|
|
|
|
def set_user_config(self, email: str, name: str):
|
|
|
|
|