|
1 | 1 | import logging |
2 | 2 | import re |
3 | 3 | from operator import attrgetter |
| 4 | +from typing import Any, Optional |
4 | 5 |
|
5 | 6 | from django.conf import settings |
6 | 7 | from django.urls import reverse |
|
15 | 16 | IntegrationProvider, |
16 | 17 | ) |
17 | 18 | from sentry.integrations.issues import IssueSyncMixin |
18 | | -from sentry.models import IntegrationExternalProject, Organization, OrganizationIntegration, User |
| 19 | +from sentry.models import ( |
| 20 | + ExternalIssue, |
| 21 | + IntegrationExternalProject, |
| 22 | + Organization, |
| 23 | + OrganizationIntegration, |
| 24 | + User, |
| 25 | +) |
19 | 26 | from sentry.shared_integrations.exceptions import ( |
20 | 27 | ApiError, |
21 | 28 | ApiUnauthorized, |
@@ -827,14 +834,20 @@ def create_issue(self, data, **kwargs): |
827 | 834 | # Immediately fetch and return the created issue. |
828 | 835 | return self.get_issue(issue_key) |
829 | 836 |
|
830 | | - def sync_assignee_outbound(self, external_issue, user, assign=True, **kwargs): |
| 837 | + def sync_assignee_outbound( |
| 838 | + self, |
| 839 | + external_issue: "ExternalIssue", |
| 840 | + user: Optional["User"], |
| 841 | + assign: bool = True, |
| 842 | + **kwargs: Any, |
| 843 | + ) -> None: |
831 | 844 | """ |
832 | 845 | Propagate a sentry issue's assignee to a jira issue's assignee |
833 | 846 | """ |
834 | 847 | client = self.get_client() |
835 | 848 |
|
836 | 849 | jira_user = None |
837 | | - if assign: |
| 850 | + if user and assign: |
838 | 851 | for ue in user.emails.filter(is_verified=True): |
839 | 852 | try: |
840 | 853 | possible_users = client.search_users_for_issue(external_issue.key, ue.email) |
@@ -873,7 +886,7 @@ def sync_assignee_outbound(self, external_issue, user, assign=True, **kwargs): |
873 | 886 | extra={ |
874 | 887 | "organization_id": external_issue.organization_id, |
875 | 888 | "integration_id": external_issue.integration_id, |
876 | | - "user_id": user.id, |
| 889 | + "user_id": user.id if user else None, |
877 | 890 | "issue_key": external_issue.key, |
878 | 891 | }, |
879 | 892 | ) |
|
0 commit comments