Skip to content

Commit

Permalink
branches_permissions (#376)
Browse files Browse the repository at this point in the history
made repository optional
added 'all_branches_permissions'
  • Loading branch information
lelandsindttouchnet authored and gonchik committed Oct 28, 2019
1 parent c57b96f commit bc1cb99
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions atlassian/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,22 +1065,47 @@ def get_content_of_file(self, project, repository, filename, at=None, markup=Non
params['markup'] = markup
return self.get(url, params=params, not_json_response=True, headers=headers)

def get_branches_permissions(self, project, repository, limit=25):
def get_branches_permissions(self, project, repository=None, start=0, limit=25):
"""
Get branches permissions from a given repo
:param project:
:param repository:
:param start:
:param limit:
:return:
"""
url = 'rest/branch-permissions/2.0/projects/{project}/repos/{repository}/restrictions'.format(
project=project,
repository=repository)
if repository != None:
url = 'rest/branch-permissions/2.0/projects/{project}/repos/{repository}/restrictions'.format(
project=project,
repository=repository)
else:
url = 'rest/branch-permissions/2.0/projects/{project}/restrictions'.format(
project=project)

params = {}
if limit:
params['limit'] = limit
if start:
params['start'] = start
return self.get(url, params=params)

def all_branches_permissions(self, project, repository=None):
"""
Get branches permissions from a given repo
:param project:
:param repository:
:return:
"""
start = 0
branches_permissions = []
response = self.get_branches_permissions(project=project, repository=repository, start=start)
branches_permissions += response.get('values')
while not response.get('isLastPage'):
start = response.get('nextPageStart')
response = self.get_branches_permissions(project=project, repository=repository, start=start)
branches_permissions += response.get('values')
return branches_permissions

def reindex(self):
"""
Rebuild the bundled Elasticsearch indexes for Bitbucket Server
Expand Down

0 comments on commit bc1cb99

Please sign in to comment.