atlassian-python-api 4.0.4__py3-none-any.whl → 4.0.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
atlassian/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.4
1
+ 4.0.6
@@ -1577,14 +1577,7 @@ class Bitbucket(BitbucketBase):
1577
1577
  return f"{self._url_repo(project_key, repository_slug)}/pull-requests"
1578
1578
 
1579
1579
  def get_pull_requests(
1580
- self,
1581
- project_key,
1582
- repository_slug,
1583
- state="OPEN",
1584
- order="newest",
1585
- limit=100,
1586
- start=0,
1587
- at=None,
1580
+ self, project_key, repository_slug, state="OPEN", order="newest", limit=100, start=0, at=None, filter_text=None
1588
1581
  ):
1589
1582
  """
1590
1583
  Get pull requests
@@ -1596,6 +1589,8 @@ class Bitbucket(BitbucketBase):
1596
1589
  :param limit:
1597
1590
  :param start:
1598
1591
  :param at:
1592
+ :param filter_text: (optional) If specified, only pull requests where the title or description
1593
+ contains the supplied string will be returned.
1599
1594
  :return:
1600
1595
  """
1601
1596
  url = self._url_pull_requests(project_key, repository_slug)
@@ -1610,6 +1605,8 @@ class Bitbucket(BitbucketBase):
1610
1605
  params["order"] = order
1611
1606
  if at:
1612
1607
  params["at"] = at
1608
+ if filter_text:
1609
+ params["filterText"] = filter_text
1613
1610
  return self._get_paged(url, params=params)
1614
1611
 
1615
1612
  def get_required_reviewers_for_pull_request(
@@ -1,5 +1,6 @@
1
1
  from ..base import BitbucketCloudBase
2
2
  from ..common.users import User
3
+ from ..common.users import AppUser
3
4
 
4
5
 
5
6
  class Comment(BitbucketCloudBase):
@@ -31,6 +32,9 @@ class Comment(BitbucketCloudBase):
31
32
  @property
32
33
  def user(self):
33
34
  """User object with user information of the comment."""
35
+ if self.get_data("user")["type"] == "app_user":
36
+ # If the participant is an app user, return an AppUser instance
37
+ return AppUser(None, self.get_data("user"), **self._new_session_args)
34
38
  return User(None, self.get_data("user"), **self._new_session_args)
35
39
 
36
40
  def update(self, **kwargs):
@@ -1,3 +1,5 @@
1
+ from datetime import datetime
2
+
1
3
  from ..base import BitbucketCloudBase
2
4
 
3
5
 
@@ -31,6 +33,49 @@ class User(BitbucketCloudBase):
31
33
  return self.get_data("links")["avatar"]["href"]
32
34
 
33
35
 
36
+ class AppUser(BitbucketCloudBase):
37
+ def __init__(self, url, data, *args, **kwargs):
38
+ super(AppUser, self).__init__(url, *args, data=data, expected_type="app_user", **kwargs)
39
+
40
+ @property
41
+ def display_name(self):
42
+ """User display name"""
43
+ return str(self.get_data("display_name"))
44
+
45
+ @property
46
+ def account_id(self):
47
+ """User account id"""
48
+ return self.get_data("account_id")
49
+
50
+ @property
51
+ def account_status(self):
52
+ """User account status"""
53
+ return self.get_data("account_status")
54
+
55
+ @property
56
+ def created_on(self):
57
+ """User creation date"""
58
+ created_on = self.get_data("created_on")
59
+ if created_on is None:
60
+ return None
61
+ return datetime.strptime(created_on, self.CONF_TIMEFORMAT)
62
+
63
+ @property
64
+ def uuid(self):
65
+ """User id"""
66
+ return self.get_data("uuid")
67
+
68
+ @property
69
+ def kind(self):
70
+ """User kind"""
71
+ return self.get_data("kind")
72
+
73
+ @property
74
+ def links(self):
75
+ """User links"""
76
+ return self.get_data("links")
77
+
78
+
34
79
  class Participant(BitbucketCloudBase):
35
80
  ROLE_REVIEWER = "REVIEWER"
36
81
  ROLE_PARTICIPANT = "PARTICIPANT"
@@ -42,6 +87,9 @@ class Participant(BitbucketCloudBase):
42
87
  @property
43
88
  def user(self):
44
89
  """User object with user information of the participant."""
90
+ if self.get_data("user")["type"] == "app_user":
91
+ # If the participant is an app user, return an AppUser instance
92
+ return AppUser(None, self.get_data("user"), **self._new_session_args)
45
93
  return User(None, self.get_data("user"), **self._new_session_args)
46
94
 
47
95
  @property
@@ -1,18 +1,20 @@
1
1
  # coding=utf-8
2
2
 
3
3
  from requests import HTTPError
4
- from ..base import BitbucketCloudBase
5
- from .issues import Issues
4
+
6
5
  from .branchRestrictions import BranchRestrictions
7
6
  from .commits import Commits
8
- from .hooks import Hooks
9
7
  from .defaultReviewers import DefaultReviewers
10
8
  from .deploymentEnvironments import DeploymentEnvironments
9
+ from .downloads import Downloads
11
10
  from .groupPermissions import GroupPermissions
11
+ from .hooks import Hooks
12
+ from .issues import Issues
12
13
  from .pipelines import Pipelines
13
14
  from .pullRequests import PullRequests
14
15
  from .refs import Branches, Tags
15
16
  from .repositoryVariables import RepositoryVariables
17
+ from ..base import BitbucketCloudBase
16
18
 
17
19
 
18
20
  class RepositoriesBase(BitbucketCloudBase):
@@ -277,6 +279,7 @@ class Repository(BitbucketCloudBase):
277
279
  f"{self.url}/pipelines_config/variables", **self._new_session_args
278
280
  )
