Skip to content

Commit a2d05a8

Browse files
client.py: remove the same code and added into one
1 parent 32710fa commit a2d05a8

File tree

1 file changed

+84
-64
lines changed

1 file changed

+84
-64
lines changed

jira/client.py

Lines changed: 84 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,10 @@ class JiraCookieAuth(AuthBase):
315315
"""
316316

317317
def __init__(
318-
self, session: ResilientSession, session_api_url: str, auth: tuple[str, str]
318+
self,
319+
session: ResilientSession,
320+
session_api_url: str,
321+
auth: tuple[str, str],
319322
):
320323
"""Cookie Based Authentication.
321324
@@ -888,7 +891,10 @@ def json_params() -> dict[str, Any]:
888891
page_params["maxResults"] = page_size
889892

890893
resource = self._get_json(
891-
request_path, params=page_params, base=base, use_post=use_post
894+
request_path,
895+
params=page_params,
896+
base=base,
897+
use_post=use_post,
892898
)
893899
if resource:
894900
next_items_page = self._get_items_from_page(
@@ -901,12 +907,20 @@ def json_params() -> dict[str, Any]:
901907
break
902908

903909
return ResultList(
904-
items, start_at_from_response, max_results_from_response, total, is_last
910+
items,
911+
start_at_from_response,
912+
max_results_from_response,
913+
total,
914+
is_last,
905915
)
906916
else: # TODO: unreachable
907917
# it seems that search_users can return a list() containing a single user!
908918
return ResultList(
909-
[item_type(self._options, self._session, resource)], 0, 1, 1, True
919+
[item_type(self._options, self._session, resource)],
920+
0,
921+
1,
922+
1,
923+
True,
910924
)
911925

912926
def _get_items_from_page(
@@ -1424,7 +1438,11 @@ def dashboard_item_property(
14241438
return dashboard_item_property
14251439

14261440
def set_dashboard_item_property(
1427-
self, dashboard_id: str, item_id: str, property_key: str, value: dict[str, Any]
1441+
self,
1442+
dashboard_id: str,
1443+
item_id: str,
1444+
property_key: str,
1445+
value: dict[str, Any],
14281446
) -> DashboardItemProperty:
14291447
"""Set a dashboard item property.
14301448
@@ -1629,7 +1647,9 @@ def update_filter(
16291647

16301648
url = self._get_url(f"filter/{filter_id}")
16311649
r = self._session.put(
1632-
url, headers={"content-type": "application/json"}, data=json.dumps(data)
1650+
url,
1651+
headers={"content-type": "application/json"},
1652+
data=json.dumps(data),
16331653
)
16341654

16351655
raw_filter_json = json.loads(r.text)
@@ -1689,12 +1709,14 @@ def group_members(self, group: str) -> OrderedDict:
16891709
Args:
16901710
group (str): Name of the group.
16911711
"""
1712+
users = {}
1713+
16921714
if self._version < (6, 0, 0):
16931715
raise NotImplementedError(
16941716
"Group members is not implemented in Jira before version 6.0, upgrade the instance, if possible."
16951717
)
16961718

1697-
if self._version < (10, 0, 0):
1719+
elif self._version < (10, 0, 0):
16981720
params = {"groupname": group, "expand": "users"}
16991721
r = self._get_json("group", params=params)
17001722
size = r["users"]["size"]
@@ -1711,31 +1733,7 @@ def group_members(self, group: str) -> OrderedDict:
17111733
end_index = r2["users"]["end-index"]
17121734
size = r["users"]["size"]
17131735

1714-
result = {}
1715-
for user in r["users"]["items"]:
1716-
# 'id' is likely available only in older JIRA Server,
1717-
# it's not available on newer JIRA Server.
1718-
# 'name' is not available in JIRA Cloud.
1719-
hasId = user.get("id") is not None and user.get("id") != ""
1720-
hasName = user.get("name") is not None and user.get("name") != ""
1721-
result[
1722-
(
1723-
user["id"]
1724-
if hasId
1725-
else user.get("name")
1726-
if hasName
1727-
else user.get("accountId")
1728-
)
1729-
] = {
1730-
"name": user.get("name"),
1731-
"id": user.get("id"),
1732-
"accountId": user.get("accountId"),
1733-
"fullname": user.get("displayName"),
1734-
"email": user.get("emailAddress", "hidden"),
1735-
"active": user.get("active"),
1736-
"timezone": user.get("timezone"),
1737-
}
1738-
return OrderedDict(sorted(result.items(), key=lambda t: t[0]))
1736+
users = r["users"]["items"]
17391737

17401738
else:
17411739
params = {"groupname": group}
@@ -1755,31 +1753,33 @@ def group_members(self, group: str) -> OrderedDict:
17551753
r["values"].append(user)
17561754
end_index += r2["maxResults"]
17571755

1758-
result = {}
1759-
for user in r["values"]:
1760-
# 'id' is likely available only in older JIRA Server,
1761-
# it's not available on newer JIRA Server.
1762-
# 'name' is not available in JIRA Cloud.
1763-
hasId = user.get("id") is not None and user.get("id") != ""
1764-
hasName = user.get("name") is not None and user.get("name") != ""
1765-
result[
1766-
(
1767-
user["id"]
1768-
if hasId
1769-
else user.get("name")
1770-
if hasName
1771-
else user.get("accountId")
1772-
)
1773-
] = {
1774-
"name": user.get("name"),
1775-
"id": user.get("id"),
1776-
"accountId": user.get("accountId"),
1777-
"fullname": user.get("displayName"),
1778-
"email": user.get("emailAddress", "hidden"),
1779-
"active": user.get("active"),
1780-
"timezone": user.get("timezone"),
1781-
}
1782-
return OrderedDict(sorted(result.items(), key=lambda t: t[0]))
1756+
users = r["values"]
1757+
1758+
result = {}
1759+
for user in users:
1760+
# 'id' is likely available only in older JIRA Server,
1761+
# it's not available on newer JIRA Server.
1762+
# 'name' is not available in JIRA Cloud.
1763+
hasId = user.get("id") is not None and user.get("id") != ""
1764+
hasName = user.get("name") is not None and user.get("name") != ""
1765+
result[
1766+
(
1767+
user["id"]
1768+
if hasId
1769+
else user.get("name")
1770+
if hasName
1771+
else user.get("accountId")
1772+
)
1773+
] = {
1774+
"name": user.get("name"),
1775+
"id": user.get("id"),
1776+
"accountId": user.get("accountId"),
1777+
"fullname": user.get("displayName"),
1778+
"email": user.get("emailAddress", "hidden"),
1779+
"active": user.get("active"),
1780+
"timezone": user.get("timezone"),
1781+
}
1782+
return OrderedDict(sorted(result.items(), key=lambda t: t[0]))
17831783

17841784
def add_group(self, groupname: str) -> bool:
17851785
"""Create a new group in Jira.
@@ -1905,7 +1905,10 @@ def create_issue(
19051905
raw_issue_json = json_loads(r)
19061906
if "key" not in raw_issue_json:
19071907
raise JIRAError(
1908-
status_code=r.status_code, response=r, url=url, text=json.dumps(data)
1908+
status_code=r.status_code,
1909+
response=r,
1910+
url=url,
1911+
text=json.dumps(data),
19091912
)
19101913
if prefetch:
19111914
return self.issue(raw_issue_json["key"])
@@ -2483,7 +2486,10 @@ def add_remote_link(
24832486

24842487
data: dict[str, Any] = {}
24852488
if isinstance(destination, Issue) and destination.raw:
2486-
data["object"] = {"title": str(destination), "url": destination.permalink()}
2489+
data["object"] = {
2490+
"title": str(destination),
2491+
"url": destination.permalink(),
2492+
}
24872493
for x in applicationlinks:
24882494
if x["application"]["displayUrl"] == destination._options["server"]:
24892495
data["globalId"] = "appId={}&issueId={}".format(
@@ -4222,7 +4228,11 @@ def _create_oauth_session(self, oauth: dict[str, Any]):
42224228
FALLBACK_SHA = DEFAULT_SHA
42234229
_logging.debug("Fallback SHA 'SIGNATURE_RSA_SHA1' could not be imported.")
42244230

4225-
for sha_type in (oauth.get("signature_method"), DEFAULT_SHA, FALLBACK_SHA):
4231+
for sha_type in (
4232+
oauth.get("signature_method"),
4233+
DEFAULT_SHA,
4234+
FALLBACK_SHA,
4235+
):
42264236
if sha_type is None:
42274237
continue
42284238
oauth_instance = OAuth1(
@@ -4342,7 +4352,11 @@ def _get_internal_url(self, path: str, base: str = JIRA_BASE_URL) -> str:
43424352
"""
43434353
options = self._options.copy()
43444354
options.update(
4345-
{"path": path, "rest_api_version": "latest", "rest_path": "internal"}
4355+
{
4356+
"path": path,
4357+
"rest_api_version": "latest",
4358+
"rest_path": "internal",
4359+
}
43464360
)
43474361
return base.format(**options)
43484362

@@ -4496,7 +4510,7 @@ def rename_user(self, old_user: str, new_user: str):
44964510
self._session.put(url, params=params, data=json.dumps(payload))
44974511
else:
44984512
raise NotImplementedError(
4499-
"Support for renaming users in Jira " "< 6.0.0 has been removed."
4513+
"Support for renaming users in Jira < 6.0.0 has been removed."
45004514
)
45014515

45024516
def delete_user(self, username: str) -> bool:
@@ -4625,7 +4639,10 @@ def reindex(self, force: bool = False, background: bool = True) -> bool:
46254639
r = self._session.post(
46264640
url,
46274641
headers=self._options["headers"],
4628-
params={"indexingStrategy": indexingStrategy, "reindex": "Re-Index"},
4642+
params={
4643+
"indexingStrategy": indexingStrategy,
4644+
"reindex": "Re-Index",
4645+
},
46294646
)
46304647
if r.text.find("All issues are being re-indexed") != -1:
46314648
return True
@@ -5574,7 +5591,10 @@ def add_issues_to_sprint(self, sprint_id: int, issue_keys: list[str]) -> Respons
55745591
return self._session.post(url, data=json.dumps(payload))
55755592

55765593
def add_issues_to_epic(
5577-
self, epic_id: str, issue_keys: str | list[str], ignore_epics: bool = None
5594+
self,
5595+
epic_id: str,
5596+
issue_keys: str | list[str],
5597+
ignore_epics: bool = None,
55785598
) -> Response:
55795599
"""Add the issues in ``issue_keys`` to the ``epic_id``.
55805600

0 commit comments

Comments
 (0)