9
9
import warnings
10
10
from inspect import signature
11
11
from types import ModuleType
12
- from typing import Any , Callable , Dict , List , Literal , Mapping , Optional , Set , Union
12
+ from typing import Any , Callable , Literal , Mapping , Optional
13
13
from urllib .parse import ParseResult , urlparse
14
14
15
15
from pydantic import BaseModel , EmailStr , Field , PrivateAttr , root_validator , validator
@@ -30,13 +30,13 @@ class Action(YamlModel):
30
30
whiteboard_tag : str
31
31
module : str = "jbi.actions.default"
32
32
# TODO: Remove the tbd literal option when all actions have contact info # pylint: disable=fixme
33
- contact : Union [ EmailStr , List [EmailStr ], Literal ["tbd" ] ]
33
+ contact : EmailStr | list [EmailStr ] | Literal ["tbd" ]
34
34
description : str
35
35
enabled : bool = False
36
36
allow_private : bool = False
37
37
parameters : dict = {}
38
38
_caller : Callable = PrivateAttr (default = None )
39
- _required_jira_permissions : Set [str ] = PrivateAttr (default = None )
39
+ _required_jira_permissions : set [str ] = PrivateAttr (default = None )
40
40
41
41
@property
42
42
def caller (self ) -> Callable :
@@ -48,7 +48,7 @@ def caller(self) -> Callable:
48
48
return self ._caller
49
49
50
50
@property
51
- def required_jira_permissions (self ) -> Set [str ]:
51
+ def required_jira_permissions (self ) -> set [str ]:
52
52
"""Return the required Jira permissions for this action to be executed."""
53
53
if not self ._required_jira_permissions :
54
54
action_module : ModuleType = importlib .import_module (self .module )
@@ -61,7 +61,7 @@ def validate_action_config(cls, values): # pylint: disable=no-self-argument
61
61
"""Validate action: exists, has init function, and has expected params"""
62
62
try :
63
63
module : str = values ["module" ] # type: ignore
64
- action_parameters : Optional [Dict [str , Any ]] = values ["parameters" ]
64
+ action_parameters : Optional [dict [str , Any ]] = values ["parameters" ]
65
65
action_module : ModuleType = importlib .import_module (module )
66
66
if not action_module :
67
67
raise TypeError ("Module is not found." )
@@ -81,7 +81,7 @@ class Actions(YamlModel):
81
81
Actions is the container model for the list of actions in the configuration file
82
82
"""
83
83
84
- __root__ : List [Action ] = Field (..., min_items = 1 )
84
+ __root__ : list [Action ] = Field (..., min_items = 1 )
85
85
86
86
@functools .cached_property
87
87
def by_tag (self ) -> Mapping [str , Action ]:
@@ -102,7 +102,7 @@ def get(self, tag: Optional[str]) -> Optional[Action]:
102
102
return self .by_tag .get (tag .lower ()) if tag else None
103
103
104
104
@functools .cached_property
105
- def configured_jira_projects_keys (self ) -> Set [str ]:
105
+ def configured_jira_projects_keys (self ) -> set [str ]:
106
106
"""Return the list of Jira project keys from all configured actions"""
107
107
return {
108
108
action .parameters ["jira_project_key" ]
@@ -112,7 +112,7 @@ def configured_jira_projects_keys(self) -> Set[str]:
112
112
113
113
@validator ("__root__" )
114
114
def validate_actions ( # pylint: disable=no-self-argument
115
- cls , actions : List [Action ]
115
+ cls , actions : list [Action ]
116
116
):
117
117
"""
118
118
Inspect the list of actions:
@@ -160,11 +160,11 @@ class BugzillaWebhookEvent(BaseModel):
160
160
action : str
161
161
time : Optional [datetime .datetime ]
162
162
user : Optional [BugzillaWebhookUser ]
163
- changes : Optional [List [BugzillaWebhookEventChange ]]
163
+ changes : Optional [list [BugzillaWebhookEventChange ]]
164
164
target : Optional [str ]
165
165
routing_key : Optional [str ]
166
166
167
- def changed_fields (self ) -> Optional [List [str ]]:
167
+ def changed_fields (self ) -> Optional [list [str ]]:
168
168
"""Returns the names of changed fields in a bug"""
169
169
if self .changes :
170
170
return [c .field for c in self .changes ]
@@ -184,7 +184,7 @@ class BugzillaWebhookAttachment(BaseModel):
184
184
creation_time : Optional [datetime .datetime ]
185
185
description : Optional [str ]
186
186
file_name : Optional [str ]
187
- flags : Optional [List ]
187
+ flags : Optional [list ]
188
188
id : int
189
189
is_obsolete : Optional [bool ]
190
190
is_patch : Optional [bool ]
@@ -211,34 +211,34 @@ class BugzillaBug(BaseModel):
211
211
product : Optional [str ]
212
212
component : Optional [str ]
213
213
whiteboard : Optional [str ]
214
- keywords : Optional [List ]
215
- flags : Optional [List ]
216
- groups : Optional [List ]
214
+ keywords : Optional [list ]
215
+ flags : Optional [list ]
216
+ groups : Optional [list ]
217
217
status : Optional [str ]
218
218
resolution : Optional [str ]
219
- see_also : Optional [List ]
219
+ see_also : Optional [list ]
220
220
summary : Optional [str ]
221
221
severity : Optional [str ]
222
222
priority : Optional [str ]
223
223
creator : Optional [str ]
224
224
assigned_to : Optional [str ]
225
225
comment : Optional [BugzillaWebhookComment ]
226
226
227
- def get_whiteboard_as_list (self ) -> List [str ]:
227
+ def get_whiteboard_as_list (self ) -> list [str ]:
228
228
"""Convert string whiteboard into list, splitting on ']' and removing '['."""
229
229
if self .whiteboard is not None :
230
230
split_list = self .whiteboard .replace ("[" , "" ).split ("]" )
231
231
return [x .strip () for x in split_list if x not in ["" , " " ]]
232
232
return []
233
233
234
- def get_whiteboard_with_brackets_as_list (self ) -> List [str ]:
234
+ def get_whiteboard_with_brackets_as_list (self ) -> list [str ]:
235
235
"""Convert string whiteboard into list, splitting on ']' and removing '['; then re-adding."""
236
236
wb_list = self .get_whiteboard_as_list ()
237
237
if wb_list is not None and len (wb_list ) > 0 :
238
238
return [f"[{ element } ]" for element in wb_list ]
239
239
return []
240
240
241
- def get_jira_labels (self ) -> List [str ]:
241
+ def get_jira_labels (self ) -> list [str ]:
242
242
"""
243
243
whiteboard labels are added as a convenience for users to search in jira;
244
244
bugzilla is an expected label in Jira
@@ -251,9 +251,9 @@ def get_jira_labels(self) -> List[str]:
251
251
252
252
return ["bugzilla" ] + wb_list + wb_bracket_list
253
253
254
- def get_potential_whiteboard_config_list (self ) -> List [str ]:
254
+ def get_potential_whiteboard_config_list (self ) -> list [str ]:
255
255
"""Get all possible tags from `whiteboard` field"""
256
- converted_list : List = []
256
+ converted_list : list = []
257
257
for whiteboard in self .get_whiteboard_as_list ():
258
258
first_tag = whiteboard .strip ().lower ().split (sep = "-" , maxsplit = 1 )[0 ]
259
259
if first_tag :
@@ -266,7 +266,7 @@ def issue_type(self) -> str:
266
266
type_map : dict = {"enhancement" : "Task" , "task" : "Task" , "defect" : "Bug" }
267
267
return type_map .get (self .type , "Task" )
268
268
269
- def map_as_jira_issue (self ) -> Dict :
269
+ def map_as_jira_issue (self ) -> dict :
270
270
"""Extract bug info as jira issue dictionary"""
271
271
return {
272
272
"summary" : self .summary ,
@@ -304,7 +304,7 @@ def extract_from_see_also(self):
304
304
305
305
def lookup_action (self , actions : Actions ) -> Action :
306
306
"""Find first matching action from bug's whiteboard list"""
307
- tags : List [str ] = self .get_potential_whiteboard_config_list ()
307
+ tags : list [str ] = self .get_potential_whiteboard_config_list ()
308
308
for tag in tags :
309
309
if action := actions .get (tag ):
310
310
return action
@@ -354,10 +354,10 @@ def map_as_comments(
354
354
self ,
355
355
status_log_enabled : bool = True ,
356
356
assignee_log_enabled : bool = True ,
357
- ) -> List [str ]:
357
+ ) -> list [str ]:
358
358
"""Extract update dict and comment list from Webhook Event"""
359
359
360
- comments : List = []
360
+ comments : list = []
361
361
bug : BugzillaBug = self .bug # type: ignore
362
362
363
363
if self .event .changes :
@@ -396,5 +396,5 @@ def bugzilla_object(self) -> BugzillaBug:
396
396
class BugzillaApiResponse (BaseModel ):
397
397
"""Bugzilla Response Object"""
398
398
399
- faults : Optional [List ]
400
- bugs : Optional [List [BugzillaBug ]]
399
+ faults : Optional [list ]
400
+ bugs : Optional [list [BugzillaBug ]]
0 commit comments