Skip to content

Commit 87d1d58

Browse files
committed
Address review comments
This adds an additional test to make sure that actions are dispatched to the appropriate project.
1 parent 2ef1c92 commit 87d1d58

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

jbi/runner.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,7 @@ def execute_action(
246246
# is processed (eg. if it spent some time in the DL queue)
247247
raise IgnoreInvalidRequestError(str(err)) from err
248248

249-
runner_context = runner_context.update(bug=bug)
250-
251-
runner_context = runner_context.update(actions=relevant_actions)
249+
runner_context = runner_context.update(bug=bug, actions=relevant_actions)
252250

253251
return do_execute_actions(runner_context, bug, relevant_actions)
254252
except IgnoreInvalidRequestError as exception:
@@ -317,6 +315,10 @@ def do_execute_actions(
317315
if (
318316
project_key := jira_issue["fields"]["project"]["key"]
319317
) != action_context.jira.project:
318+
# TODO: We're now executing multiple actions for a given bug, we
319+
# should probably either not fail and instead report which actions
320+
# failed to apply, or execute all the changes as a "transaction" and
321+
# roll them back if one of them fails.
320322
raise IgnoreInvalidRequestError(
321323
f"ignore linked project {project_key!r} (!={action_context.jira.project!r})"
322324
)

tests/unit/test_runner.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,3 +714,54 @@ def test_request_triggers_multiple_actions(
714714
assert len(actions) == len(details)
715715
assert "devtest" in details
716716
assert "other" in details
717+
718+
719+
def test_request_triggers_multiple_update_actions(
720+
webhook_request_factory,
721+
mocked_bugzilla,
722+
mocked_jira,
723+
):
724+
actions = factories.ActionsFactory(
725+
root=[
726+
factories.ActionFactory(
727+
whiteboard_tag="devtest",
728+
bugzilla_user_id="tbd",
729+
description="test config",
730+
parameters__jira_project_key="JBI",
731+
),
732+
factories.ActionFactory(
733+
whiteboard_tag="other",
734+
bugzilla_user_id="tbd",
735+
description="test config",
736+
parameters__jira_project_key="DE",
737+
),
738+
]
739+
)
740+
741+
webhook = webhook_request_factory(
742+
bug__whiteboard="[devtest][other]",
743+
bug__see_also=[
744+
"https://mozilla.atlassian.net/browse/JBI-234",
745+
"https://mozilla.atlassian.net/browse/DE-567",
746+
],
747+
)
748+
mocked_bugzilla.get_bug.return_value = webhook.bug
749+
750+
def side_effect_for_get_issue(issue_key):
751+
if issue_key.startswith("JBI-"):
752+
return {"fields": {"project": {"key": "JBI"}}}
753+
elif issue_key.startswith("DE-"):
754+
return {"fields": {"project": {"key": "DE"}}}
755+
756+
return None
757+
758+
mocked_jira.get_issue.side_effect = side_effect_for_get_issue
759+
760+
details = execute_action(request=webhook, actions=actions)
761+
762+
# Details has the following shape:
763+
# {'devtest': {'responses': [..]}, 'other': {'responses': [...]}}
764+
assert len(actions) == len(details)
765+
assert "devtest" in details
766+
assert "other" in details
767+
print(details)

0 commit comments

Comments
 (0)