Compare commits
2 commits
36df9f486b
...
07cf837ac6
Author | SHA1 | Date | |
---|---|---|---|
07cf837ac6 | |||
6399a1dfeb |
1 changed files with 6 additions and 37 deletions
|
@ -48,11 +48,11 @@ class BuildFile(Validateable):
|
|||
def __get_file_type_regex_str(self, file_type: BuildFileType):
|
||||
match file_type:
|
||||
case BuildFileType.JAVA_GRADLE:
|
||||
return "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?"
|
||||
return r'(?P<pre_version>version\s?=\s?)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT)?)\"'
|
||||
case BuildFileType.PYTHON:
|
||||
return "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?(-dev)?[0-9]*"
|
||||
return r'(?P<pre_version>version\s?=\s?)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT|-dev\d*)?)\"'
|
||||
case BuildFileType.JAVA_CLOJURE:
|
||||
return r'(?P<project>\(defproject\s(\S)*\s)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT)?)\"'
|
||||
return r'(?P<pre_version>\(defproject\s(\S)*\s)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT)?)\"'
|
||||
case _:
|
||||
return ""
|
||||
|
||||
|
@ -62,24 +62,7 @@ class BuildFile(Validateable):
|
|||
match build_file_type:
|
||||
case BuildFileType.JS:
|
||||
version_str = json.loads(self.content)["version"]
|
||||
case BuildFileType.JAVA_GRADLE:
|
||||
# TODO: '\nversion = ' will not parse all ?!
|
||||
version_line = re.search("\nversion = .*", self.content)
|
||||
version_line_group = version_line.group()
|
||||
version_string = re.search(
|
||||
self.__get_file_type_regex_str(build_file_type), version_line_group
|
||||
)
|
||||
version_str = version_string.group()
|
||||
case BuildFileType.PYTHON:
|
||||
# TODO: '\nversion = ' will not parse all ?!
|
||||
version_line = re.search("\nversion = .*\n", self.content)
|
||||
version_line_group = version_line.group()
|
||||
version_string = re.search(
|
||||
self.__get_file_type_regex_str(build_file_type),
|
||||
version_line_group,
|
||||
)
|
||||
version_str = version_string.group()
|
||||
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}")
|
||||
|
@ -101,24 +84,10 @@ 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(
|
||||
f'\nversion = "{self.__get_file_type_regex_str(build_file_type)}"',
|
||||
f'\nversion = "{new_version.to_string()}"',
|
||||
self.content,
|
||||
)
|
||||
self.content = substitute
|
||||
case BuildFileType.PYTHON:
|
||||
substitute = re.sub(
|
||||
f'\nversion = "{self.__get_file_type_regex_str(build_file_type)}"',
|
||||
f'\nversion = "{new_version.to_string()}"',
|
||||
self.content,
|
||||
)
|
||||
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<project>"{new_version.to_string()}"',
|
||||
fr'\g<pre_version>"{new_version.to_string()}"',
|
||||
self.content,
|
||||
1,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue