From 07cf837ac6e2f0b6617eab3967779f080c9ddea7 Mon Sep 17 00:00:00 2001 From: bom Date: Fri, 17 Nov 2023 15:00:33 +0100 Subject: [PATCH] Simplify set/get version functions --- .../python/ddadevops/domain/build_file.py | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/src/main/python/ddadevops/domain/build_file.py b/src/main/python/ddadevops/domain/build_file.py index 76cb044..c1dbbf5 100644 --- a/src/main/python/ddadevops/domain/build_file.py +++ b/src/main/python/ddadevops/domain/build_file.py @@ -62,11 +62,7 @@ class BuildFile(Validateable): match build_file_type: case BuildFileType.JS: version_str = json.loads(self.content)["version"] - case BuildFileType.JAVA_GRADLE: - version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version") - case BuildFileType.PYTHON: - version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version") - case BuildFileType.JAVA_CLOJURE: + case BuildFileType.JAVA_GRADLE | BuildFileType.PYTHON | BuildFileType.JAVA_CLOJURE: version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version") except: raise RuntimeError(f"Version not found in file {self.file_path}") @@ -88,23 +84,7 @@ class BuildFile(Validateable): json_data = json.loads(self.content) json_data["version"] = new_version.to_string() self.content = json.dumps(json_data, indent=4) - case BuildFileType.JAVA_GRADLE: - substitute = re.sub( - self.__get_file_type_regex_str(build_file_type), - fr'\g"{new_version.to_string()}"', - self.content, - 1, - ) - self.content = substitute - case BuildFileType.PYTHON: - substitute = re.sub( - self.__get_file_type_regex_str(build_file_type), - fr'\g"{new_version.to_string()}"', - self.content, - 1, - ) - self.content = substitute - case BuildFileType.JAVA_CLOJURE: + case BuildFileType.JAVA_GRADLE | BuildFileType.PYTHON | BuildFileType.JAVA_CLOJURE: substitute = re.sub( self.__get_file_type_regex_str(build_file_type), fr'\g"{new_version.to_string()}"',