Skip to content

Commit 7cc4f18

Browse files
authored
[BitBucket] Fix missing function for paged API. (#630)
* [BitBucket] Fix missing function for paged API. Fix wrong function calls found while implementing tests. * Change api_root for cloud. Api root for data center (cloud and not https://api.bitbucket.org) shall be `api_root` as in 1.17.7.
1 parent 0c2a7df commit 7cc4f18

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

atlassian/bitbucket/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, url, *args, **kwargs):
1818
if "api_version" not in kwargs:
1919
kwargs["api_version"] = "2.0" if "cloud" in kwargs and kwargs["cloud"] else "1.0"
2020
if "cloud" in kwargs:
21-
kwargs["api_root"] = "" if "api.bitbucket.org" in url else "api"
21+
kwargs["api_root"] = "" if "api.bitbucket.org" in url else "rest/api"
2222
super(Bitbucket, self).__init__(url, *args, **kwargs)
2323

2424
def markup_preview(self, data):
@@ -2343,7 +2343,7 @@ def get_pipeline_step(self, workspace, repository_slug, pipeline_uuid, step_uuid
23432343
.workspaces.get(workspace)
23442344
.repositories.get(repository_slug)
23452345
.pipelines.get(pipeline_uuid)
2346-
.steps(step_uuid)
2346+
.step(step_uuid)
23472347
.data
23482348
)
23492349

@@ -2363,7 +2363,7 @@ def get_pipeline_step_log(self, workspace, repository_slug, pipeline_uuid, step_
23632363
.workspaces.get(workspace)
23642364
.repositories.get(repository_slug)
23652365
.pipelines.get(pipeline_uuid)
2366-
.steps(step_uuid)
2366+
.step(step_uuid)
23672367
.log()
23682368
)
23692369

@@ -2467,6 +2467,7 @@ def delete_issue(self, workspace, repository_slug, id):
24672467
.repositories.get(repository_slug)
24682468
.issues.get(id)
24692469
.delete()
2470+
.data
24702471
)
24712472

24722473
@deprecated(
@@ -2572,6 +2573,7 @@ def delete_branch_restriction(self, workspace, repository_slug, id):
25722573
.repositories.get(repository_slug)
25732574
.branch_restrictions.get(id)
25742575
.delete()
2576+
.data
25752577
)
25762578

25772579
@deprecated(

atlassian/bitbucket/base.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,37 @@ def __init__(self, url, *args, **kwargs):
3030
def __str__(self):
3131
return PrettyPrinter(indent=4).pformat(self.__data)
3232

33+
def _get_paged(self, url, params={}, data=None, flags=None, trailing=None, absolute=False):
34+
"""
35+
Used to get the paged data
36+
:param url: The url to retrieve.
37+
:param params: The parameters (optional).
38+
:param data: The data (optional).
39+
40+
:return: nothing
41+
"""
42+
43+
while True:
44+
response = self.get(url, trailing=trailing, params=params, data=data, flags=flags, absolute=absolute)
45+
if "values" not in response:
46+
return
47+
48+
for value in response.get("values", []):
49+
yield value
50+
51+
if self.cloud:
52+
url = response.get("next")
53+
if url is None:
54+
break
55+
# From now on we have absolute URLs
56+
absolute = True
57+
else:
58+
if response.get("nextPageStart") is None:
59+
break
60+
params["start"] = response.get("nextPageStart")
61+
62+
return
63+
3364
@property
3465
def _new_session_args(self):
3566
return dict(

atlassian/rest_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def resource_url(self, resource, api_root=None, api_version=None):
158158

159159
@staticmethod
160160
def url_joiner(url, path, trailing=None):
161-
url_link = "/".join(s.strip("/") for s in [url, path] if s is not None)
161+
url_link = "/".join(str(s).strip("/") for s in [url, path] if s is not None)
162162
if trailing:
163163
url_link += "/"
164164
return url_link

0 commit comments

Comments
 (0)