Skip to content

Commit ce4a122

Browse files
Gonchik TsymzhitovGonchik Tsymzhitov
authored andcommitted
2 parents a1ab25e + a3d9fcf commit ce4a122

File tree

14 files changed

+313
-71
lines changed

14 files changed

+313
-71
lines changed

README.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
============================
22
Atlassian Python API wrapper
33
============================
4-
|Build Status| |PyPI version| |PyPI - Downloads| |License| |Codacy Badge|
4+
|Build Status| |PyPI version| |PyPI - Downloads| |License| |Codacy Badge| |Docs|
55

66
Documentation
77
-------------
88

9-
`Documentation (beta)`_
9+
`Documentation`_
1010

11-
.. _Documentation (beta): https://atlassian-python-api.readthedocs.io/en/latest/index.html
11+
.. _Documentation: https://atlassian-python-api.readthedocs.io/en/latest/index.html
1212

1313
Examples
1414
--------
@@ -109,6 +109,9 @@ See the `Contribution guidelines for this project`_ for details on how to make c
109109
:alt: Codacy Badge
110110
.. |PyPI - Downloads| image:: https://pepy.tech/badge/atlassian-python-api/month
111111
:alt: PyPI - Downloads
112+
.. |Docs| image:: https://readthedocs.org/projects/atlassian-python-api/badge/?version=latest
113+
:target: https://atlassian-python-api.readthedocs.io/en/latest/?badge=latest
114+
:alt: Documentation Status
112115

113116

114117
Credits

atlassian/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.13.23
1+
1.13.28

