Skip to content

Bitbucket: Adding repository variables. #1179

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

Merged
merged 2 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions atlassian/bitbucket/cloud/repositories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .pipelines import Pipelines
from .pullRequests import PullRequests
from .refs import Branches, Tags
from .repositoryVariables import RepositoryVariables


class RepositoriesBase(BitbucketCloudBase):
Expand Down Expand Up @@ -264,6 +265,9 @@ def __init__(self, data, *args, **kwargs):
self.__issues = Issues("{}/issues".format(self.url), **self._new_session_args)
self.__pipelines = Pipelines("{}/pipelines".format(self.url), **self._new_session_args)
self.__pullrequests = PullRequests("{}/pullrequests".format(self.url), **self._new_session_args)
self.__repository_variables = RepositoryVariables(
"{}/pipelines_config/variables".format(self.url), **self._new_session_args
)
self.__tags = Tags("{}/refs/tags".format(self.url), **self._new_session_args)

def update(self, **kwargs):
Expand Down Expand Up @@ -402,6 +406,11 @@ def pullrequests(self):
"""The repository pull requests"""
return self.__pullrequests

@property
def repository_variables(self):
"""The repository variables"""
return self.__repository_variables

@property
def tags(self):
"""The repository tags."""
Expand Down
95 changes: 95 additions & 0 deletions atlassian/bitbucket/cloud/repositories/repositoryVariables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# coding=utf-8

from ..base import BitbucketCloudBase


class RepositoryVariables(BitbucketCloudBase):
def __init__(self, url, *args, **kwargs):
super(RepositoryVariables, self).__init__(url, *args, **kwargs)

def __get_object(self, data):
return RepositoryVariable(
self.url_joiner(self.url, data["uuid"]),
data,
**self._new_session_args,
)

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

:param q: string: Query string to narrow down the response.
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 RepositoryVariable objects

API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pipelines_config/variables/#get
"""
params = {}
if sort is not None:
params["sort"] = sort
if q is not None:
params["q"] = q
for pipeline_variable in self._get_paged(
None,
trailing=True,
paging_workaround=True,
params=params,
):
yield self.__get_object(pipeline_variable)

return

def get(self, uuid):
"""
Returns the pipeline with the uuid in this repository.

:param uuid: string: The requested pipeline uuid

:return: The requested RepositoryVariable objects

API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pipelines_config/variables/%7Bvariable_uuid%7D#get
"""
return self.__get_object(super(RepositoryVariables, self).get(uuid))


class RepositoryVariable(BitbucketCloudBase):
def __init__(self, url, data, *args, **kwargs):
super(RepositoryVariable, self).__init__(url, *args, data=data, expected_type="pipeline_variable", **kwargs)

@property
def uuid(self):
"""The repository variable uuid"""
return self.get_data("uuid")

@property
def key(self):
"""The repository variable key"""
return self.get_data("key")

@property
def scope(self):
"""The repository variable scope"""
return self.get_data("scope")

@property
def secured(self):
"""The repository variable secured"""
return self.get_data("secured")

@property
def system(self):
"""The repository variable system"""
return self.get_data("system")

@property
def type(self):
"""The repository variable type"""
return self.get_data("type")

@property
def value(self):
"""The repository variable value"""
return self.get_data("value")
18 changes: 18 additions & 0 deletions docs/bitbucket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,24 @@ Bitbucket Cloud
# Get a list of repos from a project
project.repositories.each():

# Get a repository
repository = workplace.repositories.get(repository_slug)

# Get a list of deployment environments from a repository
repository.deployment_environments.each():

# Get a single deployment environment from a repository by deployment environment key
deployment_environment = repository.deployment_environments.get(deployment_environment_key)

# Get a list of deployment environment variables from a deployment environment
deployment_environment.deployment_environment_variables.each():

# Get a list of repository variables from a repository
repository.repository_variables.each():

# Get a single repository variable from a repository by repository variable key
repository.repository_variables.get(repository_variable_key)

Pipelines management
--------------------

Expand Down