atlassian-python-api 3.41.10__py3-none-any.whl → 3.41.12__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 +1 -1
- atlassian/bitbucket/__init__.py +24 -1
- atlassian/bitbucket/cloud/repositories/__init__.py +11 -0
- atlassian/bitbucket/cloud/repositories/hooks.py +117 -0
- atlassian/confluence.py +41 -0
- atlassian/jira.py +172 -82
- atlassian/rest_client.py +56 -2
- {atlassian_python_api-3.41.10.dist-info → atlassian_python_api-3.41.12.dist-info}/METADATA +1 -1
- {atlassian_python_api-3.41.10.dist-info → atlassian_python_api-3.41.12.dist-info}/RECORD +12 -11
- {atlassian_python_api-3.41.10.dist-info → atlassian_python_api-3.41.12.dist-info}/WHEEL +1 -1
- {atlassian_python_api-3.41.10.dist-info → atlassian_python_api-3.41.12.dist-info}/LICENSE +0 -0
- {atlassian_python_api-3.41.10.dist-info → atlassian_python_api-3.41.12.dist-info}/top_level.txt +0 -0
atlassian/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.41.
|
|
1
|
+
3.41.12
|
atlassian/bitbucket/__init__.py
CHANGED
|
@@ -39,6 +39,26 @@ class Bitbucket(BitbucketBase):
|
|
|
39
39
|
def _url_admin(self, api_version=None):
|
|
40
40
|
return self.resource_url("admin", api_version=api_version)
|
|
41
41
|
|
|
42
|
+
def get_groups(self, group_filter=None, limit=25, start=0):
|
|
43
|
+
"""
|
|
44
|
+
Get list of bitbucket groups.
|
|
45
|
+
Use 'group_filter' for get specific group or get all group if necessary.
|
|
46
|
+
|
|
47
|
+
:param group_filter: str - groupname
|
|
48
|
+
:param limit: int - paginated limit to retrieve
|
|
49
|
+
:param start: int - paginated point to start retrieving
|
|
50
|
+
:return: The collection as JSON with all relevant information about the group
|
|
51
|
+
"""
|
|
52
|
+
url = self.resource_url("groups", api_version="1.0")
|
|
53
|
+
params = {}
|
|
54
|
+
if group_filter:
|
|
55
|
+
params["filter"] = group_filter
|
|
56
|
+
if limit:
|
|
57
|
+
params["limit"] = limit
|
|
58
|
+
if start:
|
|
59
|
+
params["start"] = start
|
|
60
|
+
return self._get_paged(url, params=params)
|
|
61
|
+
|
|
42
62
|
def group_members(self, group, start=0, limit=None):
|
|
43
63
|
"""
|
|
44
64
|
Get group of members
|
|
@@ -1781,7 +1801,10 @@ class Bitbucket(BitbucketBase):
|
|
|
1781
1801
|
:param start:
|
|
1782
1802
|
:return:
|
|
1783
1803
|
"""
|
|
1784
|
-
|
|
1804
|
+
if self.cloud:
|
|
1805
|
+
url = "{}/activity".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
|
|
1806
|
+
else:
|
|
1807
|
+
url = "{}/activities".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
|
|
1785
1808
|
params = {}
|
|
1786
1809
|
if start:
|
|
1787
1810
|
params["start"] = start
|
|
@@ -5,6 +5,7 @@ from ..base import BitbucketCloudBase
|
|
|
5
5
|
from .issues import Issues
|
|
6
6
|
from .branchRestrictions import BranchRestrictions
|
|
7
7
|
from .commits import Commits
|
|
8
|
+
from .hooks import Hooks
|
|
8
9
|
from .defaultReviewers import DefaultReviewers
|
|
9
10
|
from .deploymentEnvironments import DeploymentEnvironments
|
|
10
11
|
from .groupPermissions import GroupPermissions
|
|
@@ -259,6 +260,11 @@ class Repository(BitbucketCloudBase):
|
|
|
259
260
|
data={"links": {"commit": {"href": "{}/commit".format(self.url)}}},
|
|
260
261
|
**self._new_session_args
|
|
261
262
|
) # fmt: skip
|
|
263
|
+
self.__hooks = Hooks(
|
|
264
|
+
"{}/hooks".format(self.url),
|
|
265
|
+
data={"links": {"hooks": {"href": "{}/hooks".format(self.url)}}},
|
|
266
|
+
**self._new_session_args,
|
|
267
|
+
)
|
|
262
268
|
self.__default_reviewers = DefaultReviewers("{}/default-reviewers".format(self.url), **self._new_session_args)
|
|
263
269
|
self.__deployment_environments = DeploymentEnvironments(
|
|
264
270
|
"{}/environments".format(self.url), **self._new_session_args
|
|
@@ -385,6 +391,11 @@ class Repository(BitbucketCloudBase):
|
|
|
385
391
|
"""The repository commits."""
|
|
386
392
|
return self.__commits
|
|
387
393
|
|
|
394
|
+
@property
|
|
395
|
+
def hooks(self):
|
|
396
|
+
"""The repository hooks."""
|
|
397
|
+
return self.__hooks
|
|
398
|
+
|
|
388
399
|
@property
|
|
389
400
|
def default_reviewers(self):
|
|
390
401
|
"""The repository default reviewers"""
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
|
|
3
|
+
from ..base import BitbucketCloudBase
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Hooks(BitbucketCloudBase):
|
|
7
|
+
"""Bitbucket Cloud webhooks."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, url, *args, **kwargs):
|
|
10
|
+
super(Hooks, self).__init__(url, *args, **kwargs)
|
|
11
|
+
|
|
12
|
+
def __get_object(self, data):
|
|
13
|
+
return Hook(data, **self._new_session_args)
|
|
14
|
+
|
|
15
|
+
def create(
|
|
16
|
+
self,
|
|
17
|
+
url,
|
|
18
|
+
description,
|
|
19
|
+
events,
|
|
20
|
+
active=True,
|
|
21
|
+
):
|
|
22
|
+
"""
|
|
23
|
+
Creates a new webhook for the current repository
|
|
24
|
+
|
|
25
|
+
param: url: string: Url that will receive event requests
|
|
26
|
+
param: description: string: Details about the webhook
|
|
27
|
+
param: events: [string] List of event types that requests will generate for
|
|
28
|
+
param: active: boolean: Enables/Disables the webhook
|
|
29
|
+
|
|
30
|
+
:return: Hook Object
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
data = {"url": url, "description": description, "active": active, "events": events}
|
|
34
|
+
|
|
35
|
+
return self.__get_object(self.post(None, data))
|
|
36
|
+
|
|
37
|
+
def each(self):
|
|
38
|
+
"""
|
|
39
|
+
Return the list of webhooks in this repository.
|
|
40
|
+
|
|
41
|
+
:return: A generator for the Webhook objects
|
|
42
|
+
"""
|
|
43
|
+
for hook in self._get_paged(None):
|
|
44
|
+
yield self.__get_object(hook)
|
|
45
|
+
|
|
46
|
+
def get(self, id):
|
|
47
|
+
"""
|
|
48
|
+
Return the hook with the requested hook uuid in this repository.
|
|
49
|
+
|
|
50
|
+
:param id: string: The id of the webhook
|
|
51
|
+
|
|
52
|
+
:return: The requested hook object
|
|
53
|
+
"""
|
|
54
|
+
return self.__get_object(
|
|
55
|
+
super(Hooks, self).get(
|
|
56
|
+
self.url_joiner(self.get_link("hooks"), id),
|
|
57
|
+
absolute=True,
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Hook(BitbucketCloudBase):
|
|
63
|
+
"""
|
|
64
|
+
Bitbucket Cloud hook endpoint.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
def __init__(self, data, *args, **kwargs):
|
|
68
|
+
super(Hook, self).__init__(None, *args, data=data, expected_type="webhook_subscription", **kwargs)
|
|
69
|
+
|
|
70
|
+
def uuid(self):
|
|
71
|
+
"""hook uuid."""
|
|
72
|
+
return self.get_data("uuid")
|
|
73
|
+
|
|
74
|
+
def webhook_url(self):
|
|
75
|
+
"""webhook url."""
|
|
76
|
+
return self.get_data("url")
|
|
77
|
+
|
|
78
|
+
def description(self):
|
|
79
|
+
"""webhook description."""
|
|
80
|
+
return self.get_data("description")
|
|
81
|
+
|
|
82
|
+
def active(self):
|
|
83
|
+
"""is webhook active?"""
|
|
84
|
+
return self.get_data("active")
|
|
85
|
+
|
|
86
|
+
def events(self):
|
|
87
|
+
"""events that the webhook is triggered by"""
|
|
88
|
+
return self.get_data("events")
|
|
89
|
+
|
|
90
|
+
def update(self, **kwargs):
|
|
91
|
+
"""
|
|
92
|
+
Update a webhook
|
|
93
|
+
|
|
94
|
+
Valid keywords:
|
|
95
|
+
param: url: string: Url that will receive event requests
|
|
96
|
+
param: description: string: Details about the webhook
|
|
97
|
+
param: events: [string] List of event types that requests will generate for
|
|
98
|
+
param: active: boolean: Enables/Disables the webhook
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
payload = {
|
|
102
|
+
"url": self.webhook_url(),
|
|
103
|
+
"description": self.description(),
|
|
104
|
+
"events": self.events(),
|
|
105
|
+
"active": self.active(),
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
for key in payload.keys() and kwargs.keys():
|
|
109
|
+
payload[key] = kwargs[key]
|
|
110
|
+
|
|
111
|
+
return self._update_data(self.put(None, data=payload))
|
|
112
|
+
|
|
113
|
+
def delete(self):
|
|
114
|
+
"""
|
|
115
|
+
Delete the webhook.
|
|
116
|
+
"""
|
|
117
|
+
return super(Hook, self).delete(None)
|
atlassian/confluence.py
CHANGED
|
@@ -2877,6 +2877,47 @@ class Confluence(AtlassianRestAPI):
|
|
|
2877
2877
|
params["searchString"] = search_string
|
|
2878
2878
|
return self.get(url, params=params)
|
|
2879
2879
|
|
|
2880
|
+
"""
|
|
2881
|
+
##############################################################################################
|
|
2882
|
+
# Confluence whiteboards (cloud only!) #
|
|
2883
|
+
##############################################################################################
|
|
2884
|
+
"""
|
|
2885
|
+
|
|
2886
|
+
def create_whiteboard(self, spaceId, title=None, parentId=None):
|
|
2887
|
+
url = "/api/v2/whiteboards"
|
|
2888
|
+
data = {"spaceId": spaceId}
|
|
2889
|
+
if title is not None:
|
|
2890
|
+
data["title"] = title
|
|
2891
|
+
if parentId is not None:
|
|
2892
|
+
data["parentId"] = parentId
|
|
2893
|
+
return self.post(url, data=data)
|
|
2894
|
+
|
|
2895
|
+
def get_whiteboard(self, whiteboard_id):
|
|
2896
|
+
try:
|
|
2897
|
+
url = f"/api/v2/whiteboards/{whiteboard_id}"
|
|
2898
|
+
return self.get(url)
|
|
2899
|
+
except HTTPError as e:
|
|
2900
|
+
# Default 404 error handling is ambiguous
|
|
2901
|
+
if e.response.status_code == 404:
|
|
2902
|
+
raise ApiValueError(
|
|
2903
|
+
"Whiteboard not found. Check confluence instance url and/or if whiteboard id exists", reason=e
|
|
2904
|
+
)
|
|
2905
|
+
|
|
2906
|
+
raise
|
|
2907
|
+
|
|
2908
|
+
def delete_whiteboard(self, whiteboard_id):
|
|
2909
|
+
try:
|
|
2910
|
+
url = f"/api/v2/whiteboards/{whiteboard_id}"
|
|
2911
|
+
return self.delete(url)
|
|
2912
|
+
except HTTPError as e:
|
|
2913
|
+
# # Default 404 error handling is ambiguous
|
|
2914
|
+
if e.response.status_code == 404:
|
|
2915
|
+
raise ApiValueError(
|
|
2916
|
+
"Whiteboard not found. Check confluence instance url and/or if whiteboard id exists", reason=e
|
|
2917
|
+
)
|
|
2918
|
+
|
|
2919
|
+
raise
|
|
2920
|
+
|
|
2880
2921
|
"""
|
|
2881
2922
|
##############################################################################################
|
|
2882
2923
|
# Team Calendars REST API implements (https://jira.atlassian.com/browse/CONFSERVER-51003) #
|
atlassian/jira.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# coding=utf-8
|
|
2
2
|
import logging
|
|
3
3
|
import re
|
|
4
|
+
import os
|
|
4
5
|
from warnings import warn
|
|
5
6
|
from deprecated import deprecated
|
|
6
7
|
from requests import HTTPError
|
|
@@ -23,6 +24,62 @@ class Jira(AtlassianRestAPI):
|
|
|
23
24
|
|
|
24
25
|
super(Jira, self).__init__(url, *args, **kwargs)
|
|
25
26
|
|
|
27
|
+
def _get_paged(
|
|
28
|
+
self,
|
|
29
|
+
url,
|
|
30
|
+
params=None,
|
|
31
|
+
data=None,
|
|
32
|
+
flags=None,
|
|
33
|
+
trailing=None,
|
|
34
|
+
absolute=False,
|
|
35
|
+
):
|
|
36
|
+
"""
|
|
37
|
+
Used to get the paged data
|
|
38
|
+
|
|
39
|
+
:param url: string: The url to retrieve
|
|
40
|
+
:param params: dict (default is None): The parameter's
|
|
41
|
+
:param data: dict (default is None): The data
|
|
42
|
+
:param flags: string[] (default is None): The flags
|
|
43
|
+
:param trailing: bool (default is None): If True, a trailing slash is added to the url
|
|
44
|
+
:param absolute: bool (default is False): If True, the url is used absolute and not relative to the root
|
|
45
|
+
|
|
46
|
+
:return: A generator object for the data elements
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
if self.cloud:
|
|
50
|
+
if params is None:
|
|
51
|
+
params = {}
|
|
52
|
+
|
|
53
|
+
while True:
|
|
54
|
+
response = super(Jira, self).get(
|
|
55
|
+
url,
|
|
56
|
+
trailing=trailing,
|
|
57
|
+
params=params,
|
|
58
|
+
data=data,
|
|
59
|
+
flags=flags,
|
|
60
|
+
absolute=absolute,
|
|
61
|
+
)
|
|
62
|
+
values = response.get("values", [])
|
|
63
|
+
for value in values:
|
|
64
|
+
yield value
|
|
65
|
+
|
|
66
|
+
if response.get("isLast", False) or len(values) == 0:
|
|
67
|
+
break
|
|
68
|
+
|
|
69
|
+
url = response.get("nextPage")
|
|
70
|
+
if url is None:
|
|
71
|
+
break
|
|
72
|
+
# From now on we have absolute URLs with parameters
|
|
73
|
+
absolute = True
|
|
74
|
+
# Params are now provided by the url
|
|
75
|
+
params = {}
|
|
76
|
+
# Trailing should not be added as it is already part of the url
|
|
77
|
+
trailing = False
|
|
78
|
+
else:
|
|
79
|
+
raise ValueError("``_get_paged`` method is only available for Jira Cloud platform")
|
|
80
|
+
|
|
81
|
+
return
|
|
82
|
+
|
|
26
83
|
def get_permissions(
|
|
27
84
|
self,
|
|
28
85
|
permissions,
|
|
@@ -163,6 +220,18 @@ class Jira(AtlassianRestAPI):
|
|
|
163
220
|
Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/attachment
|
|
164
221
|
"""
|
|
165
222
|
|
|
223
|
+
def get_attachments_ids_from_issue(self, issue):
|
|
224
|
+
"""
|
|
225
|
+
Get attachments IDs from jira issue
|
|
226
|
+
:param jira issue key: str
|
|
227
|
+
:return: list of integers attachment IDs
|
|
228
|
+
"""
|
|
229
|
+
issue_id = self.get_issue(issue)["fields"]["attachment"]
|
|
230
|
+
list_attachments_id = []
|
|
231
|
+
for attachment in issue_id:
|
|
232
|
+
list_attachments_id.append({"filename": attachment["filename"], "attachment_id": attachment["id"]})
|
|
233
|
+
return list_attachments_id
|
|
234
|
+
|
|
166
235
|
def get_attachment(self, attachment_id):
|
|
167
236
|
"""
|
|
168
237
|
Returns the meta-data for an attachment, including the URI of the actual attached file
|
|
@@ -173,6 +242,44 @@ class Jira(AtlassianRestAPI):
|
|
|
173
242
|
url = "{base_url}/{attachment_id}".format(base_url=base_url, attachment_id=attachment_id)
|
|
174
243
|
return self.get(url)
|
|
175
244
|
|
|
245
|
+
def download_attachments_from_issue(self, issue, path=None, cloud=True):
|
|
246
|
+
"""
|
|
247
|
+
Downloads all attachments from a Jira issue.
|
|
248
|
+
:param issue: The issue-key of the Jira issue
|
|
249
|
+
:param path: Path to directory where attachments will be saved. If None, current working directory will be used.
|
|
250
|
+
:param cloud: Use True for Jira Cloud, false when using Jira Data Center or Server
|
|
251
|
+
:return: A message indicating the result of the download operation.
|
|
252
|
+
"""
|
|
253
|
+
try:
|
|
254
|
+
if path is None:
|
|
255
|
+
path = os.getcwd()
|
|
256
|
+
issue_id = self.issue(issue, fields="id")["id"]
|
|
257
|
+
if cloud:
|
|
258
|
+
url = self.url + f"/secure/issueAttachments/{issue_id}.zip"
|
|
259
|
+
else:
|
|
260
|
+
url = self.url + f"/secure/attachmentzip/{issue_id}.zip"
|
|
261
|
+
response = self._session.get(url)
|
|
262
|
+
attachment_name = f"{issue_id}_attachments.zip"
|
|
263
|
+
file_path = os.path.join(path, attachment_name)
|
|
264
|
+
# if Jira issue doesn't have any attachments _session.get request response will return 22 bytes of PKzip format
|
|
265
|
+
file_size = sum(len(chunk) for chunk in response.iter_content(8196))
|
|
266
|
+
if file_size == 22:
|
|
267
|
+
return "No attachments found on the Jira issue"
|
|
268
|
+
if os.path.isfile(file_path):
|
|
269
|
+
return "File already exists"
|
|
270
|
+
with open(file_path, "wb") as f:
|
|
271
|
+
f.write(response.content)
|
|
272
|
+
return "Attachments downloaded successfully"
|
|
273
|
+
|
|
274
|
+
except FileNotFoundError:
|
|
275
|
+
raise FileNotFoundError("Verify if directory path is correct and/or if directory exists")
|
|
276
|
+
except PermissionError:
|
|
277
|
+
raise PermissionError(
|
|
278
|
+
"Directory found, but there is a problem with saving file to this directory. Check directory permissions"
|
|
279
|
+
)
|
|
280
|
+
except Exception as e:
|
|
281
|
+
raise e
|
|
282
|
+
|
|
176
283
|
def get_attachment_content(self, attachment_id):
|
|
177
284
|
"""
|
|
178
285
|
Returns the content for an attachment
|
|
@@ -975,13 +1082,7 @@ class Jira(AtlassianRestAPI):
|
|
|
975
1082
|
params["expand"] = expand
|
|
976
1083
|
return self.get(url, params=params)
|
|
977
1084
|
|
|
978
|
-
def get_issue(
|
|
979
|
-
self,
|
|
980
|
-
issue_id_or_key,
|
|
981
|
-
fields=None,
|
|
982
|
-
properties=None,
|
|
983
|
-
update_history=True,
|
|
984
|
-
):
|
|
1085
|
+
def get_issue(self, issue_id_or_key, fields=None, properties=None, update_history=True, expand=None):
|
|
985
1086
|
"""
|
|
986
1087
|
Returns a full representation of the issue for the given issue key
|
|
987
1088
|
By default, all fields are returned in this get-issue resource
|
|
@@ -990,6 +1091,7 @@ class Jira(AtlassianRestAPI):
|
|
|
990
1091
|
:param fields: str
|
|
991
1092
|
:param properties: str
|
|
992
1093
|
:param update_history: bool
|
|
1094
|
+
:param expand: str
|
|
993
1095
|
:return: issue
|
|
994
1096
|
"""
|
|
995
1097
|
base_url = self.resource_url("issue")
|
|
@@ -1002,11 +1104,9 @@ class Jira(AtlassianRestAPI):
|
|
|
1002
1104
|
params["fields"] = fields
|
|
1003
1105
|
if properties is not None:
|
|
1004
1106
|
params["properties"] = properties
|
|
1005
|
-
if
|
|
1006
|
-
params["
|
|
1007
|
-
|
|
1008
|
-
params["updateHistory"] = "false"
|
|
1009
|
-
|
|
1107
|
+
if expand:
|
|
1108
|
+
params["expand"] = expand
|
|
1109
|
+
params["updateHistory"] = str(update_history).lower()
|
|
1010
1110
|
return self.get(url, params=params)
|
|
1011
1111
|
|
|
1012
1112
|
def epic_issues(self, epic, fields="*all", expand=None):
|
|
@@ -1598,6 +1698,42 @@ class Jira(AtlassianRestAPI):
|
|
|
1598
1698
|
url += "/" + internal_id
|
|
1599
1699
|
return self.get(url, params=params)
|
|
1600
1700
|
|
|
1701
|
+
def get_issue_tree_recursive(self, issue_key, tree=[], depth=0):
|
|
1702
|
+
"""
|
|
1703
|
+
Returns list that contains the tree structure of the root issue, with all subtasks and inward linked issues.
|
|
1704
|
+
(!) Function only returns child issues from the same jira instance or from instance to which api key has access to.
|
|
1705
|
+
(!) User asssociated with API key must have access to the all child issues in order to get them.
|
|
1706
|
+
:param jira issue_key:
|
|
1707
|
+
:param tree: blank parameter used for recursion. Don't change it.
|
|
1708
|
+
:param depth: blank parameter used for recursion. Don't change it.
|
|
1709
|
+
:return: list of dictioanries, key is the parent issue key, value is the child/linked issue key
|
|
1710
|
+
|
|
1711
|
+
"""
|
|
1712
|
+
|
|
1713
|
+
# Check the recursion depth. In case of any bugs that would result in infinite recursion, this will prevent the function from crashing your app. Python default for REcursionError is 1000
|
|
1714
|
+
if depth > 50:
|
|
1715
|
+
raise Exception("Recursion depth exceeded")
|
|
1716
|
+
issue = self.get_issue(issue_key)
|
|
1717
|
+
issue_links = issue["fields"]["issuelinks"]
|
|
1718
|
+
subtasks = issue["fields"]["subtasks"]
|
|
1719
|
+
for issue_link in issue_links:
|
|
1720
|
+
if issue_link.get("inwardIssue") is not None:
|
|
1721
|
+
parent_issue_key = issue["key"]
|
|
1722
|
+
if not [
|
|
1723
|
+
x for x in tree if issue_link["inwardIssue"]["key"] in x.keys()
|
|
1724
|
+
]: # condition to avoid infinite recursion
|
|
1725
|
+
tree.append({parent_issue_key: issue_link["inwardIssue"]["key"]})
|
|
1726
|
+
self.get_issue_tree_recursive(
|
|
1727
|
+
issue_link["inwardIssue"]["key"], tree, depth + 1
|
|
1728
|
+
) # recursive call of the function
|
|
1729
|
+
for subtask in subtasks:
|
|
1730
|
+
if subtask.get("key") is not None:
|
|
1731
|
+
parent_issue_key = issue["key"]
|
|
1732
|
+
if not [x for x in tree if subtask["key"] in x.keys()]: # condition to avoid infinite recursion
|
|
1733
|
+
tree.append({parent_issue_key: subtask["key"]})
|
|
1734
|
+
self.get_issue_tree_recursive(subtask["key"], tree, depth + 1) # recursive call of the function
|
|
1735
|
+
return tree
|
|
1736
|
+
|
|
1601
1737
|
def create_or_update_issue_remote_links(
|
|
1602
1738
|
self,
|
|
1603
1739
|
issue_key,
|
|
@@ -1724,6 +1860,20 @@ class Jira(AtlassianRestAPI):
|
|
|
1724
1860
|
data["update"] = update
|
|
1725
1861
|
return self.post(url, data=data)
|
|
1726
1862
|
|
|
1863
|
+
def get_issue_status_changelog(self, issue_id):
|
|
1864
|
+
# Get the issue details with changelog
|
|
1865
|
+
response_get_issue = self.get_issue(issue_id, expand="changelog")
|
|
1866
|
+
status_change_history = []
|
|
1867
|
+
for history in response_get_issue["changelog"]["histories"]:
|
|
1868
|
+
for item in history["items"]:
|
|
1869
|
+
# Check if the item is a status change
|
|
1870
|
+
if item["field"] == "status":
|
|
1871
|
+
status_change_history.append(
|
|
1872
|
+
{"from": item["fromString"], "to": item["toString"], "date": history["created"]}
|
|
1873
|
+
)
|
|
1874
|
+
|
|
1875
|
+
return status_change_history
|
|
1876
|
+
|
|
1727
1877
|
def set_issue_status_by_transition_id(self, issue_key, transition_id):
|
|
1728
1878
|
"""
|
|
1729
1879
|
Setting status by transition_id
|
|
@@ -2246,83 +2396,23 @@ class Jira(AtlassianRestAPI):
|
|
|
2246
2396
|
:param expand:
|
|
2247
2397
|
:return:
|
|
2248
2398
|
"""
|
|
2249
|
-
if self.cloud:
|
|
2250
|
-
return self.projects_from_cloud(
|
|
2251
|
-
included_archived=included_archived,
|
|
2252
|
-
expand=expand,
|
|
2253
|
-
)
|
|
2254
|
-
else:
|
|
2255
|
-
return self.projects_from_server(
|
|
2256
|
-
included_archived=included_archived,
|
|
2257
|
-
expand=expand,
|
|
2258
|
-
)
|
|
2259
|
-
|
|
2260
|
-
def projects_from_cloud(self, included_archived=None, expand=None):
|
|
2261
|
-
"""
|
|
2262
|
-
Returns all projects which are visible for the currently logged-in user.
|
|
2263
|
-
Cloud version should use the ``paginated``endpoint to get pages of projects, as the old endpoint is deprecated.
|
|
2264
|
-
If no user is logged in, it returns the list of projects that are visible when using anonymous access.
|
|
2265
|
-
:param included_archived: boolean whether to include archived projects in response, default: false
|
|
2266
|
-
:param expand:
|
|
2267
|
-
:return:
|
|
2268
|
-
"""
|
|
2269
|
-
if not self.cloud:
|
|
2270
|
-
raise ValueError("``projects_from_cloud`` method is only available for Jira Cloud platform")
|
|
2271
|
-
|
|
2272
|
-
projects = self.paginated_projects(
|
|
2273
|
-
included_archived=included_archived,
|
|
2274
|
-
expand=expand,
|
|
2275
|
-
)
|
|
2276
|
-
while not projects.get("isLast"):
|
|
2277
|
-
projects["values"].extend(
|
|
2278
|
-
self.paginated_projects(
|
|
2279
|
-
included_archived=included_archived,
|
|
2280
|
-
expand=expand,
|
|
2281
|
-
url=projects["nextPage"],
|
|
2282
|
-
)["values"]
|
|
2283
|
-
)
|
|
2284
|
-
return projects["values"]
|
|
2285
|
-
|
|
2286
|
-
def paginated_projects(self, included_archived=None, expand=None, url=None):
|
|
2287
|
-
"""
|
|
2288
|
-
Returns a page of projects which are visible for the currently logged-in user.
|
|
2289
|
-
Method to be used only for Jira Cloud platform, until tests on Jira Server are executed.
|
|
2290
|
-
If no user is logged in, it returns the list of projects that are visible when using anonymous access.
|
|
2291
|
-
:param included_archived: boolean whether to include archived projects in response, default: false
|
|
2292
|
-
:param expand:
|
|
2293
|
-
:param url: url to get the next page of projects, default: false (first page)
|
|
2294
|
-
:return:
|
|
2295
|
-
"""
|
|
2296
|
-
if not self.cloud:
|
|
2297
|
-
raise ValueError("``projects_from_cloud`` method is only available for Jira Cloud platform")
|
|
2298
2399
|
|
|
2299
2400
|
params = {}
|
|
2300
2401
|
if included_archived:
|
|
2301
2402
|
params["includeArchived"] = included_archived
|
|
2302
2403
|
if expand:
|
|
2303
2404
|
params["expand"] = expand
|
|
2304
|
-
page_url = url or self.resource_url("project/search")
|
|
2305
|
-
is_url_absolute = bool(page_url.lower().startswith("http"))
|
|
2306
|
-
return self.get(page_url, params=params, absolute=is_url_absolute)
|
|
2307
|
-
|
|
2308
|
-
def projects_from_server(self, included_archived=None, expand=None):
|
|
2309
|
-
"""
|
|
2310
|
-
Returns all projects which are visible for the currently logged-in user.
|
|
2311
|
-
If no user is logged in, it returns the list of projects that are visible when using anonymous access.
|
|
2312
|
-
:param included_archived: boolean whether to include archived projects in response, default: false
|
|
2313
|
-
:param expand:
|
|
2314
|
-
:return:
|
|
2315
|
-
"""
|
|
2316
2405
|
if self.cloud:
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2406
|
+
return list(
|
|
2407
|
+
self._get_paged(
|
|
2408
|
+
self.resource_url("project/search"),
|
|
2409
|
+
params,
|
|
2410
|
+
paging_workaround=True,
|
|
2411
|
+
)
|
|
2412
|
+
)
|
|
2413
|
+
else:
|
|
2414
|
+
url = self.resource_url("project")
|
|
2415
|
+
return self.get(url, params=params)
|
|
2326
2416
|
|
|
2327
2417
|
def create_project_from_raw_json(self, json):
|
|
2328
2418
|
"""
|
atlassian/rest_client.py
CHANGED
|
@@ -3,6 +3,7 @@ import logging
|
|
|
3
3
|
from json import dumps
|
|
4
4
|
|
|
5
5
|
import requests
|
|
6
|
+
from requests.adapters import HTTPAdapter
|
|
6
7
|
|
|
7
8
|
try:
|
|
8
9
|
from oauthlib.oauth1.rfc5849 import SIGNATURE_RSA_SHA512 as SIGNATURE_RSA
|
|
@@ -11,6 +12,7 @@ except ImportError:
|
|
|
11
12
|
from requests import HTTPError
|
|
12
13
|
from requests_oauthlib import OAuth1, OAuth2
|
|
13
14
|
from six.moves.urllib.parse import urlencode
|
|
15
|
+
from urllib3.util import Retry
|
|
14
16
|
|
|
15
17
|
from atlassian.request_utils import get_default_logger
|
|
16
18
|
|
|
@@ -61,7 +63,44 @@ class AtlassianRestAPI(object):
|
|
|
61
63
|
proxies=None,
|
|
62
64
|
token=None,
|
|
63
65
|
cert=None,
|
|
66
|
+
backoff_and_retry=False,
|
|
67
|
+
retry_status_codes=[413, 429, 503],
|
|
68
|
+
max_backoff_seconds=1800,
|
|
69
|
+
max_backoff_retries=1000,
|
|
64
70
|
):
|
|
71
|
+
"""
|
|
72
|
+
init function for the AtlassianRestAPI object.
|
|
73
|
+
|
|
74
|
+
:param url: The url to be used in the request.
|
|
75
|
+
:param username: Username. Defaults to None.
|
|
76
|
+
:param password: Password. Defaults to None.
|
|
77
|
+
:param timeout: Request timeout. Defaults to 75.
|
|
78
|
+
:param api_root: Root for the api requests. Defaults to "rest/api".
|
|
79
|
+
:param api_version: Version of the API to use. Defaults to "latest".
|
|
80
|
+
:param verify_ssl: Turn on / off SSL verification. Defaults to True.
|
|
81
|
+
:param session: Pass an existing Python requests session object. Defaults to None.
|
|
82
|
+
:param oauth: oauth. Defaults to None.
|
|
83
|
+
:param oauth2: oauth2. Defaults to None.
|
|
84
|
+
:param cookies: Cookies to send with the request. Defaults to None.
|
|
85
|
+
:param advanced_mode: Return results in advanced mode. Defaults to None.
|
|
86
|
+
:param kerberos: Kerberos. Defaults to None.
|
|
87
|
+
:param cloud: Specify if using Atlassian Cloud. Defaults to False.
|
|
88
|
+
:param proxies: Specify proxies to use. Defaults to None.
|
|
89
|
+
:param token: Atlassian / Jira auth token. Defaults to None.
|
|
90
|
+
:param cert: Client-side certificate to use. Defaults to None.
|
|
91
|
+
:param backoff_and_retry: Enable exponential backoff and retry.
|
|
92
|
+
This will retry the request if there is a predefined failure. Primarily
|
|
93
|
+
designed for Atlassian Cloud where API limits are commonly hit if doing
|
|
94
|
+
operations on many issues, and the limits require a cooling off period.
|
|
95
|
+
The wait period before the next request increases exponentially with each
|
|
96
|
+
failed retry. Defaults to False.
|
|
97
|
+
:param retry_status_codes: Errors to match, passed as a list of HTTP
|
|
98
|
+
response codes. Defaults to [413, 429, 503].
|
|
99
|
+
:param max_backoff_seconds: Max backoff seconds. When backing off, requests won't
|
|
100
|
+
wait any longer than this. Defaults to 1800.
|
|
101
|
+
:param max_backoff_retries: Maximum number of retries to try before
|
|
102
|
+
continuing. Defaults to 1000.
|
|
103
|
+
"""
|
|
65
104
|
self.url = url
|
|
66
105
|
self.username = username
|
|
67
106
|
self.password = password
|
|
@@ -78,6 +117,19 @@ class AtlassianRestAPI(object):
|
|
|
78
117
|
self._session = requests.Session()
|
|
79
118
|
else:
|
|
80
119
|
self._session = session
|
|
120
|
+
if backoff_and_retry:
|
|
121
|
+
# Note: we only retry on status and not on any of the
|
|
122
|
+
# other supported reasons
|
|
123
|
+
retries = Retry(
|
|
124
|
+
total=None,
|
|
125
|
+
status=max_backoff_retries,
|
|
126
|
+
allowed_methods=None,
|
|
127
|
+
status_forcelist=retry_status_codes,
|
|
128
|
+
backoff_factor=1,
|
|
129
|
+
backoff_jitter=1,
|
|
130
|
+
backoff_max=max_backoff_seconds,
|
|
131
|
+
)
|
|
132
|
+
self._session.mount(self.url, HTTPAdapter(max_retries=retries))
|
|
81
133
|
if username and password:
|
|
82
134
|
self._create_basic_session(username, password)
|
|
83
135
|
elif token is not None:
|
|
@@ -101,7 +153,7 @@ class AtlassianRestAPI(object):
|
|
|
101
153
|
self._session.auth = (username, password)
|
|
102
154
|
|
|
103
155
|
def _create_token_session(self, token):
|
|
104
|
-
self._update_header("Authorization", "Bearer {token}".format(token=token))
|
|
156
|
+
self._update_header("Authorization", "Bearer {token}".format(token=token.strip()))
|
|
105
157
|
|
|
106
158
|
def _create_kerberos_session(self, _):
|
|
107
159
|
from requests_kerberos import OPTIONAL, HTTPKerberosAuth
|
|
@@ -485,7 +537,9 @@ class AtlassianRestAPI(object):
|
|
|
485
537
|
else:
|
|
486
538
|
error_msg_list = j.get("errorMessages", list())
|
|
487
539
|
errors = j.get("errors", dict())
|
|
488
|
-
if isinstance(errors, dict):
|
|
540
|
+
if isinstance(errors, dict) and "message" not in errors:
|
|
541
|
+
error_msg_list.extend(errors.values())
|
|
542
|
+
elif isinstance(errors, dict) and "message" in errors:
|
|
489
543
|
error_msg_list.append(errors.get("message", ""))
|
|
490
544
|
elif isinstance(errors, list):
|
|
491
545
|
error_msg_list.extend([v.get("message", "") if isinstance(v, dict) else v for v in errors])
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: atlassian-python-api
|
|
3
|
-
Version: 3.41.
|
|
3
|
+
Version: 3.41.12
|
|
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
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
atlassian/VERSION,sha256=
|
|
1
|
+
atlassian/VERSION,sha256=ESc6UwFy1gQOeJZOoq8kTWTiqV6-lfzm4z4c4EGDNeE,8
|
|
2
2
|
atlassian/__init__.py,sha256=F13CZFoWIj9pDkj83soA7hwwHtvDC6EqFATey9p36PM,768
|
|
3
3
|
atlassian/bamboo.py,sha256=50wpYYt-6eCCotmyeiceyxJIaTpLw922jb-0Tm-ROac,45250
|
|
4
4
|
atlassian/cloud_admin.py,sha256=vZxMA6IrdCQw1KAX3xKal_0ayTWGdMVhe3i0bPpChGk,969
|
|
5
|
-
atlassian/confluence.py,sha256=
|
|
5
|
+
atlassian/confluence.py,sha256=5IKNbeG1dJXWxq8a2d9RCyhL8UWWQhzkN40DYCHCHPM,121073
|
|
6
6
|
atlassian/crowd.py,sha256=wYU_i3oSEQktJlmCvgkYbIs8oX_P5Z_OaiocKce5tWs,8126
|
|
7
7
|
atlassian/errors.py,sha256=GAKr6W4zPn7ZUMRLHG8-UgAdVnxDzKVZ-jyGXAccALE,398
|
|
8
8
|
atlassian/insight.py,sha256=oOWYoIway05rNup5GPDRm3S5WYuDhHe7JJ-g3vNccsk,23798
|
|
9
|
-
atlassian/jira.py,sha256=
|
|
9
|
+
atlassian/jira.py,sha256=NrTDlIo7p-ojCsLqHXAI_m6buBx-YHdmnYB0ryCCP0M,206239
|
|
10
10
|
atlassian/marketplace.py,sha256=-y7j0mOi00gBzq1Izj-sXI8khP90rKJUYXijpKW9vs8,2590
|
|
11
11
|
atlassian/portfolio.py,sha256=ioJMyxJW_Uuitszzd0ExoF1t8tykdit7Z7-WYlI6raA,3807
|
|
12
12
|
atlassian/request_utils.py,sha256=HRqGJyeWS3L3SAlgC2x8tKakvyHb1HafxcrHhTNq9iE,1127
|
|
13
|
-
atlassian/rest_client.py,sha256=
|
|
13
|
+
atlassian/rest_client.py,sha256=ubmKD_jTXqeKVA6ObPpnvorXwTTnsYoXOdndBlfC2TU,18622
|
|
14
14
|
atlassian/service_desk.py,sha256=8pM37-aTD4fG8VyA84s9JBGPsKgT7OHUdf9x-GffutY,32632
|
|
15
15
|
atlassian/statuspage.py,sha256=M6Ryz4cpLrjqEiv-W6Uch4_OLjdxVILQpUojeAnYYdA,94470
|
|
16
16
|
atlassian/utils.py,sha256=oKvkGflmgygUcTU-fKd0LBnovgBpu3e5uHsj0sng_vg,10955
|
|
17
17
|
atlassian/xray.py,sha256=3OvLMNfTxfCXgKXxpjhq3a01RemOEtvJH9OqbCJrHEs,26219
|
|
18
|
-
atlassian/bitbucket/__init__.py,sha256=
|
|
18
|
+
atlassian/bitbucket/__init__.py,sha256=tbWu7qASsV6JeIw9sWorg1z3Ij16Ks8ThXfpDK1X-o0,133929
|
|
19
19
|
atlassian/bitbucket/base.py,sha256=KfzR9YsdF_zfvq6KOMFzbxNut36vQ2ZJcBmURYzF4N4,6303
|
|
20
20
|
atlassian/bitbucket/cloud/__init__.py,sha256=MX58kb4PKRK5M_iLyh0pya0FG8c9cYJkCAEVsugiGok,821
|
|
21
21
|
atlassian/bitbucket/cloud/base.py,sha256=K2v04dr3K22Wsx8w-fmPQym3vsSflOERYA_TtSMwr4c,4094
|
|
@@ -23,13 +23,14 @@ atlassian/bitbucket/cloud/common/__init__.py,sha256=5r9gwfcmU-AwZXG4kjU_Jpj_R72M
|
|
|
23
23
|
atlassian/bitbucket/cloud/common/builds.py,sha256=Gka9aQIKxzzCU3JGHg97zNEz01_eFyOpJA9su-D2C_I,2366
|
|
24
24
|
atlassian/bitbucket/cloud/common/comments.py,sha256=ktnN9G0Vr49rIAeqTElnEXvpePp6roUw_Om06JnEb-4,1329
|
|
25
25
|
atlassian/bitbucket/cloud/common/users.py,sha256=BbjkMeNFp7JwuewbKL_5qO1geuZ5iu3u5AThPu1pYJo,2390
|
|
26
|
-
atlassian/bitbucket/cloud/repositories/__init__.py,sha256=
|
|
26
|
+
atlassian/bitbucket/cloud/repositories/__init__.py,sha256=IlRZdpX7FHjOHZ4EddggYjxu6AbO7C_inp3A30U8Y4c,16957
|
|
27
27
|
atlassian/bitbucket/cloud/repositories/branchRestrictions.py,sha256=E1wr1pheH9UnVLMao8-9rwmNZPJeLRoM1AmFQnfe4jQ,6503
|
|
28
28
|
atlassian/bitbucket/cloud/repositories/commits.py,sha256=mIheLsyIsfBParfNFhSoSJGAP8c-vlHgRVqoQfBOy00,6414
|
|
29
29
|
atlassian/bitbucket/cloud/repositories/defaultReviewers.py,sha256=bSa1iPILiKf9IcWcCYCQtYxQHoqeiuYGBHD7JVmXa-4,3560
|
|
30
30
|
atlassian/bitbucket/cloud/repositories/deploymentEnvironments.py,sha256=f7FAS5ljkRZOW-SkNEugQMoIVGCQVpl5gPpNW-vWEkU,9405
|
|
31
31
|
atlassian/bitbucket/cloud/repositories/diffstat.py,sha256=tzi9mDC71Jps-Lj_UdvR3mUb1nFlbN2DZ1bjHfGu26A,2893
|
|
32
32
|
atlassian/bitbucket/cloud/repositories/groupPermissions.py,sha256=yMSlQKvrQ5rFx3eD-pJuMR2QdzotTAAV8KCR6KOGHU4,2696
|
|
33
|
+
atlassian/bitbucket/cloud/repositories/hooks.py,sha256=erNk58XuROeG4ruAqNLFTxpyRB2kQjh8ny0VXVPNX8A,3181
|
|
33
34
|
atlassian/bitbucket/cloud/repositories/issues.py,sha256=rJzPfhETsI7qqi9xyo_MwaTPnwxmQe2pyBYTLyMf9Eg,5065
|
|
34
35
|
atlassian/bitbucket/cloud/repositories/pipelines.py,sha256=i4Vb0r3exi7gSkG0W1VGvB8x-DzZQn4RVrOHVo2e2rQ,9157
|
|
35
36
|
atlassian/bitbucket/cloud/repositories/pullRequests.py,sha256=11xN8-_wUT-eV-A39fCRW-jm6jm9Qn1ClpLZiaZtEJk,16253
|
|
@@ -46,8 +47,8 @@ atlassian/bitbucket/server/common/__init__.py,sha256=0j0CWKFaX1kDqfDQkf3__Y2p24t
|
|
|
46
47
|
atlassian/bitbucket/server/common/permissions.py,sha256=89KLu4PY5BUJZsjTrJ8JbrQ46EHn1qj_P-ZJ-uGv3dA,7318
|
|
47
48
|
atlassian/bitbucket/server/projects/__init__.py,sha256=QXHgvrf3lS14OAbtXNdn9TC8ML2fZUkrC5C8BTR3I_0,7696
|
|
48
49
|
atlassian/bitbucket/server/projects/repos/__init__.py,sha256=GNWhabbnLG7kpgCS85wPzOxtbeCtySchCqFwFZnTdh4,10783
|
|
49
|
-
atlassian_python_api-3.41.
|
|
50
|
-
atlassian_python_api-3.41.
|
|
51
|
-
atlassian_python_api-3.41.
|
|
52
|
-
atlassian_python_api-3.41.
|
|
53
|
-
atlassian_python_api-3.41.
|
|
50
|
+
atlassian_python_api-3.41.12.dist-info/LICENSE,sha256=xamAnoX0zfBamIilAfP3nSIt7dIvnj7oueX14l6uKPY,11335
|
|
51
|
+
atlassian_python_api-3.41.12.dist-info/METADATA,sha256=bKlay6Ks-fEjU2Hfv7Sb9vMYrW_VOi6z6TKyaGe8wrA,8792
|
|
52
|
+
atlassian_python_api-3.41.12.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
53
|
+
atlassian_python_api-3.41.12.dist-info/top_level.txt,sha256=84-EDv8LNaZx01TCGjBzglwPU1JSRJ7fPSq9uy55Sv0,10
|
|
54
|
+
atlassian_python_api-3.41.12.dist-info/RECORD,,
|
|
File without changes
|
{atlassian_python_api-3.41.10.dist-info → atlassian_python_api-3.41.12.dist-info}/top_level.txt
RENAMED
|
File without changes
|