Skip to content

Commit e1ba4cb

Browse files
author
Bryan Sieber
committed
Updates from final comments in PR #1; minor cleanup
1 parent 8c8f0e7 commit e1ba4cb

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

src/jbi/configuration.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def process_actions(action_configuration) -> Dict[str, Dict]:
4343
for yaml_action_key, inner_action_dict in action_configuration.items():
4444
inner_action_dict.setdefault("action", "src.jbi.whiteboard_actions.default")
4545
inner_action_dict.setdefault("enabled", False)
46+
inner_action_dict.setdefault("parameters", {})
4647
validate_action_yaml_jbi_naming(
4748
yaml_action_key=yaml_action_key, action_dict=inner_action_dict
4849
)
@@ -53,24 +54,18 @@ def process_actions(action_configuration) -> Dict[str, Dict]:
5354

5455
def validate_action_yaml_jbi_naming(yaml_action_key, action_dict):
5556
# Validate yaml_action_key == parameters.whiteboard_tag
56-
try:
57-
action_parameters = action_dict.get("parameters")
58-
wb_tag = action_parameters.get("whiteboard_tag")
59-
if yaml_action_key != wb_tag:
60-
raise ConfigError(
61-
f"Expected action key '{wb_tag}', found `{yaml_action_key}."
62-
"(from the `parameters.whiteboard_tag` field)."
63-
)
64-
except (TypeError, AttributeError) as exception:
65-
raise ConfigError("Action is not properly setup.") from exception
57+
wb_tag = action_dict["parameters"].get("whiteboard_tag")
58+
if yaml_action_key != wb_tag:
59+
raise ConfigError(
60+
f"Expected action key '{wb_tag}', found `{yaml_action_key}."
61+
"(from the `parameters.whiteboard_tag` field)."
62+
)
6663

6764

6865
def validate_action_yaml_module(action_dict: Dict[str, Any]):
6966
# Validate action: exists, has init function, and has expected params
7067
try:
7168
action: str = action_dict.get("action") # type: ignore
72-
print(action_dict)
73-
print(action)
7469
action_parameters: Optional[Dict[str, Any]] = action_dict.get("parameters")
7570
action_module: ModuleType = importlib.import_module(action)
7671
if not action_module:

src/jbi/router.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def create_inner_html_table(data: Dict, enable_query: Optional[bool]):
7878
agg_table = ""
7979
header = """
8080
<tr>
81-
<th>Key</th>
81+
<th>Identifier</th>
8282
<th>Action</th>
8383
<th>Contact</th>
8484
<th>Description </th>
@@ -89,12 +89,10 @@ def create_inner_html_table(data: Dict, enable_query: Optional[bool]):
8989
for key, value in data.items():
9090
enabled = value.get("enabled")
9191
if enable_query is None or enabled is enable_query:
92-
parameters = ", ".join(
93-
f"{k}={v}" for k, v in value.get("parameters").items()
94-
)
92+
parameters = ", ".join(f"{k}={v}" for k, v in value["parameters"].items())
9593
per_row = f"""
9694
<tr>
97-
<td class="key">{key}</td>
95+
<td class="identifier">{key}</td>
9896
<td class="action">{value.get("action")}</td>
9997
<td class="contact">{value.get("contact")}</td>
10098
<td class="description">{value.get("description")}</td>

src/jbi/whiteboard_actions/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
## Looking to add a new action?
2-
"actions" are python functions that, once added into `src/jbi/whiteboard_actions/` dir,
2+
"actions" are python modules that, if available in the PYTHONPATH,
33
can be run by updating the `action` attribute of the yaml config file.
44

55
### Create a new action...
66
Let's create a `new_action`!
7-
1. First, add a new python file called "my_team_action" in the `src/jbi/whiteboard_actions/` dir.
7+
1. First, add a new python file called `my_team_action.py` in the `src/jbi/whiteboard_actions/` directory.
88
1. Add the python function `init` to a new "my_team_action" module, let's use the following:
99
```python
1010
def init(whiteboard_tag, jira_project_key, optional_param=42):
1111
return lambda payload, context: print("Hi world!")
1212
```
13-
1. In the above example whiteboard_tag and jira_project_key are required
14-
1. optional_param, which has a default value--is not required to run this action
13+
1. In the above example `whiteboard_tag` and `jira_project_key` parameters are required
14+
1. `optional_param`, which has a default value and is not required to run this action
1515
1. init returns a `__call__`able object that the system calls with the bugzilla request and yaml configuration objects
1616
1. Using `payload` and `context` perform the desired processing!
1717
1. `payload` is bugzilla webhook payload
18-
1. `context` is the full yaml blob as a python dict (if additional context is desired)
18+
1. `parameters` is the yaml section `parameters` as a python dict
1919
1. Use the available service calls from `src/jbi/services.py' (or make new ones)
20-
1. Now the action `src.jbi.whiteboard_actions.my_team_actions` can be added to a configuration.
20+
1. Now the action `src.jbi.whiteboard_actions.my_team_actions` can be added to a configuration yaml under the `action` key.

src/jbi/whiteboard_actions/default.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def __init__(self, **kwargs):
1313
self.whiteboard_tag = kwargs.get("whiteboard_tag")
1414
self.jira_project_key = kwargs.get("jira_project_key")
1515

16-
def __call__(self, payload, context):
16+
def __call__(self, payload, parameters):
1717
# Called from BZ webhook
1818
# Call Jira SDK with project key etc.
1919
print(payload)
20-
print(context)
20+
print(parameters)

0 commit comments

Comments
 (0)