From 9db91c0a16c40b656af23ef9460e882498f6c94f Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 28 Apr 2023 14:41:37 +0200 Subject: [PATCH] Fix pylint messages for repo --- .../infrastructure/release_mixin/repo.py | 65 ++++++++++--------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/src/main/python/ddadevops/infrastructure/release_mixin/repo.py b/src/main/python/ddadevops/infrastructure/release_mixin/repo.py index 4fd65df..2dab0c1 100644 --- a/src/main/python/ddadevops/infrastructure/release_mixin/repo.py +++ b/src/main/python/ddadevops/infrastructure/release_mixin/repo.py @@ -23,9 +23,8 @@ class VersionRepository: def write_file(self, version_string): if self.file_handler is None: - raise Exception("Version was not created by load_file method.") - else: - self.file_handler.write(version_string) + raise RuntimeError("Version was not created by load_file method.") + self.file_handler.write(version_string) def parse_file(self): version_list, is_snapshot = self.file_handler.parse() @@ -53,29 +52,30 @@ class ReleaseTypeRepository: @classmethod def from_git(cls, git_api: GitApi): - releaseTypeRepo = cls(git_api=git_api) - releaseTypeRepo.get_from_git = True - return releaseTypeRepo + release_type_repo = cls(git_api=git_api) + release_type_repo.get_from_git = True + return release_type_repo @classmethod def from_environment(cls, environment_api: EnvironmentApi): - releaseTypeRepo = cls(environment_api=environment_api) - releaseTypeRepo.get_from_env = True - return releaseTypeRepo + release_type_repo = cls(environment_api=environment_api) + release_type_repo.get_from_env = True + return release_type_repo def __get_release_type_git(self) -> ReleaseType | None: latest_commit = self.git_api.get_latest_commit() - if ReleaseType.MAJOR.name in latest_commit.upper(): - return ReleaseType.MAJOR - elif ReleaseType.MINOR.name in latest_commit.upper(): - return ReleaseType.MINOR - elif ReleaseType.PATCH.name in latest_commit.upper(): - return ReleaseType.PATCH - elif ReleaseType.SNAPSHOT.name in latest_commit.upper(): - return ReleaseType.SNAPSHOT - else: - return None + match latest_commit.upper(): + case ReleaseType.MAJOR.name: + return ReleaseType.MAJOR + case ReleaseType.MINOR.name: + return ReleaseType.MINOR + case ReleaseType.PATCH.name: + return ReleaseType.PATCH + case ReleaseType.SNAPSHOT.name: + return ReleaseType.SNAPSHOT + case _: + return None def __get_release_type_environment(self) -> ReleaseType | None: release_name = self.environment_api.get( @@ -86,24 +86,25 @@ class ReleaseTypeRepository: raise ValueError( "Release Name not found. Is the Environment correctly configured?" ) - elif ReleaseType.MAJOR.name in release_name.upper(): - return ReleaseType.MAJOR - elif ReleaseType.MINOR.name in release_name.upper(): - return ReleaseType.MINOR - elif ReleaseType.PATCH.name in release_name.upper(): - return ReleaseType.PATCH - elif ReleaseType.SNAPSHOT.name in release_name.upper(): - return ReleaseType.SNAPSHOT - else: - return None + + match release_name.upper(): + case ReleaseType.MAJOR.name: + return ReleaseType.MAJOR + case ReleaseType.MINOR.name: + return ReleaseType.MINOR + case ReleaseType.PATCH.name: + return ReleaseType.PATCH + case ReleaseType.SNAPSHOT.name: + return ReleaseType.SNAPSHOT + case _: + return None def get_release_type(self) -> ReleaseType | None: if self.get_from_git: return self.__get_release_type_git() - elif self.get_from_env: + if self.get_from_env: return self.__get_release_type_environment() - else: - raise ValueError("No valid api passed to ReleaseTypeRepository") + raise ValueError("No valid api passed to ReleaseTypeRepository") class ReleaseContextRepository: