Skip to content

Commit

Permalink
Bitbucket Cloud: Adding Repository Group Permissions (#1183)
Browse files Browse the repository at this point in the history
* Bitbucket Cloud: Adding Repository Group Permissions

* Bitbucket Cloud: Updating bitbucket read the docs.
  • Loading branch information
djgoku authored Jun 8, 2023
1 parent 9cd0df8 commit 01fcf59
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
9 changes: 9 additions & 0 deletions atlassian/bitbucket/cloud/repositories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .commits import Commits
from .defaultReviewers import DefaultReviewers
from .deploymentEnvironments import DeploymentEnvironments
from .groupPermissions import GroupPermissions
from .pipelines import Pipelines
from .pullRequests import PullRequests
from .refs import Branches, Tags
Expand Down Expand Up @@ -262,6 +263,9 @@ def __init__(self, data, *args, **kwargs):
self.__deployment_environments = DeploymentEnvironments(
"{}/environments".format(self.url), **self._new_session_args
)
self.__group_permissions = GroupPermissions(
"{}/permissions-config/groups".format(self.url), **self._new_session_args
)
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)
Expand Down Expand Up @@ -396,6 +400,11 @@ def issues(self):
"""The repository issues"""
return self.__issues

@property
def group_permissions(self):
"""The repository group permissions"""
return self.__group_permissions

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

from ..base import BitbucketCloudBase


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

def __get_object(self, data):
return GroupPermission(
self.url,
data,
**self._new_session_args,
)

def each(self, q=None, sort=None):
"""
Returns the list of group permissions 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 GroupPermission objects
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-repositories/#api-repositories-workspace-repo-slug-permissions-config-groups-get
"""
params = {}
if sort is not None:
params["sort"] = sort
if q is not None:
params["q"] = q
for group_permission in self._get_paged(
None,
trailing=True,
params=params,
):
yield self.__get_object(group_permission)

return

def get(self, group_slug):
"""
Returns the group permission with the group slug in this repository.
:param group_slug: string: The requested permission group_slug
:return: The requested GroupPermission objects
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-repositories/#api-repositories-workspace-repo-slug-permissions-config-groups-group-slug-get
"""
return self.__get_object(super(GroupPermissions, self).get(group_slug))


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

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

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

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

@property
def links(self):
"""The repository variable links"""
return self.get_data("links")
6 changes: 6 additions & 0 deletions docs/bitbucket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,12 @@ Bitbucket Cloud
# Get a list of deployment environment variables from a deployment environment
deployment_environment.deployment_environment_variables.each():
# Get a list of group permissions from a repository
repository.group_permissions.each():
# Get a single group permission from a repository by group slug
repository.group_permissions.get(group_slug)
# Get a list of repository variables from a repository
repository.repository_variables.each():
Expand Down

0 comments on commit 01fcf59

Please sign in to comment.