279
281
  self.__tags = Tags(f"{self.url}/refs/tags", **self._new_session_args)
282
+ self.__downloads = Downloads(f"{self.url}/downloads", **self._new_session_args)
280
283
 
281
284
  def update(self, **kwargs):
282
285
  """
@@ -433,3 +436,8 @@ class Repository(BitbucketCloudBase):
433
436
  def tags(self):
434
437
  """The repository tags."""
435
438
  return self.__tags
439
+
440
+ @property
441
+ def downloads(self):
442
+ """The repository downloads"""
443
+ return self.__downloads
@@ -3,7 +3,7 @@
3
3
  from ..base import BitbucketCloudBase
4
4
  from ..common.builds import Build
5
5
  from ..common.comments import Comment
6
- from ..common.users import Participant, User
6
+ from ..common.users import Participant, User, AppUser
7
7
 
8
8
 
9
9
  class Commits(BitbucketCloudBase):
@@ -89,6 +89,9 @@ class Commit(BitbucketCloudBase):
89
89
  @property
90
90
  def author(self):
91
91
  """User object of the author."""
92
+ if self.get_data("author")["type"] == "app_user":
93
+ # If the author is an app user, return an AppUser instance
94
+ return AppUser(None, self.get_data("author").get("user"), **self._new_session_args)
92
95
  return User(None, self.get_data("author").get("user"))
93
96
 
94
97
  def parents(self):
@@ -0,0 +1,75 @@
1
+ from datetime import datetime
2
+
3
+ from ..base import BitbucketCloudBase
4
+ from ..common.users import AppUser
5
+
6
+
7
+ class Download(BitbucketCloudBase):
8
+ def __init__(self, url, data, *args, **kwargs):
9
+ super(Download, self).__init__(url, *args, data=data, expected_type="download", **kwargs)
10
+
11
+ @property
12
+ def name(self):
13
+ """The download file name"""
14
+ return self.get_data("name")
15
+
16
+ @property
17
+ def size(self):
18
+ """The download size in bytes"""
19
+ return self.get_data("size")
20
+
21
+ @property
22
+ def created_on(self):
23
+ """The download created date"""
24
+ created_on = self.get_data("created_on")
25
+ if created_on is None:
26
+ return None
27
+ return datetime.strptime(created_on, self.CONF_TIMEFORMAT)
28
+
29
+ @property
30
+ def user(self):
31
+ """The user who created this download"""
32
+ return AppUser(None, self.get_data("user"))
33
+
34
+ @property
35
+ def downloads(self):
36
+ """The number of times this file was downloaded"""
37
+ return self.get_data("downloads")
38
+
39
+ @property
40
+ def links(self):
41
+ """The download links"""
42
+ return self.get_data("links")
43
+
44
+ def get_content(self):
45
+ """Download file content"""
46
+ return self.get(self.url, absolute=True)
47
+
48
+
49
+ class Downloads(BitbucketCloudBase):
50
+ def __init__(self, url, *args, **kwargs):
51
+ super(Downloads, self).__init__(url, *args, **kwargs)
52
+
53
+ def __get_object(self, data):
54
+ url = self.url_joiner(self.url, data["name"])
55
+ if data["links"] and data["links"]["self"] and data["links"]["self"]["href"]:
56
+ url = data["links"]["self"]["href"]
57
+
58
+ return Download(
59
+ url,
60
+ data,
61
+ **self._new_session_args
62
+ ) # fmt: skip
63
+
64
+ def each(self):
65
+ """
66
+ Returns the list of downloads in this repository.
67
+
68
+ :return: A generator for the Download objects
69
+
70
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-downloads/#api-repositories-workspace-repo-slug-downloads-get
71
+ """
72
+ for issue in self._get_paged(None):
73
+ yield self.__get_object(issue)
74
+
75
+ return
@@ -5,7 +5,7 @@ from .diffstat import DiffStat
5
5
  from ...cloud.repositories.commits import Commit
6
6
  from ..common.builds import Build
7
7
  from ..common.comments import Comment
8
- from ..common.users import User, Participant
8
+ from ..common.users import User, Participant, AppUser
9
9
 
10
10
 
11
11
  class PullRequests(BitbucketCloudBase):
@@ -209,6 +209,9 @@ class PullRequest(BitbucketCloudBase):
209
209
  @property
210
210
  def author(self):
211
211
  """User object of the author"""
212
+ if self.get_data("author")["type"] == "app_user":
213
+ # If the author is an app user, return an AppUser instance
214
+ return AppUser(None, self.get_data("author"), **self._new_session_args)
212
215
  return User(None, self.get_data("author"))
213
216
 
214
217
  @property
@@ -451,11 +454,17 @@ class Task(BitbucketCloudBase):
451
454
  @property
452
455
  def creator(self):
453
456
  """User object with user information of the task creator"""
457
+ if self.get_data("creator")["type"] == "app_user":
458
+ # If the creator is an app user, return an AppUser instance
459
+ return AppUser(None, self.get_data("creator"), **self._new_session_args)
454
460
  return User(None, self.get_data("creator"), **self._new_session_args)
455
461
 
456
462
  @property
457
463
  def resolved_by(self):
458
464
  """User object with user information of the task resolver"""
465
+ if self.get_data("resolved_by")["type"] == "app_user":
466
+ # If the resolver is an app user, return an AppUser instance
467
+ return AppUser(None, self.get_data("resolved_by"), **self._new_session_args)
459
468
  return User(None, self.get_data("resolved_by"), **self._new_session_args)
460
469
 
461
470
  def update(self, raw_message):
@@ -1,7 +1,7 @@
1
1
  # coding=utf-8
2
2
 
3
3
  from ..base import BitbucketCloudBase
4
- from ..common.users import User
4
+ from ..common.users import User, AppUser
5
5
 
6
6
 
7
7
  class Refs(BitbucketCloudBase):
@@ -120,6 +120,9 @@ class Branch(Ref):
120
120
  @property
121
121
  def author(self):
122
122
  """User object of the author."""
123
+ if self.get_data("author")["type"] == "app_user":
124
+ # If the author is an app user, return an AppUser instance
125
+ return AppUser(None, self.get_data("author").get("user"), **self._new_session_args)
123
126
  return User(None, self.get_data("author"))
124
127
 
125
128
 
@@ -5,6 +5,7 @@ import logging
5
5
  import os
6
6
  import re
7
7
  import time
8
+ import warnings
8
9
  from typing import cast
9
10
 
10
11
  import requests
@@ -13,16 +14,23 @@ from deprecated import deprecated
13
14
  from requests import HTTPError
14
15
 
15
16
  from atlassian import utils
16
-
17
- from .errors import (
17
+ from atlassian.errors import (
18
18
  ApiConflictError,
19
19
  ApiError,
20
20
  ApiNotAcceptable,
21
21
  ApiNotFoundError,
22
22
  ApiPermissionError,
23
23
  ApiValueError,
24
+ JsonRPCError,
25
+ JsonRPCRestrictionsError,
24
26
  )
25
- from .rest_client import AtlassianRestAPI
27
+ from atlassian.rest_client import AtlassianRestAPI
28
+ import sys
29
+
30
+ if sys.version_info >= (3, 8):
31
+ from typing import Literal # Python 3.8+
32
+ else:
33
+ from typing_extensions import Literal # Python <=3.7
26
34
 
27
35
  log = logging.getLogger(__name__)
28
36
 
@@ -674,7 +682,7 @@ class Confluence(AtlassianRestAPI):
674
682
  all_pages.extend(results) # Add the current batch of pages to the list
675
683
 
676
684
  # Break the loop if no more pages are available
677
- if len(results) < limit:
685
+ if len(results) <= limit:
678
686
  break
679
687
 
680
688
  # Increment the start index for the next batch
@@ -860,6 +868,160 @@ class Confluence(AtlassianRestAPI):
860
868
  url = f"rest/api/content/{content_id}/restriction/byOperation"
861
869
  return self.get(url)
862
870
 
871
+ def get_all_restrictions_from_page_json_rpc(self, page_id):
872
+ """
873
+ The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to.
874
+ JSON-RPC APIs operate differently than REST APIs.
875
+ To learn more about how to use these APIs,
876
+ please refer to the Confluence JSON-RPC documentation on Atlassian Developers.
877
+ """
878
+ if self.api_version == "cloud" or self.cloud:
879
+ return {}
880
+ url = "rpc/json-rpc/confluenceservice-v2"
881
+ data = {"jsonrpc": "2.0", "method": "getContentPermissionSets", "id": 9, "params": [page_id]}
882
+ return self.post(url, data=data).get("result") or {}
883
+
884
+ def update_restrictions_for_page_json_rpc(self, page_id, permission_type, content_permissions):
885
+ """
886
+ The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to.
887
+ JSON-RPC APIs operate differently than REST APIs.
888
+ To learn more about how to use these APIs,
889
+ please refer to the Confluence JSON-RPC documentation on Atlassian Developers.
890
+ """
891
+ if self.api_version == "cloud" or self.cloud:
892
+ return {}
893
+ url = "rpc/json-rpc/confluenceservice-v2"
894
+ data = {
895
+ "jsonrpc": "2.0",
896
+ "method": "setContentPermissions",
897
+ "id": 9,
898
+ "params": [page_id, permission_type, content_permissions],
899
+ }
900
+ return self.post(url, data=data).get("result") or {}
901
+
902
+ def get_users_from_restricts_in_page_by_type(self, page_id: str, restriction_type: Literal["View", "Edit"]):
903
+ page_name = self.get_page_by_id(page_id=page_id)["title"]
904
+ restrictions_in_page = self.get_all_restrictions_from_page_json_rpc(page_id=page_id)
905
+ try:
906
+ if len(restrictions_in_page) > 0:
907
+ for restriction_type_in_page in restrictions_in_page:
908
+ if dict(restriction_type_in_page).get("type") == restriction_type:
909
+ users = dict(restriction_type_in_page).get("contentPermissions")
910
+ return users
911
+ else:
912
+ raise JsonRPCRestrictionsError(
913
+ f'On page "{page_name}" has no restrictions type of "{restriction_type}"'
914
+ )
915
+ except JsonRPCError:
916
+ raise
917
+
918
+ def create_restricts_from_from_user(self, user_name: str, restriction_type: Literal["View", "Edit"]):
919
+ content = {"type": restriction_type, "userName": user_name, "groupName": None}
920
+
921
+ return content
922
+
923
+ def add_user_in_restricted_page(self, user_name: str, page_id: str, restriction_type: Literal["View", "Edit"]):
924
+ page_name = self.get_page_by_id(page_id=page_id).get("title")
925
+ user_find_view_bool = False
926
+ user_find_edit_bool = False
927
+ users_content_view: list = self.get_users_from_restricts_in_page_by_type(
928
+ page_id=page_id, restriction_type="View"
929
+ )
930
+ users_content_edit: list = self.get_users_from_restricts_in_page_by_type(
931
+ page_id=page_id, restriction_type="Edit"
932
+ )
933
+ current_user_content_view: dict = self.create_restricts_from_from_user(
934
+ user_name=user_name, restriction_type="View"
935
+ )
936
+ current_user_content_edit: dict = self.create_restricts_from_from_user(
937
+ user_name=user_name, restriction_type="Edit"
938
+ )
939
+ try:
940
+ if None not in [users_content_view, users_content_edit]:
941
+ if users_content_view is not None:
942
+ for user in users_content_view:
943
+ if dict(user).get("userName") == current_user_content_view.get("userName"):
944
+ user_find_view_bool = True
945
+ if users_content_edit is not None:
946
+ for user in users_content_edit:
947
+ if dict(user).get("userName") == current_user_content_edit.get("userName"):
948
+ user_find_edit_bool = True
949
+ if restriction_type == "View":
950
+ if user_find_view_bool is False:
951
+ current_user_content = self.create_restricts_from_from_user(
952
+ user_name=user_name, restriction_type=restriction_type
953
+ )
954
+ users_content_view.append(current_user_content)
955
+ self.update_restrictions_for_page_json_rpc(
956
+ page_id=page_id,
957
+ permission_type=restriction_type,
958
+ content_permissions=users_content_view,
959
+ )
960
+ elif user_find_view_bool:
961
+ raise JsonRPCRestrictionsError(
962
+ f'User "{user_name}" already have restrictions type of "{restriction_type}" on page "{page_name}"'
963
+ )
964
+ elif restriction_type == "Edit":
965
+ if not user_find_edit_bool:
966
+ current_user_content_view = self.create_restricts_from_from_user(
967
+ user_name=user_name, restriction_type="View"
968
+ )
969
+ current_user_content_edit = self.create_restricts_from_from_user(
970
+ user_name=user_name, restriction_type=restriction_type
971
+ )
972
+ users_content_view.append(current_user_content_view)
973
+ users_content_edit.append(current_user_content_edit)
974
+ self.update_restrictions_for_page_json_rpc(
975
+ page_id=page_id, permission_type="View", content_permissions=users_content_view
976
+ )
977
+ self.update_restrictions_for_page_json_rpc(
978
+ page_id=page_id, permission_type=restriction_type, content_permissions=users_content_edit
979
+ )
980
+ print(
981
+ f'User "{user_name}" granted restrictions type of "{restriction_type}" on page "{page_name}"'
982
+ )
983
+ elif user_find_edit_bool:
984
+ raise JsonRPCRestrictionsError(
985
+ f'User "{user_name}" already have restrictions type of "{restriction_type}" on page "{page_name}"'
986
+ )
987
+ except JsonRPCError:
988
+ raise
989
+
990
+ def remove_user_from_restricted_page(self, user_name: str, page_id: str):
991
+ page_name = self.get_page_by_id(page_id=page_id).get("title")
992
+ user_find_bool = False
993
+ users_content_view: list = self.get_users_from_restricts_in_page_by_type(
994
+ page_id=page_id, restriction_type="View"
995
+ )
996
+ users_content_edit: list = self.get_users_from_restricts_in_page_by_type(
997
+ page_id=page_id, restriction_type="Edit"
998
+ )
999
+ current_user_content_view = self.create_restricts_from_from_user(user_name=user_name, restriction_type="View")
1000
+ current_user_content_edit = self.create_restricts_from_from_user(user_name=user_name, restriction_type="Edit")
1001
+ for user_index, user_value in enumerate(users_content_view):
1002
+ if dict(user_value).get("userName") == current_user_content_view.get("userName"):
1003
+ user_find_bool = True
1004
+ users_content_view.pop(user_index)
1005
+ for user_index, user_value in enumerate(users_content_edit):
1006
+ if dict(user_value).get("userName") == current_user_content_edit.get("userName"):
1007
+ user_find_bool = True
1008
+ users_content_edit.pop(user_index)
1009
+ try:
1010
+ if user_find_bool:
1011
+ self.update_restrictions_for_page_json_rpc(
1012
+ page_id=page_id, permission_type="View", content_permissions=users_content_view
1013
+ )
1014
+ self.update_restrictions_for_page_json_rpc(
1015
+ page_id=page_id, permission_type="Edit", content_permissions=users_content_edit
1016
+ )
1017
+ print(f'User "{user_name}" has been deleted from restrictions on page "{page_name}"')
1018
+ elif not user_find_bool:
1019
+ raise JsonRPCRestrictionsError(
1020
+ f'User "{user_name}" has not founded in restrictions on page "{page_name}"'
1021
+ )
1022
+ except JsonRPCError:
1023
+ raise
1024
+
863
1025
  def remove_page_from_trash(self, page_id):
864
1026
  """
