4
4
import logging
5
5
import os
6
6
import re
7
- from typing import TYPE_CHECKING , Any , BinaryIO , Literal , cast
7
+ from typing import TYPE_CHECKING , Any , BinaryIO , Literal , cast , Iterable
8
8
from warnings import warn
9
9
10
10
from deprecated import deprecated
@@ -145,7 +145,7 @@ def get_permissions(
145
145
146
146
return self .get (url , params = params )
147
147
148
- def get_all_permissions (self ):
148
+ def get_all_permissions (self ) -> dict | None :
149
149
"""
150
150
Returns all permissions that are present in the Jira instance -
151
151
Global, Project and the global ones added by plugins
@@ -159,7 +159,9 @@ def get_all_permissions(self):
159
159
Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/application-properties
160
160
"""
161
161
162
- def get_property (self , key : T_id | None = None , permission_level : str | None = None , key_filter : str | None = None ):
162
+ def get_property (
163
+ self , key : T_id | None = None , permission_level : str | None = None , key_filter : str | None = None
164
+ ) -> dict | None :
163
165
"""
164
166
Returns an application property
165
167
:param key: str
@@ -180,7 +182,7 @@ def get_property(self, key: T_id | None = None, permission_level: str | None = N
180
182
181
183
return self .get (url , params = params )
182
184
183
- def set_property (self , property_id : T_id , value : str ):
185
+ def set_property (self , property_id : T_id , value : str ) -> dict | None :
184
186
"""
185
187
Modify an application property via PUT. The "value" field present in the PUT will override the existing value.
186
188
:param property_id:
@@ -207,15 +209,15 @@ def get_advanced_settings(self) -> dict | None:
207
209
Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/applicationrole
208
210
"""
209
211
210
- def get_all_application_roles (self ):
212
+ def get_all_application_roles (self ) -> dict | None :
211
213
"""
212
214
Returns all ApplicationRoles in the system
213
215
:return:
214
216
"""
215
217
url = self .resource_url ("applicationrole" )
216
218
return self .get (url ) or {}
217
219
218
- def get_application_role (self , role_key : str ):
220
+ def get_application_role (self , role_key : str ) -> dict | None :
219
221
"""
220
222
Returns the ApplicationRole with passed key if it exists
221
223
:param role_key: str
@@ -242,7 +244,7 @@ def get_attachments_ids_from_issue(self, issue: T_id) -> list[dict[str, str]]:
242
244
list_attachments_id .append ({"filename" : attachment ["filename" ], "attachment_id" : attachment ["id" ]})
243
245
return list_attachments_id
244
246
245
- def get_attachment (self , attachment_id : T_id ):
247
+ def get_attachment (self , attachment_id : T_id ) -> dict | None :
246
248
"""
247
249
Returns the meta-data for an attachment, including the URI of the actual attached file
248
250
:param attachment_id: int
@@ -301,7 +303,7 @@ def download_attachments_from_issue(self, issue: T_id, path: str | None = None,
301
303
except Exception as e :
302
304
raise e
303
305
304
- def get_attachment_content (self , attachment_id : T_id ):
306
+ def get_attachment_content (self , attachment_id : T_id ) -> dict | None :
305
307
"""
306
308
Returns the content for an attachment
307
309
:param attachment_id: int
@@ -311,7 +313,7 @@ def get_attachment_content(self, attachment_id: T_id):
311
313
url = f"{ base_url } /content/{ attachment_id } "
312
314
return self .get (url , not_json_response = True )
313
315
314
- def remove_attachment (self , attachment_id : T_id ):
316
+ def remove_attachment (self , attachment_id : T_id ) -> dict | None :
315
317
"""
316
318
Remove an attachment from an issue
317
319
:param attachment_id: int
@@ -321,7 +323,7 @@ def remove_attachment(self, attachment_id: T_id):
321
323
url = f"{ base_url } /{ attachment_id } "
322
324
return self .delete (url )
323
325
324
- def get_attachment_meta (self ):
326
+ def get_attachment_meta (self ) -> dict | None :
325
327
"""
326
328
Returns the meta information for an attachments,
327
329
specifically if they are enabled and the maximum upload size allowed
@@ -330,7 +332,7 @@ def get_attachment_meta(self):
330
332
url = self .resource_url ("attachment/meta" )
331
333
return self .get (url )
332
334
333
- def get_attachment_expand_human (self , attachment_id : T_id ):
335
+ def get_attachment_expand_human (self , attachment_id : T_id ) -> dict | None :
334
336
"""
335
337
Returns the information for an expandable attachment in human-readable format
336
338
:param attachment_id: int
@@ -340,7 +342,7 @@ def get_attachment_expand_human(self, attachment_id: T_id):
340
342
url = f"{ base_url } /{ attachment_id } /expand/human"
341
343
return self .get (url )
342
344
343
- def get_attachment_expand_raw (self , attachment_id : T_id ):
345
+ def get_attachment_expand_raw (self , attachment_id : T_id ) -> dict | None :
344
346
"""
345
347
Returns the information for an expandable attachment in raw format
346
348
:param attachment_id: int
@@ -362,7 +364,7 @@ def get_audit_records(
362
364
filter : str | None = None ,
363
365
from_date : str | None = None ,
364
366
to_date : str | None = None ,
365
- ):
367
+ ) -> dict | None :
366
368
"""
367
369
Returns auditing records filtered using provided parameters
368
370
:param offset: the number of record from which search starts
@@ -392,7 +394,7 @@ def get_audit_records(
392
394
url = self .resource_url ("auditing/record" )
393
395
return self .get (url , params = params ) or {}
394
396
395
- def post_audit_record (self , audit_record : dict | str ):
397
+ def post_audit_record (self , audit_record : dict | str ) -> dict | None :
396
398
"""
397
399
Store a record in Audit Log
398
400
:param audit_record: json with compat https://docs.atlassian.com/jira/REST/schema/audit-record#
@@ -406,7 +408,7 @@ def post_audit_record(self, audit_record: dict | str):
406
408
Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/avatar
407
409
"""
408
410
409
- def get_all_system_avatars (self , avatar_type : str = "user" ):
411
+ def get_all_system_avatars (self , avatar_type : str = "user" ) -> dict | None :
410
412
"""
411
413
Returns all system avatars of the given type.
412
414
:param avatar_type:
@@ -422,11 +424,11 @@ def get_all_system_avatars(self, avatar_type: str = "user"):
422
424
Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/cluster
423
425
"""
424
426
425
- def get_cluster_all_nodes (self ):
427
+ def get_cluster_all_nodes (self ) -> dict | None :
426
428
url = self .resource_url ("cluster/nodes" )
427
429
return self .get (url )
428
430
429
- def delete_cluster_node (self , node_id : T_id ):
431
+ def delete_cluster_node (self , node_id : T_id ) -> dict | None :
430
432
"""
431
433
Delete the node from the cluster if state of node is OFFLINE
432
434
:param node_id: str
@@ -436,7 +438,7 @@ def delete_cluster_node(self, node_id: T_id):
436
438
url = f"{ base_url } /{ node_id } "
437
439
return self .delete (url )
438
440
439
- def set_node_to_offline (self , node_id : T_id ):
441
+ def set_node_to_offline (self , node_id : T_id ) -> dict | None :
440
442
"""
441
443
Change the node's state to offline if the node is reporting as active, but is not alive
442
444
:param node_id: str
@@ -446,14 +448,15 @@ def set_node_to_offline(self, node_id: T_id):
446
448
url = f"{ base_url } /{ node_id } /offline"
447
449
return self .put (url )
448
450
449
- def get_cluster_alive_nodes (self ):
451
+ def get_cluster_alive_nodes (self ) -> list :
450
452
"""
451
453
Get cluster nodes where alive = True
452
454
:return: list of node dicts
453
455
"""
454
- return [_ for _ in self .get_cluster_all_nodes () if _ ["alive" ]]
456
+ nodes = self .get_cluster_all_nodes ()
457
+ return [_ for _ in nodes .values () if _ ["alive" ]] if nodes else []
455
458
456
- def request_current_index_from_node (self , node_id : T_id ):
459
+ def request_current_index_from_node (self , node_id : T_id ) -> dict | None :
457
460
"""
458
461
Request current index from node (the request is processed asynchronously)
459
462
:return:
@@ -467,7 +470,7 @@ def request_current_index_from_node(self, node_id: T_id):
467
470
Reference: https://confluence.atlassian.com/support/create-a-support-zip-using-the-rest-api-in-data-center-applications-952054641.html
468
471
"""
469
472
470
- def generate_support_zip_on_nodes (self , node_ids : list ):
473
+ def generate_support_zip_on_nodes (self , node_ids : list ) -> dict | None :
471
474
"""
472
475
Generate a support zip on targeted nodes of a cluster
473
476
:param node_ids: list
@@ -477,7 +480,7 @@ def generate_support_zip_on_nodes(self, node_ids: list):
477
480
url = "/rest/troubleshooting/latest/support-zip/cluster"
478
481
return self .post (url , data = data )
479
482
480
- def check_support_zip_status (self , cluster_task_id : T_id ):
483
+ def check_support_zip_status (self , cluster_task_id : T_id ) -> dict | None :
481
484
"""
482
485
Check status of support zip creation task
483
486
:param cluster_task_id: str
@@ -486,7 +489,7 @@ def check_support_zip_status(self, cluster_task_id: T_id):
486
489
url = f"/rest/troubleshooting/latest/support-zip/status/cluster/{ cluster_task_id } "
487
490
return self .get (url )
488
491
489
- def download_support_zip (self , file_name : str ):
492
+ def download_support_zip (self , file_name : str ) -> bytes :
490
493
"""
491
494
Download created support zip file
492
495
:param file_name: str
@@ -500,12 +503,12 @@ def download_support_zip(self, file_name: str):
500
503
Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/cluster/zdu
501
504
"""
502
505
503
- def get_cluster_zdu_state (self ):
506
+ def get_cluster_zdu_state (self ) -> dict | None :
504
507
url = self .resource_url ("cluster/zdu/state" )
505
508
return self .get (url )
506
509
507
510
# Issue Comments
508
- def issue_get_comments (self , issue_id : T_id ):
511
+ def issue_get_comments (self , issue_id : T_id ) -> dict | None :
509
512
"""
510
513
Get Comments on an Issue.
511
514
:param issue_id: Issue ID
@@ -516,7 +519,7 @@ def issue_get_comments(self, issue_id: T_id):
516
519
url = f"{ base_url } /{ issue_id } /comment"
517
520
return self .get (url )
518
521
519
- def issues_get_comments_by_id (self , * args ) :
522
+ def issues_get_comments_by_id (self , * args : int ) -> dict | None :
520
523
"""
521
524
Get Comments on Multiple Issues
522
525
:param *args: int Issue ID's
@@ -847,7 +850,7 @@ def get_filter(self, filter_id: T_id):
847
850
url = f"{ base_url } /{ filter_id } "
848
851
return self .get (url )
849
852
850
- def update_filter (self , filter_id : T_id , jql : str , ** kwargs ):
853
+ def update_filter (self , filter_id : T_id , jql : str , ** kwargs : Any ):
851
854
"""
852
855
:param filter_id: int
853
856
:param jql: str
@@ -1412,7 +1415,7 @@ def issue_field_value_append(self, issue_id_or_key: str, field: str, value: str,
1412
1415
params = params ,
1413
1416
)
1414
1417
1415
- def get_issue_labels (self , issue_key : str ):
1418
+ def get_issue_labels (self , issue_key : str ) -> dict | None :
1416
1419
"""
1417
1420
Get issue labels.
1418
1421
:param issue_key:
@@ -1744,7 +1747,7 @@ def scrap_regex_from_issue(self, issue: str, regex: str):
1744
1747
except HTTPError as e :
1745
1748
if e .response .status_code == 404 :
1746
1749
# Raise ApiError as the documented reason is ambiguous
1747
- log .error ("couldn't find issue: " , issue [ "key" ] )
1750
+ log .error ("couldn't find issue: " , issue )
1748
1751
raise ApiNotFoundError (
1749
1752
"There is no content with the given issue ud,"
1750
1753
"or the calling user does not have permission to view the issue" ,
@@ -1886,7 +1889,7 @@ def update_issue_remote_link_by_id(
1886
1889
url = f"{ base_url } /{ issue_key } /remotelink/{ link_id } "
1887
1890
return self .put (url , data = data )
1888
1891
1889
- def delete_issue_remote_link_by_id (self , issue_key : str , link_id : T_id ):
1892
+ def delete_issue_remote_link_by_id (self , issue_key : str , link_id : T_id ) -> dict | None :
1890
1893
"""
1891
1894
Deletes Remote Link on Issue
1892
1895
:param issue_key: str
@@ -1896,27 +1899,23 @@ def delete_issue_remote_link_by_id(self, issue_key: str, link_id: T_id):
1896
1899
url = f"{ base_url } /{ issue_key } /remotelink/{ link_id } "
1897
1900
return self .delete (url )
1898
1901
1899
- def get_issue_transitions (self , issue_key : str ):
1902
+ def get_issue_transitions (self , issue_key : str ) -> list [ dict ] :
1900
1903
if self .advanced_mode :
1901
- return [
1902
- {
1903
- "name" : transition ["name" ],
1904
- "id" : int (transition ["id" ]),
1905
- "to" : transition ["to" ]["name" ],
1906
- }
1907
- for transition in (self .get_issue_transitions_full (issue_key ).json () or {}).get ("transitions" )
1908
- ]
1904
+ resp = cast (Response , self .get_issue_transitions_full (issue_key ))
1905
+ d : dict [str , list ] = resp .json () or {}
1909
1906
else :
1910
- return [
1911
- {
1912
- "name" : transition ["name" ],
1913
- "id" : int (transition ["id" ]),
1914
- "to" : transition ["to" ]["name" ],
1915
- }
1916
- for transition in (self .get_issue_transitions_full (issue_key ) or {}).get ("transitions" )
1917
- ]
1907
+ d = self .get_issue_transitions_full (issue_key ) or {}
1908
+
1909
+ return [
1910
+ {
1911
+ "name" : transition ["name" ],
1912
+ "id" : int (transition ["id" ]),
1913
+ "to" : transition ["to" ]["name" ],
1914
+ }
1915
+ for transition in cast (list [dict ], d .get ("transitions" ))
1916
+ ]
1918
1917
1919
- def issue_transition (self , issue_key : str , status : str ):
1918
+ def issue_transition (self , issue_key : str , status : str ) -> dict | None :
1920
1919
return self .set_issue_status (issue_key , status )
1921
1920
1922
1921
def set_issue_status (
@@ -1975,7 +1974,7 @@ def get_issue_status(self, issue_key: str):
1975
1974
fields = [("fields" ,), ("status" ,), ("name" ,)]
1976
1975
return self ._get_response_content (url , fields = fields ) or {}
1977
1976
1978
- def get_issue_status_id (self , issue_key : str ):
1977
+ def get_issue_status_id (self , issue_key : str ) -> str :
1979
1978
base_url = self .resource_url ("issue" )
1980
1979
url = f"{ base_url } /{ issue_key } ?fields=status"
1981
1980
fields = [("fields" ,), ("status" ,), ("id" ,)]
0 commit comments