Skip to content

Commit 277234d

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

File tree

2 files changed

+106
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)