865
1027
  This method removes a page from trash
@@ -1570,6 +1732,15 @@ class Confluence(AtlassianRestAPI):
1570
1732
  file_obj = io.BytesIO(response)
1571
1733
  downloaded_files[file_name] = file_obj
1572
1734
  else:
1735
+ # Sanitize filename if needed
1736
+ if re.search(r'[<>:"/\\|?*\x00-\x1F]', file_name):
1737
+ sanitized = re.sub(r'[<>:"/\\|?*\x00-\x1F]', "_", file_name)
1738
+ warnings.warn(
1739
+ f"File name '{file_name}' contained invalid characters and was renamed to '{sanitized}'.",
1740
+ UserWarning,
1741
+ )
1742
+ file_name = sanitized
1743
+ file_path = os.path.join(path, file_name)
1573
1744
  # Save file to disk
1574
1745
  file_path = os.path.join(path, file_name)
1575
1746
  with open(file_path, "wb") as file:
@@ -3689,6 +3860,24 @@ class Confluence(AtlassianRestAPI):
3689
3860
 
3690
3861
  return self.post(url, data=data, headers=self.experimental_headers)
3691
3862
 
3863
+ def add_space_permission_json_rpc(self, space_key, user, permission):
3864
+ """
3865
+ The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to.
3866
+ JSON-RPC APIs operate differently than REST APIs.
3867
+ To learn more about how to use these APIs,
3868
+ please refer to the Confluence JSON-RPC documentation on Atlassian Developers.
3869
+ """
3870
+ if self.api_version == "cloud" or self.cloud:
3871
+ return {}
3872
+ url = "rpc/json-rpc/confluenceservice-v2"
3873
+ data = {
3874
+ "jsonrpc": "2.0",
3875
+ "method": "addPermissionToSpace",
3876
+ "id": 9,
3877
+ "params": [permission, user, space_key],
3878
+ }
3879
+ return self.post(url, data=data).get("result") or {}
3880
+
3692
3881
  def remove_space_permission(self, space_key, user, permission):
