Skip to content

Commit f582e9e

Browse files
committed
Bitbucket: Adding repository variables.
1 parent adb6ac0 commit f582e9e

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

atlassian/bitbucket/cloud/repositories/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .pipelines import Pipelines
1111
from .pullRequests import PullRequests
1212
from .refs import Branches, Tags
13+
from .repositoryVariables import RepositoryVariables
1314

1415

1516
class RepositoriesBase(BitbucketCloudBase):
@@ -264,6 +265,9 @@ def __init__(self, data, *args, **kwargs):
264265
self.__issues = Issues("{}/issues".format(self.url), **self._new_session_args)
265266
self.__pipelines = Pipelines("{}/pipelines".format(self.url), **self._new_session_args)
266267
self.__pullrequests = PullRequests("{}/pullrequests".format(self.url), **self._new_session_args)
268+
self.__repository_variables = RepositoryVariables(
269+
"{}/pipelines_config/variables".format(self.url), **self._new_session_args
270+
)
267271
self.__tags = Tags("{}/refs/tags".format(self.url), **self._new_session_args)
268272

269273
def update(self, **kwargs):
@@ -402,6 +406,11 @@ def pullrequests(self):
402406
"""The repository pull requests"""
403407
return self.__pullrequests
404408

409+
@property
410+
def repository_variables(self):
411+
"""The repository variables"""
412+
return self.__repository_variables
413+
405414
@property
406415
def tags(self):
407416
"""The repository tags."""
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# coding=utf-8
2+
3+
from ..base import BitbucketCloudBase
4+
5+
6+
class RepositoryVariables(BitbucketCloudBase):
7+
def __init__(self, url, *args, **kwargs):
8+
super(RepositoryVariables, self).__init__(url, *args, **kwargs)
9+
10+
def __get_object(self, data):
11+
return RepositoryVariable(
12+
self.url_joiner(self.url, data["uuid"]),
13+
data,
14+
**self._new_session_args,
15+
)
16+
17+
def each(self, q=None, sort=None):
18+
"""
19+
Returns the list of repository variables in this repository.
20+
21+
:param q: string: Query string to narrow down the response.
22+
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
23+
:param sort: string: Name of a response property to sort results.
24+
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
25+
26+
:return: A generator for the RepositoryVariable objects
27+
28+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pipelines_config/variables/#get
29+
"""
30+
params = {}
31+
if sort is not None:
32+
params["sort"] = sort
33+
if q is not None:
34+
params["q"] = q
35+
for pipeline_variable in self._get_paged(
36+
None,
37+
trailing=True,
38+
paging_workaround=True,
39+
params=params,
40+
):
41+
yield self.__get_object(pipeline_variable)
42+
43+
return
44+
45+
def get(self, uuid):
46+
"""
47+
Returns the pipeline with the uuid in this repository.
48+
49+
:param uuid: string: The requested pipeline uuid
50+
51+
:return: The requested RepositoryVariable objects
52+
53+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pipelines_config/variables/%7Bvariable_uuid%7D#get
54+
"""
55+
return self.__get_object(super(RepositoryVariables, self).get(uuid))
56+
57+
58+
class RepositoryVariable(BitbucketCloudBase):
59+
def __init__(self, url, data, *args, **kwargs):
60+
super(RepositoryVariable, self).__init__(url, *args, data=data, expected_type="pipeline_variable", **kwargs)
61+
62+
@property
63+
def uuid(self):
64+
"""The repository variable uuid"""
65+
return self.get_data("uuid")
66+
67+
@property
68+
def key(self):
69+
"""The repository variable key"""
70+
return self.get_data("key")
71+
72+
@property
73+
def scope(self):
74+
"""The repository variable scope"""
75+
return self.get_data("scope")
76+
77+
@property
78+
def secured(self):
79+
"""The repository variable secured"""
80+
return self.get_data("secured")
81+
82+
@property
83+
def system(self):
84+
"""The repository variable system"""
85+
return self.get_data("system")
86+
87+
@property
88+
def type(self):
89+
"""The repository variable type"""
90+
return self.get_data("type")
91+
92+
@property
93+
def value(self):
94+
"""The repository variable value"""
95+
return self.get_data("value")

0 commit comments

Comments
 (0)