Skip to content

Commit

Permalink
Bitbucket Cloud: Adding getting workspace members. (#1266)
Browse files Browse the repository at this point in the history
  • Loading branch information
djgoku authored Oct 21, 2023
1 parent 2716f13 commit 85f116f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
7 changes: 7 additions & 0 deletions atlassian/bitbucket/cloud/workspaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from requests import HTTPError
from ..base import BitbucketCloudBase

from .members import WorkspaceMembers
from .permissions import Permissions
from .projects import Projects
from ..repositories import WorkspaceRepositories
Expand Down Expand Up @@ -88,6 +89,7 @@ def __init__(self, data, *args, **kwargs):
self.__permissions = Permissions(self.url_joiner(self.url, "permissions"), **self._new_session_args)
self.__projects = Projects(self.get_link("projects"), **self._new_session_args)
self.__repositories = WorkspaceRepositories(self.get_link("repositories"), **self._new_session_args)
self.__members = WorkspaceMembers(self.get_link("members"), **self._new_session_args)

@property
def name(self):
Expand Down Expand Up @@ -137,3 +139,8 @@ def projects(self):
def repositories(self):
"""The workspace repositories"""
return self.__repositories

@property
def members(self):
"""The workspace members"""
return self.__members
62 changes: 62 additions & 0 deletions atlassian/bitbucket/cloud/workspaces/members.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# coding=utf-8

from ..base import BitbucketCloudBase


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

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

def each(self):
"""
Get all members in the workspace
:return: A generator for the member objects
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-workspaces/#api-workspaces-workspace-members-get
"""
for member in self._get_paged(None):
yield self.__get_object(member)

return

def get(self, member):
"""
Returns the requested member
:param member: string: Member's UUID or Atlassian ID.
:return: The requested Member object
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-workspaces/#api-workspaces-workspace-members-member-get
"""

return self.__get_object(super(WorkspaceMembers, self).get(member))


class WorkspaceMember(BitbucketCloudBase):
def __init__(self, data, *args, **kwargs):
super(WorkspaceMember, self).__init__(None, *args, data=data, expected_type="workspace_membership", **kwargs)

@property
def links(self):
"""The member links"""
return self.get_data("links")

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

@property
def user(self):
"""The member user dictionary"""
return self.get_data("user")

@property
def workspace(self):
"""The member workspace dictionary"""
return self.get_data("workspace")
7 changes: 7 additions & 0 deletions docs/bitbucket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@ Bitbucket Cloud
# Delete repository_variable
repository_variable.delete()
# Get a list of workspace members
workplace.members.each()
# Get a specific workspace member
workplace.members.get("a-user-account-id")
workplace.members.get("{a-user-uuid}")
Pipelines management
--------------------

Expand Down

0 comments on commit 85f116f

Please sign in to comment.