3693
3882
  """
3694
3883
  The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to.
atlassian/errors.py CHANGED
@@ -7,6 +7,11 @@ class ApiError(Exception):
7
7
  super(ApiError, self).__init__(*args)
8
8
 
9
9
 
10
+ class JsonRPCError(Exception):
11
+ def __init__(self, *args):
12
+ super(JsonRPCError, self).__init__(*args)
13
+
14
+
10
15
  class ApiNotFoundError(ApiError):
11
16
  pass
12
17
 
@@ -25,3 +30,7 @@ class ApiConflictError(ApiError):
25
30
 
26
31
  class ApiNotAcceptable(ApiError):
27
32
  pass
33
+
34
+
35
+ class JsonRPCRestrictionsError(JsonRPCError):
36
+ pass
atlassian/insight.py CHANGED
@@ -28,7 +28,7 @@ class Insight(AtlassianRestAPI):
28
28
 
29
29
  def __cloud_init(self, *args, **kwargs):
30
30
  """
31
- Creates a InsightCloud specific version of Insight()
31
+ Creates an InsightCloud specific version of Insight()
32
32
 
33
33
  Returns:
34
34
  Insight(AtlassianRestAPI)
atlassian/jira.py CHANGED
@@ -7,8 +7,12 @@ from warnings import warn
7
7
 
