Skip to content

[Jira] Fix get method data retrieval failures when advanced mode is on #1449

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 3 commits into from
Sep 3, 2024
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
22 changes: 12 additions & 10 deletions atlassian/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@
return self.get(url, params=params)
else:
url = "{base_url}/{issue_key}?expand=changelog".format(base_url=base_url, issue_key=issue_key)
return (self.get(url) or {}).get("changelog", params)
return self._get_response_content(url, fields=[("changelog", params)])

Check warning on line 1235 in atlassian/jira.py

View check run for this annotation

Codecov / codecov/patch

atlassian/jira.py#L1235

Added line #L1235 was not covered by tests

def issue_add_json_worklog(self, key, worklog):
"""
Expand Down Expand Up @@ -1378,7 +1378,7 @@
url = "{base_url}/{issue_key}?fields=labels".format(base_url=base_url, issue_key=issue_key)
if self.advanced_mode:
return self.get(url)
return (self.get(url) or {}).get("fields").get("labels")
return self._get_response_content(url, fields=[("fields",), ("labels",)])

Check warning on line 1381 in atlassian/jira.py

View check run for this annotation

Codecov / codecov/patch

atlassian/jira.py#L1381

Added line #L1381 was not covered by tests

def update_issue(self, issue_key, update):
"""
Expand Down Expand Up @@ -1919,12 +1919,14 @@
def get_issue_status(self, issue_key):
base_url = self.resource_url("issue")
url = "{base_url}/{issue_key}?fields=status".format(base_url=base_url, issue_key=issue_key)
return (((self.get(url) or {}).get("fields") or {}).get("status") or {}).get("name") or {}
fields = [("fields",), ("status",), ("name",)]
return self._get_response_content(url, fields=fields) or {}

Check warning on line 1923 in atlassian/jira.py

View check run for this annotation

Codecov / codecov/patch

atlassian/jira.py#L1922-L1923

Added lines #L1922 - L1923 were not covered by tests

def get_issue_status_id(self, issue_key):
base_url = self.resource_url("issue")
url = "{base_url}/{issue_key}?fields=status".format(base_url=base_url, issue_key=issue_key)
return (self.get(url) or {}).get("fields").get("status").get("id")
fields = [("fields",), ("status",), ("id",)]
return self._get_response_content(url, fields=fields)

Check warning on line 1929 in atlassian/jira.py

View check run for this annotation

Codecov / codecov/patch

atlassian/jira.py#L1928-L1929

Added lines #L1928 - L1929 were not covered by tests

def get_issue_transitions_full(self, issue_key, transition_id=None, expand=None):
"""
Expand Down Expand Up @@ -2721,7 +2723,7 @@
"""
base_url = self.resource_url("project")
url = "{base_url}/{projectIdOrKey}/role/{id}".format(base_url=base_url, projectIdOrKey=project_key, id=role_id)
return (self.get(url) or {}).get("actors")
return self._get_response_content(url, fields=[("actors",)])

Check warning on line 2726 in atlassian/jira.py

View check run for this annotation

Codecov / codecov/patch

atlassian/jira.py#L2726

Added line #L2726 was not covered by tests

def delete_project_actors(self, project_key, role_id, actor, actor_type=None):
"""
Expand Down Expand Up @@ -3080,7 +3082,7 @@
def get_status_id_from_name(self, status_name):
base_url = self.resource_url("status")
url = "{base_url}/{name}".format(base_url=base_url, name=status_name)
return int((self.get(url) or {}).get("id"))
return int(self._get_response_content(url, fields=[("id",)]))

Check warning on line 3085 in atlassian/jira.py

View check run for this annotation

Codecov / codecov/patch

atlassian/jira.py#L3085

Added line #L3085 was not covered by tests

def get_status_for_project(self, project_key):
base_url = self.resource_url("project")
Expand Down Expand Up @@ -3181,7 +3183,7 @@
a name and a label for the outward and inward link relationship.
"""
url = self.resource_url("issueLinkType")
return (self.get(url) or {}).get("issueLinkTypes")
return self._get_response_content(url, fields=[("issueLinkTypes",)])