atlassian/bamboo.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ def base_list_call(self, resource, expand, favourite, clover_enabled, max_result
6161
params['start-index'] = start_index
6262
return self.get(self.resource_url(resource), flags=flags, params=params)
6363

64+
def get_custom_expiry(self, limit=25):
65+
"""
66+
Get list of all plans where user has admin permission and which override global expiry settings.
67+
If global expiry is not enabled it returns empty response.
68+
:param limit:
69+
"""
70+
url = "rest/api/latest/admin/expiry/custom/plan?limit={}".format(limit)
71+
return self.get(url)
72+
6473
def plan_directory_info(self, plan_key):
6574
"""
6675
Returns information about the directories where artifacts, build logs, and build results will be stored.
@@ -95,7 +104,7 @@ def plans(self, expand=None, favourite=False, clover_enabled=False, start_index=
95104
elements_key='plans', element_key='plan')
96105

97106
def results(self, project_key=None, plan_key=None, job_key=None, build_number=None, expand=None, favourite=False,
98-
clover_enabled=False, issue_key=None, label=None, start_index=0, max_results=25):
107+
clover_enabled=False, issue_key=None, label=None, start_index=0, max_results=25, include_all_states=False):
99108
"""
100109
Get results as generic method
101110
:param project_key:
@@ -109,6 +118,7 @@ def results(self, project_key=None, plan_key=None, job_key=None, build_number=No
109118
:param label:
110119
:param start_index:
111120
:param max_results:
121+
:param include_all_states:
112122
:return:
113123
"""
114124
resource = "result"
@@ -124,12 +134,14 @@ def results(self, project_key=None, plan_key=None, job_key=None, build_number=No
124134
params = {}
125135
if issue_key:
126136
params['issueKey'] = issue_key
137+
if include_all_states:
138+
params['includeAllStates'] = include_all_states
127139
return self.base_list_call(resource, expand=expand, favourite=favourite, clover_enabled=clover_enabled,
128140
start_index=start_index, max_results=max_results,
129141
elements_key='results', element_key='result', label=label, **params)
130142

131143
def latest_results(self, expand=None, favourite=False, clover_enabled=False, label=None, issue_key=None,
132-
start_index=0, max_results=25):
144+
start_index=0, max_results=25, include_all_states=False):
133145
"""
134146
Get latest Results
135147
:param expand:
@@ -139,13 +151,14 @@ def latest_results(self, expand=None, favourite=False, clover_enabled=False, lab
139151
:param issue_key:
140152
:param start_index:
141153
:param max_results:
154+
:param include_all_states:
142155
:return:
143156
"""
144157
return self.results(expand=expand, favourite=favourite, clover_enabled=clover_enabled,
145-
label=label, issue_key=issue_key, start_index=start_index, max_results=max_results)
158+
label=label, issue_key=issue_key, start_index=start_index, max_results=max_results, include_all_states=include_all_states)
146159

147160
def project_latest_results(self, project_key, expand=None, favourite=False, clover_enabled=False, label=None,
148-
issue_key=None, start_index=0, max_results=25):
161+
issue_key=None, start_index=0, max_results=25, include_all_states=False):
149162
"""
150163
Get latest Project Results
151164
:param project_key:
@@ -156,13 +169,14 @@ def project_latest_results(self, project_key, expand=None, favourite=False, clov
156169
:param issue_key:
157170
:param start_index:
158171
:param max_results:
172+
:param include_all_states:
159173
:return:
160174
"""
161175
return self.results(project_key, expand=expand, favourite=favourite, clover_enabled=clover_enabled,
162-
label=label, issue_key=issue_key, start_index=start_index, max_results=max_results)
176+
label=label, issue_key=issue_key, start_index=start_index, max_results=max_results, include_all_states=include_all_states)
163177

164178
def plan_results(self, project_key, plan_key, expand=None, favourite=False, clover_enabled=False, label=None,
165-
issue_key=None, start_index=0, max_results=25):
179+
issue_key=None, start_index=0, max_results=25, include_all_states=False):
166180
"""
167181
Get Plan results
168182
:param project_key:
@@ -174,12 +188,13 @@ def plan_results(self, project_key, plan_key, expand=None, favourite=False, clov
174188
:param issue_key:
175189
:param start_index:
176190
:param max_results:
191+
:param include_all_states:
177192
:return:
178193
"""
179194
return self.results(project_key, plan_key, expand=expand, favourite=favourite, clover_enabled=clover_enabled,
180-
label=label, issue_key=issue_key, start_index=start_index, max_results=max_results)
195+
label=label, issue_key=issue_key, start_index=start_index, max_results=max_results, include_all_states=include_all_states)
181196

182-
def build_result(self, build_key, expand=None):
197+
def build_result(self, build_key, expand=None, include_all_states=False):
183198
"""
184199
Returns details of a specific build result
185200
:param expand: expands build result details on request. Possible values are: artifacts, comments, labels,
@@ -192,22 +207,23 @@ def build_result(self, build_key, expand=None):
192207
int(build_key.split('-')[-1])
193208
resource = "result/{}".format(build_key)
194209
return self.base_list_call(resource, expand, favourite=False, clover_enabled=False,
195-
start_index=0, max_results=25)
210+
start_index=0, max_results=25, include_all_states=include_all_states)
196211
except ValueError:
197212
raise ValueError('The key "{}" does not correspond to a build result'.format(build_key))
198213

199-
def build_latest_result(self, plan_key, expand=None):
214+
def build_latest_result(self, plan_key, expand=None, include_all_states=False):
200215
"""
201216
Returns details of a latest build result
202217
:param expand: expands build result details on request. Possible values are: artifacts, comments, labels,
203218
Jira Issues, stages. stages expand is available only for top level plans. It allows to drill down to job results
204219
using stages.stage.results.result. All expand parameters should contain results.result prefix.
205220
:param plan_key: Should be in the form XX-YY[-ZZ]
221+
:param include_all_states:
206222
"""
207223
try:
208224
resource = "result/{}/latest.json".format(plan_key)
209225
return self.base_list_call(resource, expand, favourite=False, clover_enabled=False,
210-
start_index=0, max_results=25)
226+
start_index=0, max_results=25, include_all_states=include_all_states)
211227
except ValueError:
212228
raise ValueError('The key "{}" does not correspond to the latest build result'.format(plan_key))
213229

atlassian/bitbucket.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def project(self, key):
2424
:return:
2525
"""
2626
url = 'rest/api/1.0/projects/{0}'.format(key)
27-
return (self.get(url) or {}).get('values')
27+
return (self.get(url) or {})
2828

2929
def create_project(self, key, name, description=""):
3030
"""
@@ -669,6 +669,25 @@ def add_pull_request_comment(self, project, repository, pull_request_id, text):
669669
body = {'text': text}
670670
return self.post(url, data=body)
671671

672+
def get_pull_request_comment(self, project, repository, pull_request_id, comment_id):
673+
"""
674+
Retrieves a pull request comment.
675+
The authenticated user must have REPO_READ permission
676+
for the repository that this pull request targets to call this resource.
677+
:param project:
678+
:param repository:
679+
:param pull_request_id: the ID of the pull request within the repository
680+
:param comment_id: the ID of the comment to retrieve
681+
:return:
682+
"""
683+
url = ('rest/api/1.0/projects/{project}/repos/{repository}'
684+
'/pull-requests/{pullRequestId}/comments/{comment_id}').format(
685+
project=project,
686+
repository=repository,
687+
pullRequestId=pull_request_id,
688+
comment_id=comment_id)
689+
return self.get(url)
690+
672691
def get_pullrequest(self, project, repository, pull_request_id):
673692
"""
674693
Retrieve a pull request.

atlassian/confluence.py

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ def get_page_id(self, space, title):
8484
"""
8585
return (self.get_page_by_title(space, title) or {}).get('id')
8686

87+
def get_parent_content_id(self, page_id):
88+
"""
89+
Provide parent content id from page id
90+
:type page_id: str
91+
:return:
92+
"""
93+
parent_content_id = ((self.get_page_by_id(page_id=page_id, expand='ancestors').get('ancestors') or {})[-1].get(
94+
'id') or None)
95+
return parent_content_id
96+
8797
def get_page_space(self, page_id):
8898
"""
8999
Provide space key from content id
@@ -124,7 +134,11 @@ def get_page_by_id(self, page_id, expand=None):
124134
"""
125135
Get page by ID
126136
:param page_id: Content ID
127-
:param expand: OPTIONAL: expand e.g. history
137+
:param expand: OPTIONAL: A comma separated list of properties to expand on the content.
138+
Default value: history,space,version We can also specify some extensions
139+
such as extensions.inlineProperties
140+
(for getting inline comment-specific properties) or extensions.resolution
141+
for the resolution status of each comment in the results
128142
:return:
129143
"""
130144
params = {}
@@ -202,7 +216,7 @@ def get_all_pages_by_label(self, label, start=0, limit=50):
202216
url = 'rest/api/content/search'
203217
params = {}
204218
if label:
205-
params['cql'] = 'type={type}%20AND%20label={label}'.format(type='page',
219+
params['cql'] = 'type={type} AND label={label}'.format(type='page',
206220
label=label)
207221
if start:
208222
params['start'] = start
@@ -364,19 +378,22 @@ def create_page(self, space, title, body, parent_id=None, type='page',
364378
data['ancestors'] = [{'type': type, 'id': parent_id}]
365379
return self.post(url, data=data)
366380

367-
def get_all_spaces(self, start=0, limit=500):
381+
def get_all_spaces(self, start=0, limit=500, expand=None):
368382
"""
369383
Get all spaces with provided limit
370384
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
371385
:param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
372386
fixed system limits. Default: 500
387+
:param expand: OPTIONAL: additional info, e.g. metadata, icon, description, homepage
373388
"""
374389
url = 'rest/api/space'
375390
params = {}
376-
if limit:
377-
params['limit'] = limit
378391
if start:
379392
params['start'] = start
393+
if limit:
394+
params['limit'] = limit
395+
if expand:
396+
params['expand'] = expand
380397
return (self.get(url, params=params) or {}).get('results')
381398

382399
def add_comment(self, page_id, text):
@@ -671,10 +688,10 @@ def update_page(self, page_id, title, body, parent_id=None, type='page', represe
671688
minor_edit=False):
672689
"""
673690
Update page if already exist
674-
:param parent_id:
675691
:param page_id:
676692
:param title:
677693
:param body:
694+
:param parent_id:
678695
:param type:
679696
:param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
680697
:param minor_edit: Indicates whether to notify watchers about changes.
@@ -702,7 +719,7 @@ def update_page(self, page_id, title, body, parent_id=None, type='page', represe
702719

703720
return self.put('rest/api/content/{0}'.format(page_id), data=data)
704721

705-
def append_page(self, parent_id, page_id, title, append_body, type='page', representation='storage',
722+
def append_page(self, page_id, title, append_body, parent_id=None, type='page', representation='storage',
706723
minor_edit=False):
707724
"""
708725
Append body to page if already exist
@@ -741,21 +758,23 @@ def append_page(self, parent_id, page_id, title, append_body, type='page', repre
741758

742759
return self.put('rest/api/content/{0}'.format(page_id), data=data)
743760

744-
def update_or_create(self, parent_id, title, body, representation='storage'):
761+
def update_or_create(self, parent_id, title, body, representation='storage', minor_edit=False):
745762
"""
746763
Update page or create a page if it is not exists
747764
:param parent_id:
748765
:param title:
749766
:param body:
750767
:param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
768+
:param minor_edit: Update page without notification
751769
:return:
752770
"""
753771
space = self.get_page_space(parent_id)
754772

755773
if self.page_exists(space, title):
756774
page_id = self.get_page_id(space, title)
775+
parent_id = self.get_parent_content_id(page_id)
757776
result = self.update_page(parent_id=parent_id, page_id=page_id, title=title, body=body,
758-
representation=representation)
777+
representation=representation, minor_edit=minor_edit)
759778
else:
760779
result = self.create_page(space=space, parent_id=parent_id, title=title, body=body,
761780
representation=representation)
@@ -1200,3 +1219,56 @@ def audit(self, start_date=None, end_date=None, start=None, limit=None, search_s
12001219
if search_string:
12011220
params['searchString'] = search_string
12021221
return self.get(url, params=params)
1222+
1223+
"""
1224+
##############################################################################################
1225+
# Team Calendars REST API implements (https://jira.atlassian.com/browse/CONFSERVER-51003) #
1226+
##############################################################################################
1227+
"""
1228+
1229+
def team_calendars_get_sub_calendars(self, include=None, viewing_space_key=None, calendar_context=None):
1230+
"""
1231+
Get subscribed calendars
1232+
:param include:
1233+
:param viewing_space_key:
1234+
:param calendar_context:
1235+
:return:
1236+
"""
1237+
url = 'rest/calendar-services/1.0/calendar/subcalendars'
1238+
params = {}
1239+
if include:
1240+
params['include'] = include
1241+
if viewing_space_key:
1242+
params['viewingSpaceKey'] = viewing_space_key
1243+
if calendar_context:
1244+
params['calendarContext'] = calendar_context
1245+
return self.get(url, params=params)
1246+
1247+
def team_calendars_get_sub_calendars_watching_status(self, include=None):
1248+
url = 'rest/calendar-services/1.0/calendar/subcalendars/watching/status'
1249+
params = {}
1250+
if include:
1251+
params['include'] = include
1252+
return self.get(url, params=params)
1253+
1254+
def team_calendar_events(self, sub_calendar_id, start, end, user_time_zone_id=None):
1255+
"""
1256+
Get calendar event status
1257+
:param sub_calendar_id:
1258+
:param start:
1259+
:param end:
1260+
:param user_time_zone_id:
1261+
:return:
1262+
"""
1263+
url = 'rest/calendar-services/1.0/calendar/events'
1264+
params = {}
1265+
if sub_calendar_id:
1266+
params['subCalendarId'] = sub_calendar_id
1267+
if user_time_zone_id:
1268+
params['userTimeZoneId'] = user_time_zone_id
1269+
if start:
1270+
params['start'] = start
1271+
if end:
1272+
params['start'] = end
1273+
return self.get(url, params=params)
1274+

0 commit comments

Comments
 (0)