Skip to content

Commit 4b27086

Browse files
authored
Ref #984: do not post comments if body is empty (#997)
1 parent e7b3fca commit 4b27086

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

jbi/jira/service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ def add_jira_comment(self, context: ActionContext):
120120
commenter = context.event.user.login if context.event.user else "unknown"
121121
comment = context.bug.comment
122122
assert comment # See jbi.steps.create_comment()
123+
assert comment.body # Also see jbi.steps.create_comment()
123124

124125
issue_key = context.jira.issue
125126
formatted_comment = (
126-
f"*{commenter}* commented: \n{markdown_to_jira(comment.body or "")}"
127+
f"*{commenter}* commented: \n{markdown_to_jira(comment.body)}"
127128
)
128129
jira_response = self.client.issue_add_comment(
129130
issue_key=issue_key,

jbi/steps.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ def create_comment(context: ActionContext, *, jira_service: JiraService) -> Step
5757
)
5858
return (StepStatus.NOOP, context)
5959

60+
if not bug.comment.body:
61+
logger.info(
62+
"Comment message is empty",
63+
extra=context.model_dump(),
64+
)
65+
return (StepStatus.NOOP, context)
66+
6067
jira_response = jira_service.add_jira_comment(context)
6168
context = context.append_responses(jira_response)
6269
return (StepStatus.SUCCESS, context)

tests/unit/test_steps.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,30 @@ def test_added_comment(
234234
)
235235

236236

237+
def test_empty_comment_not_added(
238+
action_context_factory, mocked_jira, action_params_factory
239+
):
240+
empty_comment_context = action_context_factory(
241+
operation=Operation.COMMENT,
242+
bug__see_also=["https://mozilla.atlassian.net/browse/JBI-234"],
243+
bug__with_comment=True,
244+
bug__comment__number=2,
245+
bug__comment__body="",
246+
bug__comment__is_private=False,
247+
event__target="comment",
248+
event__user__login="[email protected]",
249+
jira__issue="JBI-234",
250+
)
251+
252+
callable_object = Executor(
253+
action_params_factory(jira_project_key=empty_comment_context.jira.project)
254+
)
255+
256+
callable_object(context=empty_comment_context)
257+
258+
mocked_jira.issue_add_comment.assert_not_called()
259+
260+
237261
def test_jira_returns_an_error(
238262
context_create_example: ActionContext, mocked_jira, action_params_factory
239263
):

0 commit comments

Comments
 (0)