diff --git a/atlassian/bitbucket/cloud/repositories/repositoryVariables.py b/atlassian/bitbucket/cloud/repositories/repositoryVariables.py index fdbef84f1..16ee1cf33 100644 --- a/atlassian/bitbucket/cloud/repositories/repositoryVariables.py +++ b/atlassian/bitbucket/cloud/repositories/repositoryVariables.py @@ -14,6 +14,25 @@ def __get_object(self, data): **self._new_session_args, ) + def create(self, key, value, secured): + """ + Create a new repository variable for the given repository. + + :param key: string: The unique name of the variable. + :param value: string: The value of the variable. If the variable is secured, this will be empty. + :param secured: boolean: If true, this variable will be treated as secured. The value will never be exposed in the logs or the REST API. + + :return: The created RepositoryVariable object + + API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-config-variables-post + """ + data = { + "key": key, + "value": value, + "secured": secured, + } + return self.__get_object(self.post(None, data=data)) + def each(self, q=None, sort=None): """ Returns the list of repository variables in this repository. @@ -25,7 +44,7 @@ def each(self, q=None, sort=None): :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 + API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-config-variables-get """ params = {} if sort is not None: @@ -50,7 +69,7 @@ def get(self, 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 + API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-config-variables-variable-uuid-get """ return self.__get_object(super(RepositoryVariables, self).get(uuid)) @@ -59,6 +78,28 @@ class RepositoryVariable(BitbucketCloudBase): def __init__(self, url, data, *args, **kwargs): super(RepositoryVariable, self).__init__(url, *args, data=data, expected_type="pipeline_variable", **kwargs) + def update(self, **kwargs): + """ + Update the repository variable properties. Fields not present in the request body are ignored. + + :param kwargs: dict: The data to update. + + :return: The updated repository variable + + API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-config-variables-variable-uuid-put + """ + return self._update_data(self.put(None, data=kwargs)) + + def delete(self): + """ + Delete the repository variable. + + :return: The response on success + + API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-config-variables-variable-uuid-delete + """ + return super(RepositoryVariable, self).delete(None) + @property def uuid(self): """The repository variable uuid""" @@ -69,6 +110,11 @@ def key(self): """The repository variable key""" return self.get_data("key") + @key.setter + def key(self, key): + """Setter for the repository variable is key""" + return self.update(key=key) + @property def scope(self): """The repository variable scope""" @@ -93,3 +139,8 @@ def type(self): def value(self): """The repository variable value""" return self.get_data("value") + + @value.setter + def value(self, value): + """Setter for the repository variable value""" + return self.update(value=value) diff --git a/docs/bitbucket.rst b/docs/bitbucket.rst index 602523709..307ed6035 100755 --- a/docs/bitbucket.rst +++ b/docs/bitbucket.rst @@ -381,7 +381,19 @@ Bitbucket Cloud repository.repository_variables.each(): # Get a single repository variable from a repository by repository variable key - repository.repository_variables.get(repository_variable_key) + repository_variable = repository.repository_variables.get(repository_variable_key) + + # Create a new repository variable with a name of 'KEY', value of 'VALUE' and is not secured. + new_repository_variable = repository.repository_variables.create("KEY", "VALUE", False) + + # Update the 'key' field of repository_variable + updated_repository_variable = repository_variable.update(key="UPDATED_REPOSITORY_VARIABLE_KEY") + + # Update the 'value' field of repository_variable + updated_repository_variable = repository_variable.update(value="UPDATED_REPOSITORY_VARIABLE_VALUE") + + # Delete repository_variable + repository_variable.delete() Pipelines management --------------------