Skip to content

Commit 269e9ea

Browse files
Gonchik TsymzhitovGonchik Tsymzhitov
authored andcommitted
Polish Bamboo methods and review upload plugin method
1 parent 8e4ad63 commit 269e9ea

File tree

9 files changed

+66
-39
lines changed

9 files changed

+66
-39
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Documentation
88

99
`Documentation`_
1010

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

1313
Install
1414
-------

atlassian/bamboo.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,16 @@ def project(self, project_key, expand=None, favourite=False, clover_enabled=Fals
8787
resource = 'project/{}'.format(project_key)
8888
return self.base_list_call(resource, expand, favourite, clover_enabled, start_index=0, max_results=25)
8989

90-
def project_plans(self, project_key):
90+
def project_plans(self, project_key, max_results=25):
9191
"""
9292
Returns a generator with the plans in a given project
9393
:param project_key: Project key
94+
:param max_results:
9495
:return: Generator with plans
9596
"""
96-
resource = 'project/{}'.format(project_key, max_results=25)
97-
return self.base_list_call(resource, expand='plans', favourite=False, clover_enabled=False, max_results=25,
97+
resource = 'project/{}'.format(project_key, max_results=max_results)
98+
return self.base_list_call(resource, expand='plans', favourite=False,
99+
clover_enabled=False, max_results=max_results,
98100
elements_key='plans', element_key='plan')
99101

100102
def plans(self, expand=None, favourite=False, clover_enabled=False, start_index=0, max_results=25):
@@ -150,10 +152,10 @@ def enable_plan(self, plan_key):
150152

151153
""" Branches """
152154

153-
def search_branches(self, plan_key, include_default_branch=True, max_results=25):
155+
def search_branches(self, plan_key, include_default_branch=True, max_results=25, start=0):
154156
params = {
155157
'max-result': max_results,
156-
'start-index': 0,
158+
'start-index': start,
157159
'masterPlanKey': plan_key,
158160
'includeMasterBranch': include_default_branch
159161
}
@@ -310,7 +312,7 @@ def plan_results(self, project_key, plan_key, expand=None, favourite=False, clov
310312
label=label, issue_key=issue_key, start_index=start_index, max_results=max_results,
311313
include_all_states=include_all_states)
312314

313-
def build_result(self, build_key, expand=None, include_all_states=False):
315+
def build_result(self, build_key, expand=None, include_all_states=False, start=0, max_results=25):
314316
"""
315317
Returns details of a specific build result
316318
:param expand: expands build result details on request. Possible values are: artifacts, comments, labels,
@@ -319,12 +321,15 @@ def build_result(self, build_key, expand=None, include_all_states=False):
319321
:param build_key: Should be in the form XX-YY[-ZZ]-99, that is, the last token should be an integer representing
320322
the build number
321323
:param include_all_states
324+
:param start:
325+
:param max_results:
322326
"""
323327
try:
324328
int(build_key.split('-')[-1])
325329
resource = "result/{}".format(build_key)
326330
return self.base_list_call(resource, expand, favourite=False, clover_enabled=False,
327-
start_index=0, max_results=25, include_all_states=include_all_states)
331+
start_index=start, max_results=max_results,
332+
include_all_states=include_all_states)
328333
except ValueError:
329334
raise ValueError('The key "{}" does not correspond to a build result'.format(build_key))
330335

@@ -654,10 +659,8 @@ def upload_plugin(self, plugin_path):
654659
files = {
655660
'plugin': open(plugin_path, 'rb')
656661
}
657-
headers = {
658-
'X-Atlassian-Token': 'nocheck'
659-
}
660-
upm_token = self.request(method='GET', path='rest/plugins/1.0/', headers=headers, trailing=True).headers[
661-
'upm-token']
662+
upm_token = \
663+
self.request(method='GET', path='rest/plugins/1.0/', headers=self.no_check_headers, trailing=True).headers[
664+
'upm-token']
662665
url = 'rest/plugins/1.0/?token={upm_token}'.format(upm_token=upm_token)
663-
return self.post(url, files=files, headers=headers)
666+
return self.post(url, files=files, headers=self.no_check_headers)

atlassian/bitbucket.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,13 +1785,11 @@ def upload_plugin(self, plugin_path):
17851785
files = {
17861786
'plugin': open(plugin_path, 'rb')
17871787
}
1788-
headers = {
1789-
'X-Atlassian-Token': 'nocheck'
1790-
}
1791-
upm_token = self.request(method='GET', path='rest/plugins/1.0/', headers=headers, trailing=True).headers[
1792-
'upm-token']
1788+
upm_token = \
1789+
self.request(method='GET', path='rest/plugins/1.0/', headers=self.no_check_headers, trailing=True).headers[
1790+
'upm-token']
17931791
url = 'rest/plugins/1.0/?token={upm_token}'.format(upm_token=upm_token)
1794-
return self.post(url, files=files, headers=headers)
1792+
return self.post(url, files=files, headers=self.no_check_headers)
17951793

17961794
def upload_file(self, project, repository, content, message, branch, filename):
17971795
"""
@@ -2170,8 +2168,8 @@ def delete_repo_condition(self, project_key, repo_key, id_condition):
21702168
repoKey=repo_key,
21712169
idCondition=id_condition)
21722170
return self.delete(url) or {}
2173-
2174-
def get_associated_build_statuses(self,commit):
2171+
2172+
def get_associated_build_statuses(self, commit):
21752173
"""
21762174
To get the build statuses associated with a commit.
21772175
:commit: str- commit id
@@ -2181,7 +2179,5 @@ def get_associated_build_statuses(self,commit):
21812179
url = '/rest/build-status/1.0/commits/{commitId}'.format(commitId=commit)
21822180
else:
21832181
url = '/rest/build-status/2.0/commits/{commitId}'.format(commitId=commit)
2184-
2182+
21852183
return self.get(url)
2186-
2187-

atlassian/confluence.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ def get_page_by_title(self, space, title, start=0, limit=1, expand=None):
148148
return self.get(url, params=params)
149149
else:
150150
try:
151-
return (self.get(url, params=params) or {}).get('results')[0]
151+
response = (self.get(url, params=params) or {}).get('results')
152+
return response[0] if response else None
152153
except (IndexError, TypeError) as e:
153154
log.error("Can't find '{title}' page on the {url}!".format(title=title, url=self.url))
154155
log.debug(e)
@@ -1266,13 +1267,11 @@ def upload_plugin(self, plugin_path):
12661267
files = {
12671268
'plugin': open(plugin_path, 'rb')
12681269
}
1269-
headers = {
1270-
'X-Atlassian-Token': 'nocheck'
1271-
}
1272-
upm_token = self.request(method='GET', path='rest/plugins/1.0/', headers=headers, trailing=True).headers[
1273-
'upm-token']
1270+
upm_token = \
1271+
self.request(method='GET', path='rest/plugins/1.0/', headers=self.no_check_headers, trailing=True).headers[
1272+
'upm-token']
12741273
url = 'rest/plugins/1.0/?token={upm_token}'.format(upm_token=upm_token)
1275-
return self.post(url, files=files, headers=headers)
1274+
return self.post(url, files=files, headers=self.no_check_headers)
12761275

12771276
def delete_plugin(self, plugin_key):
12781277
"""

atlassian/crowd.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,18 @@ def health_check(self):
4343
# check as support tools
4444
response = self.get('rest/supportHealthCheck/1.0/check/')
4545
return response
46+
47+
def upload_plugin(self, plugin_path):
48+
"""
49+
Provide plugin path for upload into Jira e.g. useful for auto deploy
50+
:param plugin_path:
51+
:return:
52+
"""
53+
files = {
54+
'plugin': open(plugin_path, 'rb')
55+
}
56+
upm_token = \
57+
self.request(method='GET', path='rest/plugins/1.0/', headers=self.no_check_headers, trailing=True).headers[
58+
'upm-token']
59+
url = 'rest/plugins/1.0/?token={upm_token}'.format(upm_token=upm_token)
60+
return self.post(url, files=files, headers=self.no_check_headers)

atlassian/jira.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,13 +1458,11 @@ def upload_plugin(self, plugin_path):
14581458
files = {
14591459
'plugin': open(plugin_path, 'rb')
14601460
}
1461-
headers = {
1462-
'X-Atlassian-Token': 'nocheck'
1463-
}
1464-
upm_token = self.request(method='GET', path='rest/plugins/1.0/', headers=headers, trailing=True).headers[
1465-
'upm-token']
1461+
upm_token = \
1462+
self.request(method='GET', path='rest/plugins/1.0/', headers=self.no_check_headers, trailing=True).headers[
1463+
'upm-token']
14661464
url = 'rest/plugins/1.0/?token={upm_token}'.format(upm_token=upm_token)
1467-
return self.post(url, files=files, headers=headers)
1465+
return self.post(url, files=files, headers=self.no_check_headers)
14681466

14691467
def delete_plugin(self, plugin_key):
14701468
"""

atlassian/service_desk.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,18 @@ def get_issues_in_queue(self, service_desk_id, queue_id, start=0, limit=50):
607607
params['limit'] = int(limit)
608608

609609
return self.get(url, headers=self.experimental_headers, params=params)
610+
611+
def upload_plugin(self, plugin_path):
612+
"""
613+
Provide plugin path for upload into Jira e.g. useful for auto deploy
614+
:param plugin_path:
615+
:return:
616+
"""
617+
files = {
618+
'plugin': open(plugin_path, 'rb')
619+
}
620+
upm_token = \
621+
self.request(method='GET', path='rest/plugins/1.0/', headers=self.no_check_headers, trailing=True).headers[
622+
'upm-token']
623+
url = 'rest/plugins/1.0/?token={upm_token}'.format(upm_token=upm_token)
624+
return self.post(url, files=files, headers=self.no_check_headers)

docs/bitbucket.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Bitbucket module
1+
BitBucket module
22
================
33

44
Manage projects

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ Or reuse cookie file:
153153
jira
154154
confluence
155155
bitbucket
156+
bamboo
156157
service_desk
157158

158159
.. |Build Status| image:: https://travis-ci.org/atlassian-api/atlassian-python-api.svg?branch=master

0 commit comments

Comments
 (0)