Skip to content

Commit 8b22e50

Browse files
Gonchik TsymzhitovGonchik Tsymzhitov
authored andcommitted
New features
2 parents e1bb795 + 15593e5 commit 8b22e50

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

atlassian/confluence.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_page_child_by_type(self, page_id, type='page', start=None, limit=None):
3434
:param page_id: A string containing the id of the type content container.
3535
:param type:
3636
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
37-
:param limit: OPTIONAL: how many items should be returned after the start index. Default: Site limit.
37+
:param limit: OPTIONAL: how many items should be returned after the start index. Default: Site limit 200.
3838
:return:
3939
"""
4040
params = {}
@@ -46,7 +46,7 @@ def get_page_child_by_type(self, page_id, type='page', start=None, limit=None):
4646
url = 'rest/api/content/{page_id}/child/{type}'.format(page_id=page_id, type=type)
4747
log.info(url)
4848
try:
49-
return self.get(url)
49+
return (self.get(url, params=params) or {}).get('results')
5050
except IndexError as e:
5151
log.error(e)
5252
return None
@@ -66,7 +66,7 @@ def get_page_space(self, page_id):
6666
:param page_id: content ID
6767
:return:
6868
"""
69-
return self.get_page_by_id(page_id, expand='space')['space']['key']
69+
return ((self.get_page_by_id(page_id, expand='space') or {}).get('space') or {}).get('key')
7070

7171
def get_page_by_title(self, space, title, start=None, limit=None):
7272
"""
@@ -91,7 +91,7 @@ def get_page_by_title(self, space, title, start=None, limit=None):
9191
params['title'] = str(title)
9292
url = 'rest/api/content'
9393
try:
94-
return self.get(url, params=params).get('results')[0]
94+
return (self.get(url, params=params) or {}).get('results')[0]
9595
except IndexError as e:
9696
log.error(e)
9797
return None
@@ -159,7 +159,7 @@ def get_all_pages_from_space(self, space, start=0, limit=500):
159159
url = 'rest/api/content?spaceKey={space}&limit={limit}&start={start}'.format(space=space,
160160
limit=limit,
161161
start=start)
162-
return self.get(url)['results']
162+
return (self.get(url) or {}).get('results')
163163

164164
def get_all_pages_from_space_trash(self, space, start=0, limit=500, status='trashed'):
165165
"""
@@ -460,7 +460,7 @@ def get_page_ancestors(self, page_id):
460460
:return: get properties
461461
"""
462462
url = 'rest/api/content/{page_id}?expand=ancestors'.format(page_id=page_id)
463-
return self.get(path=url).get('ancestors')
463+
return (self.get(path=url) or {}).get('ancestors')
464464

465465
def clean_all_caches(self):
466466
""" Clean all caches from cache management"""
@@ -580,4 +580,25 @@ def export_page(self, page_id):
580580
:param page_id: Page ID
581581
:return: PDF File
582582
"""
583-
return self.get_page_as_pdf(page_id)
583+
return self.get_page_as_pdf(page_id)
584+
585+
def get_descendant_page_id(self, space, parent_id, title):
586+
"""
587+
Provide space, parent_id and title of the descendant page, it will return the descendant page_id
588+
:param space: str
589+
:param parent_id: int
590+
:param title: str
591+
:return: page_id of the page whose title is passed in argument
592+
"""
593+
page_id = ""
594+
595+
url = 'rest/api/content/search?cql=parent={}%20AND%20space="{}"'.format(
596+
parent_id, space
597+
)
598+
response = self.get(url, {})
599+
600+
for each_page in response.get("results", []):
601+
if each_page.get("title") == title:
602+
page_id = each_page.get("id")
603+
break
604+
return page_id

atlassian/jira.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ def issue_create_or_update(self, fields):
292292
def get_issue_transitions(self, issue_key):
293293
url = 'rest/api/2/issue/{issue_key}?expand=transitions.fields&fields=status'.format(issue_key=issue_key)
294294
return [{'name': transition['name'], 'id': int(transition['id']), 'to': transition['to']['name']}
295-
for transition in self.get(url)['transitions']]
295+
for transition in (self.get(url) or {}).get('transitions')]
296296

297297
def get_status_id_from_name(self, status_name):
298298
url = 'rest/api/2/status/{name}'.format(name=status_name)
299-
return int(self.get(url)['id'])
299+
return int((self.get(url) or {}).get('id'))
300300

301301
def get_transition_id_to_status_name(self, issue_key, status_name):
302302
for transition in self.get_issue_transitions(issue_key):
@@ -313,7 +313,7 @@ def set_issue_status(self, issue_key, status_name):
313313

314314
def get_issue_status(self, issue_key):
315315
url = 'rest/api/2/issue/{issue_key}?fields=status'.format(issue_key=issue_key)
316-
return self.get(url)['fields']['status']['name']
316+
return (self.get(url) or {}).get('fields').get('status').get('name')
317317

318318
def component(self, component_id):
319319
return self.get('rest/api/2/component/{component_id}'.format(component_id=component_id))

0 commit comments

Comments
 (0)