99import warnings
1010from inspect import signature
1111from types import ModuleType
12- from typing import Callable , Literal , Mapping , Optional , TypedDict
12+ from typing import Any , Callable , Literal , Mapping , Optional , TypedDict
1313from urllib .parse import ParseResult , urlparse
1414
1515from pydantic import BaseModel , Extra , Field , PrivateAttr , root_validator , validator
2323JIRA_HOSTNAMES = ("jira" , "atlassian" )
2424
2525
26- class ActionParameters (BaseModel ):
27- """Action parameters"""
28-
29- # For runner
30- jira_project_key : str
31- steps : Optional [dict [str , list [str ]]] = None
32- # For steps
33- status_map : Optional [dict [str , str ]] = None
34- resolution_map : Optional [dict [str , str ]] = None
35- jira_components : Optional [list [str ]] = None
36- sync_whiteboard_labels : bool = True
37-
38-
3926class Action (YamlModel ):
4027 """
4128 Action is the inner model for each action in the configuration file"""
@@ -46,21 +33,21 @@ class Action(YamlModel):
4633 description : str
4734 enabled : bool = True
4835 allow_private : bool = False
49- parameters : ActionParameters
36+ parameters : dict = {}
5037 _caller : Optional [Callable ] = PrivateAttr (default = None )
5138 _required_jira_permissions : set [str ] = PrivateAttr (default = None )
5239
5340 @property
5441 def jira_project_key (self ):
5542 """Return the configured project key."""
56- return self .parameters . jira_project_key
43+ return self .parameters [ " jira_project_key" ]
5744
5845 @property
5946 def caller (self ) -> Callable :
6047 """Return the initialized callable for this action."""
6148 if self ._caller is None :
6249 action_module : ModuleType = importlib .import_module (self .module )
63- initialized : Callable = action_module .init (** self .parameters . dict () ) # type: ignore
50+ initialized : Callable = action_module .init (** self .parameters ) # type: ignore
6451 self ._caller = initialized
6552 return self ._caller
6653
@@ -78,23 +65,18 @@ def validate_action_config(cls, values): # pylint: disable=no-self-argument
7865 """Validate action: exists, has init function, and has expected params"""
7966 try :
8067 module : str = values ["module" ] # type: ignore
81- try :
82- action_parameters = values ["parameters" ].dict ()
83- except KeyError :
84- action_parameters = {}
68+ action_parameters : Optional [dict [str , Any ]] = values ["parameters" ]
8569 action_module : ModuleType = importlib .import_module (module )
8670 if not action_module :
8771 raise TypeError ("Module is not found." )
8872 if not hasattr (action_module , "init" ):
8973 raise TypeError ("Module is missing `init` method." )
9074
91- signature (action_module .init ).bind (** action_parameters )
75+ signature (action_module .init ).bind (** action_parameters ) # type: ignore
9276 except ImportError as exception :
9377 raise ValueError (f"unknown Python module `{ module } `." ) from exception
9478 except (TypeError , AttributeError ) as exception :
95- raise ValueError (
96- f"action '{ module } ' is not properly setup. { exception } "
97- ) from exception
79+ raise ValueError (f"action is not properly setup.{ exception } " ) from exception
9880 return values
9981
10082
@@ -126,7 +108,11 @@ def get(self, tag: Optional[str]) -> Optional[Action]:
126108 @functools .cached_property
127109 def configured_jira_projects_keys (self ) -> set [str ]:
128110 """Return the list of Jira project keys from all configured actions"""
129- return {action .jira_project_key for action in self .__root__ }
111+ return {
112+ action .jira_project_key
113+ for action in self .__root__
114+ if "jira_project_key" in action .parameters
115+ }
130116
131117 @validator ("__root__" )
132118 def validate_actions ( # pylint: disable=no-self-argument
0 commit comments