8
8
  from deprecated import deprecated
9
9
  from requests import HTTPError, Response
10
- from typing_extensions import Literal
10
+ import sys
11
11
 
12
+ if sys.version_info >= (3, 8):
13
+ from typing import Literal # Python 3.8+
14
+ else:
15
+ from typing_extensions import Literal # Python <=3.7
12
16
  from .errors import ApiNotFoundError, ApiPermissionError
13
17
  from .rest_client import AtlassianRestAPI
14
18
  from .typehints import T_id, T_resp_json
@@ -2058,6 +2062,16 @@ class Jira(AtlassianRestAPI):
2058
2062
  url = f"{base_url}/{issue_key}/transitions"
2059
2063
  return self.post(url, data={"transition": {"id": transition_id}})
2060
2064
 
2065
+ def set_issue_status_by_transition_name(self, issue_key: str, transition_name: str):
2066
+ """
2067
+ Setting status by transition_name
2068
+ :param issue_key: str
2069
+ :param transition_name: str
2070
+ """
2071
+ base_url = self.resource_url("issue")
2072
+ url = f"{base_url}/{issue_key}/transitions"
2073
+ return self.post(url, data={"transition": {"name": transition_name}})
2074
+
2061
2075
  def get_issue_status(self, issue_key: str):
2062
2076
  base_url = self.resource_url("issue")
2063
2077
  url = f"{base_url}/{issue_key}?fields=status"
@@ -3545,7 +3559,10 @@ class Jira(AtlassianRestAPI):
3545
3559
  params["expand"] = expand
3546
3560
  if validate_query is not None:
3547
3561
  params["validateQuery"] = validate_query
3548
- url = self.resource_url("search")
3562
+ if self.cloud:
3563
+ url = self.resource_url("search")
3564
+ else:
3565
+ url = self.resource_url("search/jql")
3549
3566
  return self.get(url, params=params)
3550
3567
 
