in jbi/jira/service.py [0:0]
def add_jira_comment(self, context: ActionContext):
"""Publish a comment on the specified Jira issue"""
context = context.update(operation=Operation.COMMENT)
commenter = context.event.user.login if context.event.user else "unknown"
if context.event.target == "attachment":
routing_key = (
context.event.routing_key or ".modify" # only to please type checking.
)
_, verb = routing_key.rsplit(".", 1)
past_verb = {"modify": "modified"}.get(verb, f"{verb}d")
formatted_comment = f"*{commenter}* {past_verb} an attachment"
else:
comment = context.bug.comment
assert comment # See jbi.steps.create_comment()
assert comment.body # Also see jbi.steps.create_comment()
prefix = f"*{commenter}* commented: \n"
formatted_comment = prefix + markdown_to_jira(
comment.body,
max_length=context.action.parameters.jira_char_limit - len(prefix),
)
issue_key = context.jira.issue
jira_response = self.client.issue_add_comment(
issue_key=issue_key,
comment=formatted_comment,
)
logger.info(
"User comment added to Jira issue %s",
issue_key,
extra=context.model_dump(),
)
return jira_response