Skip to content

fix(jira-server): try a second project for jira server if the first one fails #56439

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
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/sentry/integrations/jira_server/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,17 +705,24 @@ def get_create_issue_config(self, group, user, **kwargs):
project_id = params.get("project", defaults.get("project"))
jira_projects = self.get_projects()

try_other_projects = False
if not project_id:
project_id = jira_projects[0]["id"]
try_other_projects = True

client = self.get_client()
try:
issue_type_choices = client.get_issue_types(project_id)
except ApiError:
# re-fetch projects list w/o caching and try again
jira_projects = self.get_projects(False)
project_id = jira_projects[0]["id"]
issue_type_choices = client.get_issue_types(project_id)
if try_other_projects:
# try again with a different project
other_projects = list(filter(lambda x: x["id"] != str(project_id), jira_projects))
if not other_projects:
raise
project_id = other_projects[0]["id"]
issue_type_choices = client.get_issue_types(project_id)
else:
raise

issue_type_choices_formatted = [
(choice["id"], choice["name"]) for choice in issue_type_choices["values"]
Expand Down
4 changes: 2 additions & 2 deletions tests/sentry/integrations/jira_server/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def test_get_create_issue_config_with_default(self):
@responses.activate
def test_get_create_issue_config_with_default_project_issue_types_erroring(self):
"""Test that if you have a default project set that's returning an error when
we try to get the issue types we re-fetch the projects list w/o caching and try again
we try to get the issue types we try a second project
"""
event = self.store_event(
data={"message": "oh no", "timestamp": self.min_ago}, project_id=self.project.id
Expand All @@ -421,7 +421,7 @@ def test_get_create_issue_config_with_default_project_issue_types_erroring(self)
assert self.installation.org_integration is not None
self.installation.org_integration = integration_service.update_organization_integration(
org_integration_id=self.installation.org_integration.id,
config={"project_issue_defaults": {str(group.project_id): {"project": "10000"}}},
config={"project_issue_defaults": {str(group.project_id): {}}},
)
responses.add(
responses.GET,
Expand Down