Skip to content

Commit 8710c87

Browse files
committed
Rename and return a list from lookup_actions
1 parent 6936d49 commit 8710c87

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

jbi/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class RunnerContext(Context, extra="forbid"):
238238

239239
operation: Operation
240240
event: WebhookEvent
241-
action: Optional[Action] = None
241+
actions: Optional[list[Action]] = None
242242
bug: BugId | Bug
243243

244244

jbi/runner.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def groups2operation(steps: ActionSteps):
5858
return by_operation
5959

6060

61-
def lookup_action(bug: bugzilla_models.Bug, actions: Actions) -> Action:
61+
def lookup_actions(bug: bugzilla_models.Bug, actions: Actions) -> list[Action]:
6262
"""
63-
Find first matching action from bug's whiteboard field.
63+
Find matching actions from bug's whiteboard field.
6464
6565
Tags are strings between brackets and can have prefixes/suffixes
6666
using dashes (eg. ``[project]``, ``[project-moco]``, ``[project-moco-sprint1]``).
@@ -71,7 +71,7 @@ def lookup_action(bug: bugzilla_models.Bug, actions: Actions) -> Action:
7171
# [tag-word], [tag-], [tag], but not [word-tag] or [tagword]
7272
search_string = r"\[" + tag + r"(-[^\]]*)*\]"
7373
if re.search(search_string, bug.whiteboard, flags=re.IGNORECASE):
74-
return action
74+
return [action]
7575

7676
raise ActionNotFoundError(", ".join(actions.by_tag.keys()))
7777

@@ -221,7 +221,7 @@ def execute_action(
221221
raise IgnoreInvalidRequestError("private bugs are not supported")
222222

223223
try:
224-
action = lookup_action(bug, actions)
224+
action = lookup_actions(bug, actions)[0]
225225
except ActionNotFoundError as err:
226226
raise IgnoreInvalidRequestError(
227227
f"no bug whiteboard matching action tags: {err}"
@@ -240,7 +240,7 @@ def execute_action(
240240

241241
runner_context = runner_context.update(bug=bug)
242242

243-
runner_context = runner_context.update(action=action)
243+
runner_context = runner_context.update(actions=[action])
244244

245245
linked_issue_key: Optional[str] = bug.extract_from_see_also(
246246
project_key=action.jira_project_key

tests/unit/test_runner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Executor,
1616
execute_action,
1717
execute_or_queue,
18-
lookup_action,
18+
lookup_actions,
1919
)
2020

2121

@@ -187,7 +187,7 @@ def test_action_is_logged_as_success_if_returns_true(
187187
("Action 'devtest' executed successfully for Bug 654321", Operation.SUCCESS),
188188
]
189189
assert capturelogs.records[-1].bug["id"] == 654321
190-
assert capturelogs.records[-1].action["whiteboard_tag"] == "devtest"
190+
assert capturelogs.records[-1].actions[0]["whiteboard_tag"] == "devtest"
191191

192192

193193
def test_action_is_logged_as_ignore_if_returns_false(
@@ -619,7 +619,7 @@ def test_counter_is_incremented_for_attachment(
619619
)
620620
def test_lookup_action_found(whiteboard, actions, bug_factory):
621621
bug = bug_factory(id=1234, whiteboard=whiteboard)
622-
action = lookup_action(bug, actions)
622+
action = lookup_actions(bug, actions)[0]
623623
assert action.whiteboard_tag == "devtest"
624624
assert "test config" in action.description
625625

@@ -649,5 +649,5 @@ def test_lookup_action_found(whiteboard, actions, bug_factory):
649649
def test_lookup_action_not_found(whiteboard, actions, bug_factory):
650650
bug = bug_factory(id=1234, whiteboard=whiteboard)
651651
with pytest.raises(ActionNotFoundError) as exc_info:
652-
lookup_action(bug, actions)
652+
lookup_actions(bug, actions)[0]
653653
assert str(exc_info.value) == "devtest"

0 commit comments

Comments
 (0)