Skip to content

Commit 86eae44

Browse files
authored
Merge branch 'mozilla:main' into main
2 parents 512929c + 12dbcb7 commit 86eae44

File tree

12 files changed

+543
-353
lines changed

12 files changed

+543
-353
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Creating a python base with shared environment variables
2-
FROM python:3.13.7 AS base
2+
FROM python:3.14.0 AS base
33
ENV PIP_NO_CACHE_DIR=off \
44
PIP_DEFAULT_TIMEOUT=100 \
55
PIP_DISABLE_PIP_VERSION_CHECK=on \
@@ -22,7 +22,7 @@ COPY ./poetry.lock ./pyproject.toml ./
2222
RUN $POETRY_HOME/bin/poetry install --without dev --no-root
2323

2424
# `production` stage uses the dependencies downloaded in the `base` stage
25-
FROM python:3.13.7-slim AS production
25+
FROM python:3.14.0-slim AS production
2626

2727
# Install pandoc for markdown to Jira conversions.
2828
RUN apt-get -y update && \

config/config.prod.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
- maybe_update_components
165165
- maybe_update_issue_status
166166
- maybe_update_issue_resolution
167+
- maybe_add_phabricator_link
167168
- sync_whiteboard_labels
168169
- sync_keywords_labels
169170
existing:
@@ -172,6 +173,7 @@
172173
- maybe_assign_jira_user
173174
- maybe_update_issue_status
174175
- maybe_update_issue_resolution
176+
- maybe_add_phabricator_link
175177
- sync_whiteboard_labels
176178
- sync_keywords_labels
177179
- add_jira_comments_for_changes
@@ -364,20 +366,33 @@
364366
- maybe_assign_jira_user
365367
- maybe_update_issue_status
366368
- maybe_update_issue_resolution
369+
- maybe_update_issue_priority
370+
- maybe_update_issue_severity
371+
- maybe_add_phabricator_link
367372
- sync_whiteboard_labels
368373
- sync_keywords_labels
369374
existing:
370375
- update_issue_summary
371376
- maybe_assign_jira_user
372377
- maybe_update_issue_status
373378
- maybe_update_issue_resolution
379+
- maybe_update_issue_priority
380+
- maybe_update_issue_severity
381+
- maybe_add_phabricator_link
374382
- sync_whiteboard_labels
375383
- sync_keywords_labels
376384
- add_jira_comments_for_changes
377385
comment:
378386
- create_comment
379387
status_map: *basic-status-map
380388
resolution_map: *basic-resolution-map
389+
priority_map:
390+
"": (none)
391+
P1: P1
392+
P2: P2
393+
P3: P3
394+
P4: P4
395+
P5: P5
381396

382397
- whiteboard_tag: proton
383398
bugzilla_user_id: tbd

docs/actions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,4 @@ linked Jira issue status to "Closed". If the bug changes to a status not listed
161161
- `sync_whiteboard_labels`:
162162
Syncs the Bugzilla whitboard tags field to the Jira labels field.
163163
- `maybe_update_components`: looks at the component that's set on the bug (if any) and any components added to the project configuration with the `jira_components` parameter (see above). If those components are available on the Jira side as well, they're added to the Jira issue
164+
- `maybe_add_phabricator_link`: looks at an attachment and if it is a phabricator attachment, it gets added as a link or updated if the attachment was previously added.

jbi/bugzilla/models.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22
import logging
3+
import re
34
from typing import Any, Optional, TypedDict
45
from urllib.parse import ParseResult, urlparse
56

@@ -102,6 +103,36 @@ class WebhookAttachment(BaseModel, frozen=True):
102103
is_patch: bool
103104
is_private: bool
104105

106+
def is_phabricator_patch(self) -> bool:
107+
"""
108+
Returns True if this attachment is a phabricator patch attachment.
109+
110+
We identify an attachment as a patch if the content type contains "phabricator-request"
111+
"""
112+
return "phabricator-request" in self.content_type
113+
114+
def phabricator_url(self, base_url: str) -> str | None:
115+
"""
116+
Returns the Phabricator patch URL from the file name if the attachment is a patch, otherwise, it returns None.
117+
"""
118+
if not self.is_phabricator_patch():
119+
return None
120+
121+
match = re.search(r'D\d+', self.file_name)
122+
if not match:
123+
logger.info(
124+
"Expected that attachment with name %s is a patch, but we couldn't extract the phabricator id (e.g D1234)",
125+
self.file_name,
126+
extra={
127+
"bug": {
128+
"id": self.id,
129+
}
130+
},
131+
)
132+
return None
133+
134+
revision_id = match.group(0)
135+
return f"{base_url}/{revision_id}"
105136

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

jbi/environment.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class Settings(BaseSettings):
4040
bugzilla_base_url: str = "https://bugzilla-dev.allizom.org"
4141
bugzilla_api_key: str
4242

43+
# Phabricator
44+
phabricator_base_url: str = "https://phabricator.services.mozilla.com"
45+
4346
# Logging
4447
log_level: str = "info"
4548
log_format: str = "json" # set to "text" for human-readable logs

jbi/jira/service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ def add_jira_comment(self, context: ActionContext):
132132
formatted_comment += (
133133
f"\n*Filename*: {att.file_name} ({att.content_type})"
134134
)
135+
if phabricator_url := att.phabricator_url(base_url=settings.phabricator_base_url):
136+
formatted_comment += f"\n*Phabricator URL*: {phabricator_url}"
135137

136138
else:
137139
comment = context.bug.comment

jbi/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ActionSteps(BaseModel, frozen=True):
4545
]
4646
attachment: list[str] = [
4747
"create_comment",
48+
"maybe_add_phabricator_link",
4849
]
4950

5051
@field_validator("*")

jbi/steps.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,51 @@ def add_link_to_bugzilla(
118118
context = context.append_responses(jira_response)
119119
return (StepStatus.SUCCESS, context)
120120

121+
def maybe_add_phabricator_link(
122+
context: ActionContext,
123+
*,
124+
jira_service: JiraService,
125+
) -> StepResult:
126+
"""Add a phabricator link to the Jira issue if an attachment is a phabricator attachment"""
127+
if context.event.target != "attachment" or not context.bug.attachment:
128+
return (StepStatus.NOOP, context)
129+
130+
attachment = context.bug.attachment
131+
132+
settings = get_settings()
133+
phabricator_url = attachment.phabricator_url(base_url=settings.phabricator_base_url)
134+
135+
if not phabricator_url:
136+
return (StepStatus.NOOP, context)
137+
138+
description = attachment.description
139+
if attachment.is_obsolete:
140+
description = f"{0} - {1}".format("Abandoned", attachment.description)
141+
142+
issue_key = context.jira.issue
143+
144+
jira_response = jira_service.client.create_or_update_issue_remote_links(
145+
issue_key=issue_key,
146+
global_id=f"{context.bug.id}-{attachment.id}",
147+
link_url=phabricator_url,
148+
title=description,
149+
)
150+
151+
if jira_response:
152+
logger.info(
153+
"Phabricator patch added or updated in Jira issue %s",
154+
issue_key,
155+
extra=context.update(operation=Operation.LINK).model_dump(),
156+
)
157+
context = context.append_responses(jira_response)
158+
return (StepStatus.SUCCESS, context)
159+
else:
160+
logger.info(
161+
"Failed to add or update phabricator url in Jira issue %s",
162+
issue_key,
163+
)
164+
165+
return (StepStatus.NOOP, context)
121166

122167
def maybe_delete_duplicate(
123168
context: ActionContext,

0 commit comments

Comments
 (0)