Fix logical error

Using match would always produce None results, as we are matching
a string exactly. Reintroducing more fuzzy "in" logic fixed tests.
This commit is contained in:
erik 2023-05-02 13:23:42 +02:00
parent 8fd243a60d
commit e27db86477

View file

@ -63,41 +63,36 @@ class ReleaseTypeRepository:
return release_type_repo return release_type_repo
def __get_release_type_git(self) -> ReleaseType | None: def __get_release_type_git(self) -> ReleaseType | None:
latest_commit = self.git_api.get_latest_commit() latest_commit = self.git_api.get_latest_commit().upper()
if ReleaseType.MAJOR.name in latest_commit:
match latest_commit.upper(): return ReleaseType.MAJOR
case ReleaseType.MAJOR.name: if ReleaseType.MINOR.name in latest_commit:
return ReleaseType.MAJOR return ReleaseType.MINOR
case ReleaseType.MINOR.name: if ReleaseType.PATCH.name in latest_commit:
return ReleaseType.MINOR return ReleaseType.PATCH
case ReleaseType.PATCH.name: if ReleaseType.SNAPSHOT.name in latest_commit:
return ReleaseType.PATCH return ReleaseType.SNAPSHOT
case ReleaseType.SNAPSHOT.name: return None
return ReleaseType.SNAPSHOT
case _:
return None
def __get_release_type_environment(self) -> ReleaseType | None: def __get_release_type_environment(self) -> ReleaseType | None:
release_name = self.environment_api.get( release_name = self.environment_api.get(
EnvironmentKeys.DDADEVOPS_RELEASE_TYPE.name EnvironmentKeys.DDADEVOPS_RELEASE_TYPE.name
) ).upper()
if release_name is None: if release_name is None:
raise ValueError( raise ValueError(
"Release Name not found. Is the Environment correctly configured?" "Release Name not found. Is the Environment correctly configured?"
) )
match release_name.upper(): if ReleaseType.MAJOR.name in release_name:
case ReleaseType.MAJOR.name: return ReleaseType.MAJOR
return ReleaseType.MAJOR if ReleaseType.MINOR.name in release_name:
case ReleaseType.MINOR.name: return ReleaseType.MINOR
return ReleaseType.MINOR if ReleaseType.PATCH.name in release_name:
case ReleaseType.PATCH.name: return ReleaseType.PATCH
return ReleaseType.PATCH if ReleaseType.SNAPSHOT.name in release_name:
case ReleaseType.SNAPSHOT.name: return ReleaseType.SNAPSHOT
return ReleaseType.SNAPSHOT return None
case _:
return None
def get_release_type(self) -> ReleaseType | None: def get_release_type(self) -> ReleaseType | None:
if self.get_from_git: if self.get_from_git: