Skip to content

Commit 3fe5054

Browse files
committed
fixes
1 parent 6f1695c commit 3fe5054

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

keel_telegram_bot/bot/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from keel_telegram_bot.client.approval import Approval
1919
from keel_telegram_bot.client.resource import Resource
2020
from keel_telegram_bot.client.tracked_image import TrackedImage
21-
from keel_telegram_bot.client.types import SemverPolicyType, Provider, Policy, PollSchedule
21+
from keel_telegram_bot.client.types import SemverPolicy, Provider, Policy, PollSchedule, SemverPolicyType
2222
from keel_telegram_bot.config import Config
2323
from keel_telegram_bot.stats import *
2424
from keel_telegram_bot.util import send_message, approval_to_str, resource_to_str, tracked_image_to_str
@@ -178,7 +178,7 @@ def filter_resources_by(resources: List[Resource], glob: str or None, tracked: b
178178
list(map(lambda y: re.search(glob, y), x.images))), resources))
179179

180180
if tracked:
181-
result = list(filter(lambda x: x.policy != SemverPolicyType.NNone, result))
181+
result = list(filter(lambda x: x.policy != SemverPolicy(SemverPolicyType.NNone), result))
182182

183183
# apply limit
184184
result = result[:limit]

keel_telegram_bot/client/types.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,18 @@ def from_value(value: str):
105105
elif value.startswith("regexp:"):
106106
return RegexPolicy(re.compile(value[7:], re.IGNORECASE))
107107
else:
108-
return SemverPolicyType.from_value(value)
108+
return SemverPolicy.from_value(value)
109+
110+
@property
111+
def value(self):
112+
return self.__str__()
109113

110114
@abc.abstractmethod
111115
def __str__(self):
112116
raise NotImplementedError()
113117

114118

115-
class SemverPolicyType(Policy):
119+
class SemverPolicyType(enum.Enum):
116120
"""
117121
Enum for semver policy types
118122
"""
@@ -123,16 +127,14 @@ class SemverPolicyType(Policy):
123127
Patch = "patch"
124128
Force = "force"
125129

126-
@staticmethod
127-
def values() -> ["SemverPolicyType"]:
128-
return [
129-
SemverPolicyType.NNone,
130-
SemverPolicyType.All,
131-
SemverPolicyType.Major,
132-
SemverPolicyType.Minor,
133-
SemverPolicyType.Patch,
134-
SemverPolicyType.Force
135-
]
130+
131+
class SemverPolicy(Policy):
132+
"""
133+
Enum for semver policy types
134+
"""
135+
136+
def __init__(self, policy_type: SemverPolicyType):
137+
self._policy_type = policy_type
136138

137139
@staticmethod
138140
def from_value(value: str):
@@ -141,13 +143,13 @@ def from_value(value: str):
141143
:param value: the value to convert
142144
:return: the enum
143145
"""
144-
for policy in SemverPolicyType.values():
146+
for policy in SemverPolicyType:
145147
if policy.value.lower() == value.lower():
146148
return policy
147-
return SemverPolicyType.NNone
149+
return SemverPolicy(SemverPolicyType.NNone)
148150

149151
def __str__(self):
150-
return self.value
152+
return self._policy_type.__str__()
151153

152154

153155
class GlobPolicy(Policy):

0 commit comments

Comments
 (0)