-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
fix(Jira-Server): Adds halts, better exceptions for failed syncs #95281
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
GabeVillalobos
merged 4 commits into
master
from
gv/fix-jira-sync-failure-categorization
Jul 15, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7389d2a
fix(Jira-Server): Adds halts, better exceptions for failed syncs
GabeVillalobos 8765f77
Updates Jira/VSTS to use new exception types.
GabeVillalobos bcd2a13
Adds new tests, fixes broken ones
GabeVillalobos 9e00c3d
Fixes jira_server tests
GabeVillalobos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,17 +9,20 @@ | |
|
||
from fixtures.integrations.jira.stub_client import StubJiraApiClient | ||
from fixtures.integrations.stub_service import StubService | ||
from sentry.exceptions import InvalidConfiguration | ||
from sentry.integrations.jira.integration import JiraIntegrationProvider | ||
from sentry.integrations.jira.views import SALT | ||
from sentry.integrations.mixins.issues import IntegrationSyncTargetNotFound | ||
from sentry.integrations.models.external_issue import ExternalIssue | ||
from sentry.integrations.models.integration import Integration | ||
from sentry.integrations.models.integration_external_project import IntegrationExternalProject | ||
from sentry.integrations.models.organization_integration import OrganizationIntegration | ||
from sentry.integrations.services.integration import integration_service | ||
from sentry.models.grouplink import GroupLink | ||
from sentry.models.groupmeta import GroupMeta | ||
from sentry.shared_integrations.exceptions import IntegrationError | ||
from sentry.shared_integrations.exceptions import ( | ||
IntegrationError, | ||
IntegrationInstallationConfigurationError, | ||
) | ||
from sentry.silo.base import SiloMode | ||
from sentry.testutils.cases import APITestCase, IntegrationTestCase | ||
from sentry.testutils.factories import EventType | ||
|
@@ -825,7 +828,7 @@ def test_sync_assignee_outbound_no_email(self): | |
"https://example.atlassian.net/rest/api/2/user/assignable/search", | ||
json=[{"accountId": "deadbeef123", "displayName": "Dead Beef"}], | ||
) | ||
with pytest.raises(InvalidConfiguration): | ||
with pytest.raises(IntegrationSyncTargetNotFound): | ||
installation.sync_assignee_outbound(external_issue, user) | ||
|
||
# No sync made as jira users don't have email addresses | ||
|
@@ -866,6 +869,56 @@ def test_sync_assignee_outbound_use_email_api(self): | |
assert assign_issue_response.status_code == 200 | ||
assert assign_issue_response.request.body == b'{"accountId": "deadbeef123"}' | ||
|
||
@responses.activate | ||
def test_sync_assignee_outbound_api_unauthorized(self): | ||
user = serialize_rpc_user(self.create_user(email="[email protected]")) | ||
issue_id = "APP-123" | ||
installation = self.integration.get_installation(self.organization.id) | ||
assign_issue_url = "https://example.atlassian.net/rest/api/2/issue/%s/assignee" % issue_id | ||
|
||
external_issue = ExternalIssue.objects.create( | ||
organization_id=self.organization.id, integration_id=installation.model.id, key=issue_id | ||
) | ||
|
||
responses.add( | ||
responses.GET, | ||
"https://example.atlassian.net/rest/api/2/user/assignable/search", | ||
json=[{"accountId": "deadbeef123", "emailAddress": "[email protected]"}], | ||
) | ||
|
||
responses.add(responses.PUT, assign_issue_url, status=401, json={}) | ||
|
||
with pytest.raises(IntegrationInstallationConfigurationError) as excinfo: | ||
installation.sync_assignee_outbound(external_issue, user) | ||
|
||
assert str(excinfo.value) == "Insufficient permissions to assign user to the Jira issue." | ||
assert len(responses.calls) == 2 | ||
|
||
@responses.activate | ||
def test_sync_assignee_outbound_api_error(self): | ||
user = serialize_rpc_user(self.create_user(email="[email protected]")) | ||
issue_id = "APP-123" | ||
installation = self.integration.get_installation(self.organization.id) | ||
assign_issue_url = "https://example.atlassian.net/rest/api/2/issue/%s/assignee" % issue_id | ||
|
||
external_issue = ExternalIssue.objects.create( | ||
organization_id=self.organization.id, integration_id=installation.model.id, key=issue_id | ||
) | ||
|
||
responses.add( | ||
responses.GET, | ||
"https://example.atlassian.net/rest/api/2/user/assignable/search", | ||
json=[{"accountId": "deadbeef123", "emailAddress": "[email protected]"}], | ||
) | ||
|
||
responses.add(responses.PUT, assign_issue_url, status=400, json={}) | ||
|
||
with pytest.raises(IntegrationError) as excinfo: | ||
installation.sync_assignee_outbound(external_issue, user) | ||
|
||
assert str(excinfo.value) == "There was an error assigning the issue." | ||
assert len(responses.calls) == 2 | ||
|
||
|
||
@control_silo_test | ||
class JiraIntegrationTest(APITestCase): | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
from fixtures.integrations.jira.stub_client import StubJiraApiClient | ||
from fixtures.integrations.stub_service import StubService | ||
from sentry.integrations.jira_server.integration import JiraServerIntegration | ||
from sentry.integrations.mixins.issues import IntegrationSyncTargetNotFound | ||
from sentry.integrations.models.external_actor import ExternalActor | ||
from sentry.integrations.models.external_issue import ExternalIssue | ||
from sentry.integrations.models.integration_external_project import IntegrationExternalProject | ||
|
@@ -19,7 +20,12 @@ | |
from sentry.integrations.types import ExternalProviders | ||
from sentry.models.grouplink import GroupLink | ||
from sentry.models.groupmeta import GroupMeta | ||
from sentry.shared_integrations.exceptions import ApiError, ApiUnauthorized, IntegrationError | ||
from sentry.shared_integrations.exceptions import ( | ||
ApiError, | ||
ApiUnauthorized, | ||
IntegrationError, | ||
IntegrationInstallationConfigurationError, | ||
) | ||
from sentry.silo.base import SiloMode | ||
from sentry.silo.safety import unguarded_write | ||
from sentry.testutils.cases import APITestCase | ||
|
@@ -819,9 +825,9 @@ def test_sync_assignee_outbound_no_emails_for_multiple_users(self): | |
], | ||
) | ||
|
||
with pytest.raises(IntegrationError) as e: | ||
with pytest.raises(IntegrationSyncTargetNotFound) as e: | ||
self.installation.sync_assignee_outbound(external_issue, user) | ||
assert str(e.value) == "Failed to assign user to Jira Server issue" | ||
assert str(e.value) == "No matching Jira Server user found" | ||
|
||
# No sync made as jira users don't have email addresses | ||
assert len(responses.calls) == 1 | ||
|
@@ -877,7 +883,7 @@ def test_sync_assignee_outbound_unauthorized(self, mock_assign_issue): | |
} | ||
], | ||
) | ||
with pytest.raises(IntegrationError) as exc_info: | ||
with pytest.raises(IntegrationInstallationConfigurationError) as exc_info: | ||
self.installation.sync_assignee_outbound( | ||
external_issue=external_issue, user=user, assign=True | ||
) | ||
|
@@ -902,7 +908,7 @@ def test_sync_assignee_outbound_api_error(self, mock_assign_issue): | |
{ | ||
"accountId": "deadbeef123", | ||
"displayName": "Dead Beef", | ||
"username": "[email protected]", | ||
"emailAddress": "[email protected]", | ||
} | ||
], | ||
) | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leaving it as a vestigial reminder to do this in the future 😅 We do want this eventually.