3551
3568
  def enhanced_jql(
@@ -3605,6 +3622,39 @@ class Jira(AtlassianRestAPI):
3605
3622
  url = self.resource_url("search/approximate-count")
3606
3623
  return self.post(url, data)
3607
3624
 
3625
+ def match_jql(self, issue_ids: List[int], jqls: List[str]) -> Optional[dict[Any, Any]]:
3626
+ """
3627
+ Checks which issues match a list of JQL queries.
3628
+
3629
+ This method corresponds to the /rest/api/3/jql/match endpoint.
3630
+ It helps you verify if a set of issues would be returned by given JQL queries.
3631
+
3632
+ :param issue_ids: A list of issue IDs to be checked against the JQLs.
3633
+ :param jqls: A list of JQL query strings to match.
3634
+ :return: A dictionary containing the matching results from the API.
3635
+ For example:
3636
+ {
3637
+ "errors": [],
3638
+ "results": [
3639
+ {
3640
+ "matchedIssues": [10001],
3641
+ "errors": [],
3642
+ "jql": "project = FOO"
3643
+ },
3644
+ {
3645
+ "matchedIssues": ,
3646
+ "errors": [],
3647
+ "jql": "issuetype = Bug"
3648
+ }
3649
+ ]
3650
+ }
3651
+ """
3652
+ if not self.cloud:
3653
+ raise ValueError("``approximate_issue_count`` method is only available for Jira Cloud platform")
3654
+ payload = {"issueIds": issue_ids, "jqls": jqls}
3655
+ url = self.resource_url("jql/match")
3656
+ return self.post(url, data=payload)
3657
+
3608
3658
  def jql_get_list_of_tickets(
3609
3659
  self,
3610
3660
  jql: str,
@@ -3651,7 +3701,10 @@ class Jira(AtlassianRestAPI):
3651
3701
  params["expand"] = expand
3652
3702
  if validate_query is not None:
3653
3703
  params["validateQuery"] = validate_query
3654
- url = self.resource_url("search")
3704
+ if self.cloud:
3705
+ url = self.resource_url("search")
3706
+ else:
3707
+ url = self.resource_url("search/jql")
3655
3708
 
3656
3709
  results: List[object] = []
3657
3710
  while True:
@@ -5792,3 +5845,18 @@ api-group-workflows/#api-rest-api-2-workflow-search-get)
5792
5845
  """
5793
5846
  response = self.get("rest/api/2/user/duplicated/count")
5794
5847
  return response
5848
+
5849
+ def dark_feature_management(self, key: str, enable: bool = True) -> T_resp_json:
5850
+ """
5851
+ Dark Feature Management
5852
+ https://confluence.atlassian.com/jirakb/dark-feature-management-1063554355.html
5853
+ https://confluence.atlassian.com/jirakb/how-to-manage-dark-features-in-jira-server-and-data-center-959286331.html
5854
+ i.e. sd.sla.improved.rendering.enabled
5855
+ :return:
5856
+ """
5857
+ if enable:
5858
+ data = {"enabled": "true"}
5859
+ else:
5860
+ data = {"enabled": "false"}
5861
+ response = self.put(f"/rest/internal/1.0/darkFeatures/{key}", data=data)
5862
+ return response
atlassian/rest_client.py CHANGED
@@ -1,4 +1,5 @@
1
1
  # coding=utf-8
2
+
2
3
  import logging
3
4
  import random
4
5
  import time
@@ -13,11 +14,15 @@ from typing import (
13
14
  overload,
14
15
  )
15
16
  from urllib.parse import urlencode
16
-
17
+ import sys
17
18
  import requests
18
19
  import urllib3
19
20
  from requests.adapters import HTTPAdapter
20
- from typing_extensions import Literal
21
+
22
+ if sys.version_info >= (3, 8):
23
+ from typing import Literal # Python 3.8+
24
+ else:
25
+ from typing_extensions import Literal # Python <=3.7
21
26
 
22
27
  from atlassian.typehints import T_resp_json
23
28
 
@@ -78,7 +83,7 @@ class AtlassianRestAPI(object):
78
83
  api_root: str = "rest/api",
79
84
  api_version: Union[str, int] = "latest",
80
85
  verify_ssl: bool = True,
81
- session: Optional[requests.Session] = None,
86
+ session: Optional[requests.Session] = requests.Session(),
82
87
  oauth: Optional[dict] = None,
83
88
  oauth2: Optional[dict] = None,
84
89
  cookies: Optional[CookieJar] = None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: atlassian-python-api
3
- Version: 4.0.4
3
+ Version: 4.0.6
4
4
  Summary: Python Atlassian REST API Wrapper
5
5
  Home-page: https://github.com/atlassian-api/atlassian-python-api
6
6
  Download-URL: https://github.com/atlassian-api/atlassian-python-api
@@ -8,7 +8,7 @@ Author: Matt Harasymczuk
8
8
  Author-email: matt@astrotech.io
9
9
  Maintainer: Gonchik Tsymzhitov
10
10
  Maintainer-email: gonchik.tsymzhitov@gmail.com
11
- License: Apache License 2.0
11
+ License: Apache-2.0
12
12
  Keywords: atlassian jira core software confluence bitbucket bamboo crowd portfolio tempo servicedesk assets api
13
13
  Platform: Platform Independent
14
14
  Classifier: Development Status :: 4 - Beta
@@ -82,7 +82,7 @@ and is compatible with both Atlassian Server and Cloud instances.
82
82
 
83
83
  Overall, the **atlassian-python-api** is a useful tool for Python developers who want to work with Atlassian products.
84
84
  It is well-documented and actively maintained, and provides a convenient way to access the full range of
85
- functionality offered by the Atlassian REST APIs.
85
+ functionality offered by the Atlassian REST APIs and made with love for Atlassian.
86
86
 
87
87
 
88
88
  Documentation
@@ -1,43 +1,43 @@
1
- atlassian/VERSION,sha256=BUWrE3vwGh4ju-66o40bVH0h2u09uw_rI1ndBpj4XPw,5
1
+ atlassian/VERSION,sha256=YMHNtaPhTP-lMMqGnKNyXk_q6TDsyXkog0aHYOdpQnA,5
2
2
  atlassian/__init__.py,sha256=CpswvfzfMsXkY0aaM-ywYqsVE82OJrLiFCFOFDTt8qI,906
3
3
  atlassian/assets.py,sha256=P3Cm9UnR1dbcoRm0uZvOnZzcY2TSxJ_iH2llYqEF7Ck,21611
4
4
  atlassian/bamboo.py,sha256=-KlqEJsMV1ZsM-em-6NmuU1JjBrO7seu07I5byus2rY,48018
5
5
  atlassian/cloud_admin.py,sha256=pRLPR1-pOdvnH-H56PxtTrtW1ok_HrM2LCmvsyLlzss,4054
6
- atlassian/confluence.py,sha256=8x-YOb3v9qy-7G2RWyekFWwy1djLPsAR5TqYM3xHrb4,144666
7
6
  atlassian/crowd.py,sha256=hsLqcmKLm-qWK3xV1pDYCeGcvUIR8k6DJkMlwcDn8QM,9255
8
- atlassian/errors.py,sha256=GAKr6W4zPn7ZUMRLHG8-UgAdVnxDzKVZ-jyGXAccALE,398
9
- atlassian/insight.py,sha256=fCR9IXmatTp6-l-pOeLFFQGgBeafSzBdkgIHLWkOXEo,23398
10
- atlassian/jira.py,sha256=AFYq8YUkoHf6v9un7A4QGnFMFQQ-gjdgqaNyxsYTLPc,226640
7
+ atlassian/errors.py,sha256=5Ob7l1ZCF2-mjejJyVt0bkvDZxoUGZVaMdLpeFxasVk,569
8
+ atlassian/insight.py,sha256=H9ZZz73A6jXcvM2ng8Mho5jWHOljB3XIjFCki3t_6ic,23399
9
+ atlassian/jira.py,sha256=wCg3uEHO09rDl_3_FqkMcLiweA18Cxk2rtsnd58pyQk,229359
11
10
  atlassian/marketplace.py,sha256=dLm4I8GROkdhyu3BdGtK_ssq1g44KZFi8S0HS_ZepLs,2540
12
11
  atlassian/portfolio.py,sha256=q38sFFC7DHmHM4vsFzl8sT7HcRRGKH3tT5nRlqltDzc,3696
13
12
  atlassian/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
13
  atlassian/request_utils.py,sha256=eDWGtbbhGGoqQOqqqclaO7vuJRexzIZeTAYu7aluDuw,510
15
- atlassian/rest_client.py,sha256=720jRpJ-Fq6lKNQsom4BomD2XEnzgtjE9JjTeFh52uI,34086
14
+ atlassian/rest_client.py,sha256=V67HSgaOFcti0QYtbdeMK42Pu_kjzf-iHZoGCjH4QTs,34215
16
15
  atlassian/service_desk.py,sha256=gPC2fehnrFvWLA-mg0Ca_l3GzHd5PG_1m7OCTApqTC8,32987
17
16
  atlassian/statuspage.py,sha256=4zXsrpPVgbaOmBoS7GBgaO389rUnuCwKeSwEVS-SFyg,93560
18
17
  atlassian/typehints.py,sha256=zmAjrhp5kjiquAEYZiv1iPXCaq5GqWYrdpLXeeILYuQ,180
19
18
  atlassian/utils.py,sha256=3Qm_UCn0pDgLZOKle4IeG6-9zXz0bu-_x4rXb5Iczpg,10897
20
19
  atlassian/xray.py,sha256=JjTcYevIwYXb3B3PUQJdZDjRRo2vcCW01qq0Wo5daRk,26991
21
- atlassian/bitbucket/__init__.py,sha256=bh7i8yjgCpyxz1VGCALqDdjsPrlWe5zV-xXXCg0bGnc,135925
20
+ atlassian/bitbucket/__init__.py,sha256=JygO7iLOb-FjYYu6TLVyv8cuNlqGXNGxKwY2GOJ6zek,136135
22
21
  atlassian/bitbucket/base.py,sha256=z_8fX2w2r_MClMMmrm4rM5JrNoY0pIc07rFvPhuZU0E,6489
23
22
  atlassian/bitbucket/cloud/__init__.py,sha256=IDw6mMXXaI_KipT08Ff5duS2NiKoSX1F0HqZKsilJQA,851
24
23
  atlassian/bitbucket/cloud/base.py,sha256=zG50qqMgqyV2KJdUxn5KIdTBLA26wq0-Tk1gyBq8k9g,4267
25
24
  atlassian/bitbucket/cloud/common/__init__.py,sha256=xhpE0cKTpx6a1jjazmjIexNFuq0a5gpzefmM_NnH7fw,37
26
25
  atlassian/bitbucket/cloud/common/builds.py,sha256=S9Ox26WDiFjdHU9XqEVQz7ddC4LV3f4h55L9-ITIAnE,2374
27
- atlassian/bitbucket/cloud/common/comments.py,sha256=ktnN9G0Vr49rIAeqTElnEXvpePp6roUw_Om06JnEb-4,1329
28
- atlassian/bitbucket/cloud/common/users.py,sha256=BbjkMeNFp7JwuewbKL_5qO1geuZ5iu3u5AThPu1pYJo,2390
29
- atlassian/bitbucket/cloud/repositories/__init__.py,sha256=WoSIpOWpz8KHTsa9RjQFFeSqdq8hu_tYpycx0HilTj8,17008
26
+ atlassian/bitbucket/cloud/common/comments.py,sha256=O140p9sstUBBlB0rwHpspYVXfoxRD6heeP3oyOShRSA,1578
27
+ atlassian/bitbucket/cloud/common/users.py,sha256=Z1lX4vgriAh9cJlHVMra4CcgSe9Sj1x-DpMa7623oIU,3720
28
+ atlassian/bitbucket/cloud/repositories/__init__.py,sha256=9xZM6DUdAzj_GThgOfABm-uAYz4pMO9DrIznuvmD4GU,17241
30
29
  atlassian/bitbucket/cloud/repositories/branchRestrictions.py,sha256=Gr0_DYIQHtd2lyVEBqUiUXg6Y_xumRn10UgKo6iF8ck,6535
31
- atlassian/bitbucket/cloud/repositories/commits.py,sha256=RvwTr7dMzQEuuZ6DFMfCfPhv33o7r1rtsPIT5es16dI,7752
30
+ atlassian/bitbucket/cloud/repositories/commits.py,sha256=DVGHC5rSdK5blUgl32jJmPs9-xsAIEGeRFc_2bHPNeQ,7986
32
31
  atlassian/bitbucket/cloud/repositories/defaultReviewers.py,sha256=MLjjZP8wkIX8wYh87IpXrYXUVgZcld8AbJU1AC1u-VE,3592
33
32
  atlassian/bitbucket/cloud/repositories/deploymentEnvironments.py,sha256=eouHjBORdEJSyuccUy2Gsdm-ZdKkvJ7oJmj8P6fWtKk,9385
34
33
  atlassian/bitbucket/cloud/repositories/diffstat.py,sha256=tzi9mDC71Jps-Lj_UdvR3mUb1nFlbN2DZ1bjHfGu26A,2893
34
+ atlassian/bitbucket/cloud/repositories/downloads.py,sha256=Uc3wbKslt-fk6DLD3pIqW3cL5WBdg85KNEgY6_mmIYE,2159
35
35
  atlassian/bitbucket/cloud/repositories/groupPermissions.py,sha256=yMSlQKvrQ5rFx3eD-pJuMR2QdzotTAAV8KCR6KOGHU4,2696
36
36
  atlassian/bitbucket/cloud/repositories/hooks.py,sha256=quPT8F9la2Vz5Rh-CUsUwC7V_7U3Zv9VSTSmcDGX9_w,3193
37
37
  atlassian/bitbucket/cloud/repositories/issues.py,sha256=rJzPfhETsI7qqi9xyo_MwaTPnwxmQe2pyBYTLyMf9Eg,5065
38
38
  atlassian/bitbucket/cloud/repositories/pipelines.py,sha256=dqGkOauMtr1Baue7ICtW7KQ0EaW-3aj2Hln3dCrFexM,9129
39
- atlassian/bitbucket/cloud/repositories/pullRequests.py,sha256=NwQSQwRkpfRcUTQ5QnuL-xpQydjLeDt2kE47Nf72o78,16245
40
- atlassian/bitbucket/cloud/repositories/refs.py,sha256=hrZKaXa7_7PYO7bNGkdq6onF8YB46eBhLd56o1miEfY,4013
39
+ atlassian/bitbucket/cloud/repositories/pullRequests.py,sha256=WQBm6gTZXTIJkypUekdBsBBA5yWlUYprWV6KxYTg2iM,16908
40
+ atlassian/bitbucket/cloud/repositories/refs.py,sha256=1jMcPh03owE_NcMQXuhu0vo2h-sXyuhQaXB1DSUPvQ8,4247
41
41
  atlassian/bitbucket/cloud/repositories/repositoryVariables.py,sha256=6MAWI0vhJg71tKHVh-bfcaonXuy90lq3BEsjMl0rv2c,5088
42
42
  atlassian/bitbucket/cloud/workspaces/__init__.py,sha256=Pos5ktbVEqfcP6tTV5P-DzZL43ElDSjYT9y1CLgJnrM,5081
43
43
  atlassian/bitbucket/cloud/workspaces/members.py,sha256=fFP4ubBurFkMTDvZrQKSz5KN3cSVZnT1OBff2g8qYlE,1775
@@ -50,8 +50,9 @@ atlassian/bitbucket/server/common/__init__.py,sha256=woZpR3WXAA3A99hZ1UZI_gLPHaA
50
50
  atlassian/bitbucket/server/common/permissions.py,sha256=ve-hWRIrG0zSMo1hp2uTLHGO1PlXorzZlpt7Sc9KhJw,7300
51
51
  atlassian/bitbucket/server/projects/__init__.py,sha256=6G3MZBOTFpwx5x3chg-M8-BbmOnrdRZiZYp2YKJScbw,7668
52
52
  atlassian/bitbucket/server/projects/repos/__init__.py,sha256=RFnZ5APax9VXASYbHbMjW12L2NR4gWbXzS-c-KyExTI,10776
53
- atlassian_python_api-4.0.4.dist-info/licenses/LICENSE,sha256=xamAnoX0zfBamIilAfP3nSIt7dIvnj7oueX14l6uKPY,11335
54
- atlassian_python_api-4.0.4.dist-info/METADATA,sha256=GLBmpuqg276axHZX9mMzW4mn3tVi3XSMqcX3c4k7r0c,9500
55
- atlassian_python_api-4.0.4.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
56
- atlassian_python_api-4.0.4.dist-info/top_level.txt,sha256=84-EDv8LNaZx01TCGjBzglwPU1JSRJ7fPSq9uy55Sv0,10
57
- atlassian_python_api-4.0.4.dist-info/RECORD,,
53
+ atlassian/confluence/__init__.py,sha256=rAo1C5G5kJyBwfFvMcJCVy7i7eVz10itV1dB2y0AcTA,154600
54
+ atlassian_python_api-4.0.6.dist-info/licenses/LICENSE,sha256=xamAnoX0zfBamIilAfP3nSIt7dIvnj7oueX14l6uKPY,11335
55
+ atlassian_python_api-4.0.6.dist-info/METADATA,sha256=pZtch3ngfxwi3m6n6asKsfoav7xxDNvute77JElLiPc,9525
56
+ atlassian_python_api-4.0.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
57
+ atlassian_python_api-4.0.6.dist-info/top_level.txt,sha256=84-EDv8LNaZx01TCGjBzglwPU1JSRJ7fPSq9uy55Sv0,10
58
+ atlassian_python_api-4.0.6.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.4.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5