Skip to content

Ref #984: Show more details about attachment when created #1167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions jbi/bugzilla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@ class WebhookComment(BaseModel, frozen=True):
creation_time: Optional[SmartAwareDatetime] = None


class AttachmentFlag(BaseModel, frozen=True):
"""Flag object associated with a Bugzilla attachment."""

id: int
name: str
type_id: int
creation_date: SmartAwareDatetime
modification_date: SmartAwareDatetime
status: str
setter: str
requestee: Optional[str] = None


class WebhookAttachment(BaseModel, frozen=True):
"""Attachment object associated with a Bugzilla bug
when the webhook event is of type "attachment".
See https://bugzilla.mozilla.org/page.cgi?id=webhooks.html
"""

id: int
content_type: str
creation_time: SmartAwareDatetime
description: str
file_name: str
flags: list[AttachmentFlag]
is_obsolete: bool
is_patch: bool
is_private: bool


class Bug(BaseModel, frozen=True):
"""Bugzilla Bug Object"""

Expand All @@ -99,6 +129,7 @@ class Bug(BaseModel, frozen=True):
creator: Optional[str] = None
assigned_to: Optional[str] = None
comment: Optional[WebhookComment] = None
attachment: Optional[WebhookAttachment] = None
# Custom field Firefox for story points
cf_fx_points: Optional[str] = None

Expand Down
11 changes: 10 additions & 1 deletion jbi/jira/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,16 @@ def add_jira_comment(self, context: ActionContext):
)
_, verb = routing_key.rsplit(".", 1)
past_verb = {"modify": "modified"}.get(verb, f"{verb}d")
formatted_comment = f"*{commenter}* {past_verb} an attachment"
formatted_comment = f"*{commenter}* {past_verb} an attachment:"

# When event target is an attachment, the webhook bug object has attachment info.
if context.bug.attachment:
att = context.bug.attachment
formatted_comment += f"\n*Description*: {att.description}"
formatted_comment += (
f"\n*Filename*: {att.file_name} ({att.content_type})"
)

else:
comment = context.bug.comment
assert comment # See jbi.steps.create_comment()
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def context_attachment_example(action_context_factory) -> ActionContext:
return action_context_factory(
operation=Operation.ATTACHMENT,
bug__see_also=["https://mozilla.atlassian.net/browse/JBI-234"],
bug__with_attachment=True,
event__target="attachment",
event__routed_key="attachment.create",
event__user__login="[email protected]",
Expand Down
19 changes: 19 additions & 0 deletions tests/fixtures/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,30 @@ class Meta:
creation_time = None


class WebhookAttachmentFactory(PydanticFactory):
class Meta:
model = bugzilla_models.WebhookAttachment

id = 1
creation_time = datetime.now()
description = "Bug 1337 - Stop war r?peace"
file_name = "phabricator-D1234-url.txt"
content_type = "text/x-phabricator-request"
flags = []
is_obsolete = False
is_patch = False
is_private = False


class BugFactory(PydanticFactory):
class Meta:
model = bugzilla_models.Bug

class Params:
with_comment = factory.Trait(comment=factory.SubFactory(WebhookCommentFactory))
with_attachment = factory.Trait(
attachment=factory.SubFactory(WebhookAttachmentFactory)
)

assigned_to = "[email protected]"
comment = None
Expand All @@ -93,6 +111,7 @@ class Params:
summary = "JBI Test"
type = "defect"
whiteboard = "[devtest]"
attachment = None


class WebhookUserFactory(PydanticFactory):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def test_added_attachment(

mocked_jira.issue_add_comment.assert_called_once_with(
issue_key="JBI-234",
comment="*[email protected]* created an attachment",
comment="*[email protected]* created an attachment:\n*Description*: Bug 1337 - Stop war r?peace\n*Filename*: phabricator-D1234-url.txt (text/x-phabricator-request)",
)


Expand Down
Loading