Просмотр исходного кода

Revert "fix(jira server): Fetch priorities based on selected project (#58749)"

This reverts commit 07c6db86a0aa99b9a8af339c2037bee21b8809a6.

Co-authored-by: schew2381 <67301797+schew2381@users.noreply.github.com>
getsentry-bot 1 год назад
Родитель
Сommit
7caa0eccef

+ 1 - 1
fixtures/integrations/jira/stub_client.py

@@ -17,7 +17,7 @@ class StubJiraApiClient(StubService):
     def get_issue_types(self, project_id):
         return self._get_stub_data("issue_types_response.json")
 
-    def get_priorities(self, project_id):
+    def get_priorities(self):
         return self._get_stub_data("priorities_response.json")
 
     def get_versions(self, project_id):

+ 2 - 15
src/sentry/integrations/jira_server/client.py

@@ -34,10 +34,7 @@ class JiraServerClient(IntegrationProxyClient):
     ISSUE_URL = "/rest/api/2/issue/%s"
     ISSUE_FIELDS_URL = "/rest/api/2/issue/createmeta/%s/issuetypes/%s"
     ISSUE_TYPES_URL = "/rest/api/2/issue/createmeta/%s/issuetypes"
-    # https://docs.atlassian.com/software/jira/docs/api/REST/9.11.0/#api/2/priority-getPriorities
     PRIORITIES_URL = "/rest/api/2/priority"
-    # https://docs.atlassian.com/software/jira/docs/api/REST/9.11.0/#api/2/project/{projectKeyOrId}/priorityscheme
-    PRIORITY_SCHEME_URL = "/rest/api/2/project/%s/priorityscheme"
     PROJECT_URL = "/rest/api/2/project"
     SEARCH_URL = "/rest/api/2/search/"
     VERSIONS_URL = "/rest/api/2/project/%s/versions"
@@ -147,18 +144,8 @@ class JiraServerClient(IntegrationProxyClient):
     def get_versions(self, project):
         return self.get_cached(self.VERSIONS_URL % project)
 
-    def get_priorities(self, project: str):
-        """
-        Fetches all priorities associated with the project. Jira Server does not provide a
-        single API to fetch priorities for a project, so we instead fetch the project's
-        priority scheme which contains the relevant priority ids (but not human-readable names).
-        We then fetch the full list of priorities and find the overlap to get both ids and names.
-        """
-        project_priority_ids = self.get_cached(self.PRIORITY_SCHEME_URL % project)["optionIds"]
-        priorities = self.get_cached(self.PRIORITIES_URL)
-        # Find the overlap between the project's priority ids and the full list of priorities
-        priorities = [p for p in priorities if p["id"] in project_priority_ids]
-        return priorities
+    def get_priorities(self):
+        return self.get_cached(self.PRIORITIES_URL)
 
     def get_users_for_project(self, project):
         # Jira Server wants a project key, while cloud is indifferent.

+ 2 - 2
src/sentry/integrations/jira_server/integration.py

@@ -494,7 +494,7 @@ class JiraServerIntegration(IntegrationInstallation, IssueSyncMixin):
         return "{}/browse/{}".format(self.model.metadata["base_url"], key)
 
     def get_persisted_default_config_fields(self) -> Sequence[str]:
-        return ["project", "issuetype", "labels"]
+        return ["project", "issuetype", "priority", "labels"]
 
     def get_persisted_user_default_config_fields(self):
         return ["reporter"]
@@ -837,7 +837,7 @@ class JiraServerIntegration(IntegrationInstallation, IssueSyncMixin):
             if field["name"] == "priority":
                 # whenever priorities are available, put the available ones in the list.
                 # allowedValues for some reason doesn't pass enough info.
-                field["choices"] = self.make_choices(client.get_priorities(project_id))
+                field["choices"] = self.make_choices(client.get_priorities())
                 field["default"] = defaults.get("priority", "")
             elif field["name"] == "fixVersions":
                 field["choices"] = self.make_choices(client.get_versions(project_id))

+ 2 - 94
tests/sentry/integrations/jira_server/test_integration.py

