Skip to content

Commit

Permalink
[Jira] Update retrieval method calls
Browse files Browse the repository at this point in the history
For methods that query the API and then immediately retrieve some data
from the response, replace the get call with the new
_get_response_content method to account for advanced mode usage.
  • Loading branch information
gibsramen committed Sep 1, 2024
1 parent 48080dc commit 12f2326
Showing 1 changed file with 12 additions and 10 deletions.
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 @@ def get_issue_changelog(self, issue_key, start=None, limit=None):
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)])

def issue_add_json_worklog(self, key, worklog):
"""
Expand Down Expand Up @@ -1378,7 +1378,7 @@ def get_issue_labels(self, issue_key):
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=[("labels",)])

def update_issue(self, issue_key, update):
"""
Expand Down Expand Up @@ -1919,12 +1919,14 @@ def set_issue_status_by_transition_id(self, issue_key, transition_id):
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 {}

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)

def get_issue_transitions_full(self, issue_key, transition_id=None, expand=None):
"""
Expand Down Expand Up @@ -2721,7 +2723,7 @@ def get_project_actors_for_role_project(self, project_key, role_id):
"""
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",)])

def delete_project_actors(self, project_key, role_id, actor, actor_type=None):
"""
Expand Down Expand Up @@ -3080,7 +3082,7 @@ def get_assignable_users_for_issue(self, issue_key, username=None, start=0, limi
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",)]))

def get_status_for_project(self, project_key):
base_url = self.resource_url("project")
Expand Down Expand Up @@ -3181,7 +3183,7 @@ def get_issue_link_types(self):
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",)])

def get_issue_link_types_names(self):
"""
Expand Down Expand Up @@ -3712,7 +3714,7 @@ def get_all_permissionschemes(self, expand=None):
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",)])

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

def get_issue_security_scheme(self, scheme_id, only_levels=False):
"""
Expand All @@ -3785,7 +3787,7 @@ def get_issue_security_scheme(self, scheme_id, only_levels=False):
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",)])
else:
return self.get(url)

Expand Down

0 comments on commit 12f2326

Please sign in to comment.