Skip to content

Commit 581b623

Browse files
chore(jira): type jira integration.py (#89803)
1 parent fbbe46c commit 581b623

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ module = [
130130
"sentry.integrations.github.client",
131131
"sentry.integrations.github.integration",
132132
"sentry.integrations.gitlab.issues",
133-
"sentry.integrations.jira.integration",
134133
"sentry.integrations.pagerduty.actions.form",
135134
"sentry.integrations.pipeline",
136135
"sentry.integrations.slack.message_builder.notifications.issues",

src/sentry/integrations/jira/client.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from requests import PreparedRequest
88

99
from sentry.integrations.client import ApiClient
10+
from sentry.integrations.models.integration import Integration
1011
from sentry.integrations.services.integration.model import RpcIntegration
1112
from sentry.integrations.utils.atlassian_connect import get_query_hash
1213
from sentry.shared_integrations.exceptions import ApiError
@@ -51,7 +52,7 @@ class JiraCloudClient(ApiClient):
5152

5253
def __init__(
5354
self,
54-
integration: RpcIntegration,
55+
integration: RpcIntegration | Integration,
5556
verify_ssl: bool,
5657
logging_context: Any | None = None,
5758
):

src/sentry/integrations/jira/integration.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import sentry_sdk
1010
from django.conf import settings
11+
from django.db.models import QuerySet
1112
from django.urls import reverse
1213
from django.utils.functional import classproperty
1314
from django.utils.translation import gettext as _
@@ -42,6 +43,7 @@
4243
IntegrationInstallationConfigurationError,
4344
)
4445
from sentry.silo.base import all_silo_function
46+
from sentry.users.models.user import User
4547
from sentry.users.services.user import RpcUser
4648
from sentry.users.services.user.service import user_service
4749
from sentry.utils.strings import truncatechars
@@ -162,6 +164,7 @@ def get_organization_config(self) -> list[dict[str, Any]]:
162164
context = organization_service.get_organization_by_id(
163165
id=self.organization_id, include_projects=False, include_teams=False
164166
)
167+
assert context, "organizationcontext must exist to get org"
165168
organization = context.organization
166169

167170
has_issue_sync = features.has("organizations:integrations-issue-sync", organization)
@@ -366,7 +369,7 @@ def update_organization_config(self, data):
366369
if org_integration is not None:
367370
self.org_integration = org_integration
368371

369-
def _filter_active_projects(self, project_mappings: Sequence[IntegrationExternalProject]):
372+
def _filter_active_projects(self, project_mappings: QuerySet[IntegrationExternalProject]):
370373
project_ids_set = {p["id"] for p in self.get_client().get_projects_list()}
371374

372375
return [pm for pm in project_mappings if pm.external_id in project_ids_set]
@@ -403,16 +406,19 @@ def sync_metadata(self):
403406
except ApiError as e:
404407
raise IntegrationError(self.message_from_error(e))
405408

406-
self.model.name = server_info["serverTitle"]
409+
metadata = self.model.metadata.copy()
410+
name = server_info["serverTitle"]
407411

408412
# There is no Jira instance icon (there is a favicon, but it doesn't seem
409413
# possible to query that with the API). So instead we just use the first
410414
# project Icon.
411415
if len(projects) > 0:
412416
avatar = projects[0]["avatarUrls"]["48x48"]
413-
self.model.metadata.update({"icon": avatar})
417+
metadata.update({"icon": avatar})
414418

415-
self.model.save()
419+
integration_service.update_integration(
420+
integration_id=self.model.id, name=name, metadata=metadata
421+
)
416422

417423
def get_link_issue_config(self, group, **kwargs):
418424
fields = super().get_link_issue_config(group, **kwargs)
@@ -528,7 +534,9 @@ def create_comment(self, issue_id, user_id, group_note):
528534

529535
def create_comment_attribution(self, user_id, comment_text):
530536
user = user_service.get_user(user_id=user_id)
531-
attribution = f"{user.name} wrote:\n\n"
537+
username = "Unknown User" if user is None else user.name
538+
539+
attribution = f"{username} wrote:\n\n"
532540
return f"{attribution}{{quote}}{comment_text}{{quote}}"
533541

534542
def update_comment(self, issue_id, user_id, group_note):
@@ -639,14 +647,7 @@ def build_dynamic_field(self, field_meta, group=None):
639647
or schema["type"] == "issuelink"
640648
):
641649
fieldtype = "select"
642-
organization = (
643-
group.organization
644-
if group
645-
else organization_service.get_organization_by_id(
646-
id=self.organization_id, include_projects=False, include_teams=False
647-
).organization
648-
)
649-
fkwargs["url"] = self.search_url(organization.slug)
650+
fkwargs["url"] = self.search_url(self.organization.slug)
650651
fkwargs["choices"] = []
651652
elif schema["type"] in ["timetracking"]:
652653
# TODO: Implement timetracking (currently unsupported altogether)
@@ -761,7 +762,7 @@ def fetch_issue_create_meta(self, client, project_id):
761762
return meta
762763

763764
@all_silo_function
764-
def get_create_issue_config(self, group: Group | None, user: RpcUser, **kwargs):
765+
def get_create_issue_config(self, group: Group | None, user: RpcUser | User, **kwargs):
765766
"""
766767
We use the `group` to get three things: organization_slug, project
767768
defaults, and default title and description. In the case where we're

0 commit comments

Comments
 (0)