Simplify set/get version functions

This commit is contained in:
bom 2023-11-17 15:00:33 +01:00
parent 6399a1dfeb
commit 07cf837ac6

View file

@ -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<pre_version>"{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<pre_version>"{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<pre_version>"{new_version.to_string()}"',