Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitbucket Cloud: Fix for getting Repository Deployment Environment Variables via each() #1195

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions atlassian/bitbucket/cloud/repositories/deploymentEnvironments.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,31 +159,43 @@ def create(self, key, value, secured):
data = {"key": key, "value": value, "secured": secured}
return self.__get_object(self.post(None, data=data))

def each(self, q=None, sort=None):
def each(self, pagelen=10):
"""
Returns the list of deployment environment variables in this repository.

:param q: string: Query string to narrow down the response.
:param pagelen: integer: Query string to return this number of items from api.
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
:param sort: string: Name of a response property to sort results.
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.

:return: A generator for the DeploymentEnvironmentVariable objects
:return: A list of DeploymentEnvironmentVariable objects

API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-deployments-config-environments-environment-uuid-variables-get
"""
params = {}
if sort is not None:
params["sort"] = sort
if q is not None:
params["q"] = q
for deployment_environment_variable in self._get_paged(
None,
params=params,
):
yield self.__get_object(deployment_environment_variable)

return
params["pagelen"] = pagelen

response = super(BitbucketCloudBase, self).get(None, params=params)

pagelen = response.get("pagelen")
size_total = response.get("size")
pagelen_total = response.get("pagelen")
page = 1

deployment_environment_variables = []

# workaround for this issue
# https://jira.atlassian.com/browse/BCLOUD-20796
while True:
for value in response.get("values", []):
deployment_environment_variables.append(self.__get_object(value))

if pagelen_total < size_total:
pagelen_total = pagelen_total + response["pagelen"]
page = page + 1
response = super(BitbucketCloudBase, self).get(None, params={"pagelen": pagelen, "page": page})
else:
break

return deployment_environment_variables


class DeploymentEnvironmentVariable(BitbucketCloudBase):
Expand Down
Loading