Skip to content

Commit 9bb1644

Browse files
authored
Fix #248: add maybe_update_issue_points step (#891)
* Fix #248: add 'maybe_update_issue_points' step * Add missing test
1 parent 0a181ee commit 9bb1644

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

jbi/bugzilla/models.py

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class Bug(BaseModel, frozen=True):
7474
creator: Optional[str] = None
7575
assigned_to: Optional[str] = None
7676
comment: Optional[WebhookComment] = None
77+
# Custom field Firefox for story points
78+
cf_fx_points: Optional[str] = None
7779

7880
@property
7981
def product_component(self) -> str:

jbi/models.py

+13
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class ActionParams(BaseModel, frozen=True):
7474
jira_project_key: str
7575
steps: ActionSteps = ActionSteps()
7676
jira_components: JiraComponents = JiraComponents()
77+
jira_cf_fx_points_field: str = "customfield_10037"
7778
jira_severity_field: str = "customfield_10716"
7879
jira_priority_field: str = "priority"
7980
jira_resolution_field: str = "resolution"
@@ -88,6 +89,18 @@ class ActionParams(BaseModel, frozen=True):
8889
}
8990
resolution_map: dict[str, str] = {}
9091
severity_map: dict[str, str] = {}
92+
cf_fx_points_map: dict[str, int] = {
93+
"?": 0,
94+
"1": 1,
95+
"2": 2,
96+
"3": 3,
97+
"5": 5,
98+
"7": 7,
99+
"8": 8,
100+
"12": 12,
101+
"13": 13,
102+
"15": 15,
103+
}
91104
issue_type_map: dict[str, str] = {"task": "Task", "defect": "Bug"}
92105

93106

jbi/steps.py

+11
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,17 @@ def maybe_update_issue_severity(
270270
)
271271

272272

273+
def maybe_update_issue_points(
274+
context: ActionContext, *, parameters: ActionParams, jira_service: JiraService
275+
) -> StepResult:
276+
"""
277+
Update the Jira issue story points
278+
"""
279+
return _maybe_update_issue_mapped_field(
280+
"cf_fx_points", context, parameters, jira_service
281+
)
282+
283+
273284
def maybe_update_issue_status(
274285
context: ActionContext, *, parameters: ActionParams, jira_service: JiraService
275286
) -> StepResult:

tests/unit/test_steps.py

+67
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,73 @@ def test_update_issue_unknown_severity(
866866
assert capturelogs.messages == ["Bug severity 'S3' was not in the severity map."]
867867

868868

869+
def test_update_issue_points(
870+
action_context_factory,
871+
mocked_jira,
872+
action_params_factory,
873+
webhook_event_change_factory,
874+
):
875+
action_context = action_context_factory(
876+
operation=Operation.UPDATE,
877+
current_step="maybe_update_issue_points",
878+
bug__see_also=["https://mozilla.atlassian.net/browse/JBI-234"],
879+
jira__issue="JBI-234",
880+
bug__cf_fx_points="15",
881+
event__action="modify",
882+
event__changes=[
883+
webhook_event_change_factory(field="cf_fx_points", removed="?", added="15")
884+
],
885+
)
886+
887+
params = action_params_factory(
888+
jira_project_key=action_context.jira.project,
889+
)
890+
steps.maybe_update_issue_points(
891+
action_context, parameters=params, jira_service=JiraService(mocked_jira)
892+
)
893+
894+
mocked_jira.create_issue.assert_not_called()
895+
mocked_jira.update_issue_field.assert_called_with(
896+
key="JBI-234", fields={"customfield_10037": 15}
897+
)
898+
899+
900+
def test_update_issue_points_missing_in_map(
901+
action_context_factory,
902+
mocked_jira,
903+
action_params_factory,
904+
webhook_event_change_factory,
905+
capturelogs,
906+
):
907+
action_context = action_context_factory(
908+
operation=Operation.UPDATE,
909+
current_step="maybe_update_issue_points",
910+
bug__see_also=["https://mozilla.atlassian.net/browse/JBI-234"],
911+
jira__issue="JBI-234",
912+
bug__cf_fx_points="42",
913+
event__action="modify",
914+
event__changes=[
915+
webhook_event_change_factory(field="cf_fx_points", removed="?", added="42")
916+
],
917+
)
918+
919+
params = action_params_factory(
920+
jira_project_key=action_context.jira.project,
921+
)
922+
923+
with capturelogs.for_logger("jbi.steps").at_level(logging.DEBUG):
924+
result, _ = steps.maybe_update_issue_points(
925+
action_context, parameters=params, jira_service=JiraService(mocked_jira)
926+
)
927+
928+
assert result == steps.StepStatus.INCOMPLETE
929+
mocked_jira.create_issue.assert_not_called()
930+
mocked_jira.update_issue_field.assert_not_called()
931+
assert capturelogs.messages == [
932+
"Bug cf_fx_points '42' was not in the cf_fx_points map."
933+
]
934+
935+
869936
@pytest.mark.parametrize(
870937
"project_components,bug_component,config_components,expected_jira_components,expected_logs",
871938
[

0 commit comments

Comments
 (0)