Skip to content

Commit 6ebae33

Browse files
committed
Add support for priority and severity
1 parent 68418b2 commit 6ebae33

File tree

6 files changed

+123
-5
lines changed

6 files changed

+123
-5
lines changed

docs/actions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ linked Jira issue status to "Closed". If the bug changes to a status not listed
149149
- `update_issue`
150150
- `add_jira_comments_for_changes`
151151
- `maybe_assign_jira_user`
152+
- `maybe_update_issue_priority`
152153
- `maybe_update_issue_resolution`
154+
- `maybe_update_issue_severity`
153155
- `maybe_update_issue_status`
154156
- `create_comment`
155157
- `sync_keywords_labels`

jbi/jira/service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,9 @@ def update_issue_summary(self, context: ActionContext):
310310

311311
def update_issue_resolution(self, context: ActionContext, jira_resolution: str):
312312
"""Update the resolution of the Jira issue."""
313-
return self.update_issue_named_field(context, field="resolution", value=jira_resolution)
313+
return self.update_issue_named_field(
314+
context, field="resolution", value=jira_resolution
315+
)
314316

315317
def update_issue_components(
316318
self,

jbi/models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,23 @@ class ActionParams(BaseModel, frozen=True):
7575
jira_components: JiraComponents = JiraComponents()
7676
labels_brackets: Literal["yes", "no", "both"] = "no"
7777
status_map: dict[str, str] = {}
78+
priority_map: dict[str, str] = {
79+
"P1": "1",
80+
"P2": "2",
81+
"P3": "3",
82+
"P4": "4",
83+
"P5": "5",
84+
"--": "10000",
85+
}
7886
resolution_map: dict[str, str] = {}
87+
severity_map: dict[str, str] = {
88+
"S1": "1",
89+
"S2": "2",
90+
"S3": "3",
91+
"S4": "4",
92+
"N/A": "--",
93+
"--": "--",
94+
}
7995
issue_type_map: dict[str, str] = {"task": "Task", "defect": "Bug"}
8096

8197

jbi/steps.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,34 @@ def _maybe_update_issue_mapped_field(
220220
return (StepStatus.INCOMPLETE, context)
221221

222222
if context.operation == Operation.CREATE:
223-
resp = jira_service.update_issue_named_field(context, target_field, target_value)
223+
resp = jira_service.update_issue_named_field(
224+
context, target_field, target_value
225+
)
224226
context.append_responses(resp)
225227
return (StepStatus.SUCCESS, context)
226228

227229
if context.operation == Operation.UPDATE:
228230
if source_field in context.event.changed_fields():
229-
resp = jira_service.update_issue_named_field(context, target_field, target_value)
231+
resp = jira_service.update_issue_named_field(
232+
context, target_field, target_value
233+
)
230234
context.append_responses(resp)
231235
return (StepStatus.SUCCESS, context)
232236

233237
return (StepStatus.NOOP, context)
234238

235239

240+
def maybe_update_issue_priority(
241+
context: ActionContext, *, parameters: ActionParams, jira_service: JiraService
242+
) -> StepResult:
243+
"""
244+
Update the Jira issue priority
245+
"""
246+
return _maybe_update_issue_mapped_field(
247+
"priority", "priority", context, parameters, jira_service
248+
)
249+
250+
236251
def maybe_update_issue_resolution(
237252
context: ActionContext, *, parameters: ActionParams, jira_service: JiraService
238253
) -> StepResult:
@@ -245,6 +260,17 @@ def maybe_update_issue_resolution(
245260
)
246261

247262

263+
def maybe_update_issue_severity(
264+
context: ActionContext, *, parameters: ActionParams, jira_service: JiraService
265+
) -> StepResult:
266+
"""
267+
Update the Jira issue severity
268+
"""
269+
return _maybe_update_issue_mapped_field(
270+
"severity", "severity", context, parameters, jira_service
271+
)
272+
273+
248274
def maybe_update_issue_status(
249275
context: ActionContext, *, parameters: ActionParams, jira_service: JiraService
250276
) -> StepResult:

tests/unit/jira/test_service.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ def test_update_issue_resolution(
203203
jira_service.update_issue_resolution(context=context, jira_resolution="DONEZO")
204204

205205
before, after = capturelogs.messages
206-
assert before == "Updating resolution of Jira issue JBI-234 to DONEZO for Bug 654321"
206+
assert (
207+
before == "Updating resolution of Jira issue JBI-234 to DONEZO for Bug 654321"
208+
)
207209
assert after == "Updated resolution of Jira issue JBI-234 to DONEZO for Bug 654321"
208210

209211

@@ -230,7 +232,9 @@ def test_update_issue_resolution_raises(
230232
)
231233

232234
[message] = capturelogs.messages
233-
assert message == "Updating resolution of Jira issue JBI-234 to DONEZO for Bug 654321"
235+
assert (
236+
message == "Updating resolution of Jira issue JBI-234 to DONEZO for Bug 654321"
237+
)
234238

235239

236240
def test_create_jira_issue(

tests/unit/test_steps.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,74 @@ def test_change_to_unknown_resolution_with_resolution_map(
728728
]
729729

730730

731+
def test_update_issue_priority(
732+
action_context_factory,
733+
mocked_jira,
734+
action_params_factory,
735+
webhook_event_change_factory,
736+
):
737+
action_context = action_context_factory(
738+
operation=Operation.UPDATE,
739+
current_step="maybe_update_issue_priority",
740+
bug__see_also=["https://mozilla.atlassian.net/browse/JBI-234"],
741+
jira__issue="JBI-234",
742+
bug__priority="P1",
743+
event__action="modify",
744+
event__changes=[
745+
webhook_event_change_factory(field="priority", removed="--", added="P1")
746+
],
747+
)
748+
749+
params = action_params_factory(
750+
jira_project_key=action_context.jira.project,
751+
priority_map={
752+
"P1": "Urgent",
753+
},
754+
)
755+
steps.maybe_update_issue_priority(
756+
action_context, parameters=params, jira_service=JiraService(mocked_jira)
757+
)
758+
759+
mocked_jira.create_issue.assert_not_called()
760+
mocked_jira.update_issue_field(
761+
key="JBI-234", fields={"priority": {"name": "Urgent"}}
762+
)
763+
764+
765+
def test_update_issue_severity(
766+
action_context_factory,
767+
mocked_jira,
768+
action_params_factory,
769+
webhook_event_change_factory,
770+
):
771+
action_context = action_context_factory(
772+
operation=Operation.UPDATE,
773+
current_step="maybe_update_issue_severity",
774+
bug__see_also=["https://mozilla.atlassian.net/browse/JBI-234"],
775+
jira__issue="JBI-234",
776+
bug__severity="S3",
777+
event__action="modify",
778+
event__changes=[
779+
webhook_event_change_factory(field="severity", removed="--", added="S3")
780+
],
781+
)
782+
783+
params = action_params_factory(
784+
jira_project_key=action_context.jira.project,
785+
status_map={
786+
"S3": "Moderate",
787+
},
788+
)
789+
steps.maybe_update_issue_severity(
790+
action_context, parameters=params, jira_service=JiraService(mocked_jira)
791+
)
792+
793+
mocked_jira.create_issue.assert_not_called()
794+
mocked_jira.update_issue_field(
795+
key="JBI-234", fields={"severity": {"name": "Moderate"}}
796+
)
797+
798+
731799
@pytest.mark.parametrize(
732800
"project_components,bug_component,config_components,expected_jira_components,expected_logs",
733801
[

0 commit comments

Comments
 (0)