Check warning on line 3186 in atlassian/jira.py

View check run for this annotation

Codecov / codecov/patch

atlassian/jira.py#L3186

Added line #L3186 was not covered by tests

def get_issue_link_types_names(self):
"""
Expand Down Expand Up @@ -3712,7 +3714,7 @@
params = {}
if expand:
params["expand"] = expand
return (self.get(url, params=params) or {}).get("permissionSchemes")
return self._get_response_content(url, params=params, fields=[("permissionSchemes",)])

Check warning on line 3717 in atlassian/jira.py

View check run for this annotation

Codecov / codecov/patch

atlassian/jira.py#L3717

Added line #L3717 was not covered by tests

def get_permissionscheme(self, permission_id, expand=None):
"""
Expand Down Expand Up @@ -3768,7 +3770,7 @@
:return: list
"""
url = self.resource_url("issuesecurityschemes")
return self.get(url).get("issueSecuritySchemes")
return self._get_response_content(url, fields=[("issueSecuritySchemes",)])

Check warning on line 3773 in atlassian/jira.py

View check run for this annotation

Codecov / codecov/patch

atlassian/jira.py#L3773

Added line #L3773 was not covered by tests

def get_issue_security_scheme(self, scheme_id, only_levels=False):
"""
Expand All @@ -3785,7 +3787,7 @@
url = "{base_url}/{scheme_id}".format(base_url=base_url, scheme_id=scheme_id)

if only_levels is True:
return self.get(url).get("levels")
return self._get_response_content(url, fields=[("levels",)])

Check warning on line 3790 in atlassian/jira.py

View check run for this annotation

Codecov / codecov/patch

atlassian/jira.py#L3790

Added line #L3790 was not covered by tests
else:
return self.get(url)

Expand Down
28 changes: 28 additions & 0 deletions atlassian/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,34 @@
log.error(e)
return response.text

def _get_response_content(
self,
*args,
fields,
**kwargs,
):
"""
:param fields: list of tuples in the form (field_name, default value (optional)).
Used for chaining dictionary value accession.
E.g. [("field1", "default1"), ("field2", "default2"), ("field3", )]
"""
response = self.get(*args, **kwargs)

Check warning on line 376 in atlassian/rest_client.py

View check run for this annotation

Codecov / codecov/patch

atlassian/rest_client.py#L376

Added line #L376 was not covered by tests
if "advanced_mode" in kwargs:
advanced_mode = kwargs["advanced_mode"]

Check warning on line 378 in atlassian/rest_client.py

View check run for this annotation

Codecov / codecov/patch

atlassian/rest_client.py#L378

Added line #L378 was not covered by tests
else:
advanced_mode = self.advanced_mode

Check warning on line 380 in atlassian/rest_client.py

View check run for this annotation

Codecov / codecov/patch

atlassian/rest_client.py#L380

Added line #L380 was not covered by tests

if not advanced_mode: # dict
for field in fields:
response = response.get(*field)

Check warning on line 384 in atlassian/rest_client.py

View check run for this annotation

Codecov / codecov/patch

atlassian/rest_client.py#L384

Added line #L384 was not covered by tests
else: # requests.Response
first_field = fields[0]
response = response.json().get(*first_field)

Check warning on line 387 in atlassian/rest_client.py

View check run for this annotation

Codecov / codecov/patch

atlassian/rest_client.py#L386-L387

Added lines #L386 - L387 were not covered by tests
for field in fields[1:]:
response = response.get(*field)

Check warning on line 389 in atlassian/rest_client.py

View check run for this annotation

Codecov / codecov/patch

atlassian/rest_client.py#L389

Added line #L389 was not covered by tests

return response

Check warning on line 391 in atlassian/rest_client.py

View check run for this annotation

Codecov / codecov/patch

atlassian/rest_client.py#L391

Added line #L391 was not covered by tests

def post(
self,
path,
Expand Down