@@ -1,6 +1,7 @@
 import copy
 from functools import cached_property
 from unittest import mock
+from unittest.mock import patch
 
 import pytest
 import responses
@@ -345,99 +346,6 @@ class JiraServerIntegrationTest(APITestCase):
                 "versions",
             ]
 
-    @responses.activate
-    def test_get_create_issue_config_with_project_having_subset_priorities(self):
-        """Test that a project that is limited to a subset of priorities
-        correctly returns the subset instead of all priorities
-        """
-        event = self.store_event(
-            data={
-                "event_id": "a" * 32,
-                "message": "message",
-                "timestamp": self.min_ago,
-                "stacktrace": copy.deepcopy(DEFAULT_EVENT_DATA["stacktrace"]),
-            },
-            project_id=self.project.id,
-        )
-        group = event.group
-
-        responses.add(
-            responses.GET,
-            f"https://jira.example.org/rest/api/2/project/{DEFAULT_PROJECT_ID}/priorityscheme",
-            json={
-                "expand": "projectKeys",
-                "self": "https://jira.example.org/rest/api/2/priorityschemes/1",
-                "id": 1,
-                "name": "Default Priority Scheme",
-                "description": "The default priority scheme that applies to all projects",
-                # Exclude the "medium" priority (id 2)
-                "optionIds": ["1", "3"],
-                "defaultScheme": False,
-            },
-        )
-
-        responses.add(
-            responses.GET,
-            "https://jira.example.org/rest/api/2/priority",
-            json=[
-                {
-                    "self": "https://jira.example.org/rest/api/2/priority/1",
-                    "statusColor": "#f15C75",
-                    "description": "Serious problem that could block progress.",
-                    "iconUrl": "https://jira-integration.getsentry.net/images/icons/priorities/high.svg",
-                    "name": "High",
-                    "id": "1",
-                },
-                {
-                    "self": "https://jira.example.org/rest/api/2/priority/2",
-                    "statusColor": "#f79232",
-                    "description": "Has the potential to affect progress.",
-                    "iconUrl": "https://jira-integration.getsentry.net/images/icons/priorities/medium.svg",
-                    "name": "Medium",
-                    "id": "2",
-                },
-                {
-                    "self": "https://jira.example.org/rest/api/2/priority/3",
-                    "statusColor": "#707070",
-                    "description": "Minor problem or easily worked around.",
-                    "iconUrl": "https://jira-integration.getsentry.net/images/icons/priorities/low.svg",
-                    "name": "Low",
-                    "id": "3",
-                },
-            ],
-        )
-
-        def get_priorities_callthrough_client(installation: JiraServerIntegration):
-            """
-            This functions returns a lambda that when called upon, returns a
-            StubJiraApiClient. The only difference is we don't mock the function
-            call to get_priorities for the stub client.
-            """
-            mock_client = StubJiraApiClient()
-            # set the mock call to the real function
-            setattr(mock_client, "get_priorities", installation.get_client().get_priorities)
-            return lambda: mock_client
-
-        with mock.patch.object(
-            self.installation,
-            "get_client",
-            get_priorities_callthrough_client(installation=self.installation),
-        ):
-            # Initially all fields are present
-            fields = self.installation.get_create_issue_config(group, self.user)
-            priority_field = [field for field in fields if field["name"] == "priority"][0]
-            assert priority_field == {
-                "default": "",
-                "choices": [
-                    ("1", "High"),
-                    ("3", "Low"),
-                ],
-                "type": "select",
-                "name": "priority",
-                "label": "Priority",
-                "required": False,
-            }
-
     def test_get_create_issue_config_with_default_and_param(self):
         event = self.store_event(
             data={
@@ -541,7 +449,7 @@ class JiraServerIntegrationTest(APITestCase):
         assert fields[1]["name"] == "error"
         assert fields[1]["type"] == "blank"
 
-    @mock.patch("sentry.integrations.jira_server.client.JiraServerClient.get_issue_fields")
+    @patch("sentry.integrations.jira_server.client.JiraServerClient.get_issue_fields")
     def test_get_create_issue_config_with_default_project_deleted(self, mock_get_issue_fields):
         event = self.store_event(
             data={