Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 194 additions & 1 deletion atlassian/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ def get_repo(self, project_key, repository_slug):
:param repository_slug: url-compatible repository identifier
:return: Dictionary of request response
"""

if not self.cloud:
url = 'rest/api/1.0/projects/{project}/repos/{repository}' \
.format(project=project_key, repository=repository_slug)
Expand Down Expand Up @@ -1940,3 +1939,197 @@ def _get_paged(self, url, params):
response = self.get(url, params=params)
values += response.get('values')
return values

def get_project_conditions(self, project_key):
"""
Request type: GET
Return a page of defaults conditions with reviewers list that have been configured for this project.
For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264904368
:projectKey: str
:return:
"""
url = 'rest/default-reviewers/1.0/projects/{projectKey}/conditions'.format(
projectKey=project_key)
return (self.get(url) or {})

def get_project_condition(self, project_key, id_condition):
"""
Request type: GET
Return a specific condition with reviewers list that has been configured for this project.
For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264901504
:projectKey: str - project key involved
:idCondition: int - condition id involved
:return:
"""
url = 'rest/default-reviewers/1.0/projects/{projectKey}/conditions/{idCondition}'.format(
projectKey=key,
idCondition=id_condition)
return (self.get(url) or {})

def create_project_condition(self, project_key, condition):
"""
Request type: POST
Create a new condition for this project.
For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264893584
:projectKey: str- project key involved
:data: condition: dictionary object
:example condition: '{"sourceMatcher":{"id":"any","type":{"id":"ANY_REF"}},"targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},"reviewers":[{"id": 12}],"requiredApprovals":"0"}'
:return:
"""
url = 'rest/default-reviewers/1.0/projects/{projectKey}/condition'.format(
projectKey=project_key)
return (self.post(url, data=condition) or {})

def update_project_condition(self, project_key, condition, id_condition):
"""
Request type: PUT
Update a new condition for this project.
For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264927632
:projectKey: str- project key involved
:idCondition: int - condition id involved
:data: condition: dictionary object
:example condition: '{"sourceMatcher":{"id":"any","type":{"id":"ANY_REF"}},"targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},"reviewers":[{"id": 12}],"requiredApprovals":"0"}'
:return:
"""
url = 'rest/default-reviewers/1.0/projects/{projectKey}/condition/{idCondition}'.format(
projectKey=project_key,
idCondition=id_condition)
return (self.put(url, data=condition) or {})

def delete_project_condition(self, project_key, id_condition):
"""
Request type: DELETE
Delete a specific condition for this repository slug inside project.
For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264896304
:projectKey: str- project key involved
:idCondition: int - condition id involved
:return:
"""
url = 'rest/default-reviewers/1.0/projects/{projectKey}/condition/{idCondition}'.format(
projectKey=project_key,
idCondition=id_condition)
return (self.delete(url) or {})

def get_repo_conditions(self, project_key, repo_key):
"""
Request type: GET
Return a page of defaults conditions with reviewers list (type REPOSITORY or PROJECT) that have been configured for this repository slug inside project specified.
For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264928992
:projectKey: str- project key involved
:repoKey: str - repo key involved
:return:
"""
url = 'rest/default-reviewers/1.0/projects/{projectKey}/repos/{repoKey}/conditions'.format(
projectKey=project_key,
repoKey=repo_key)
return (self.get(url) or {})

def get_repo_project_conditions(self, project_key, repo_key):
"""
Request type: GET
Return a page of repository conditions (only type PROJECT) with reviewers list associated that have been configured for this repository slug inside project specified.
For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264928992
:projectKey: str- project key involved
:repoKey: str - repo key involved
:return:
"""
TYPE_REPO = 'REPOSITORY'
url = 'rest/default-reviewers/1.0/projects/{projectKey}/repos/{repoKey}/conditions'.format(
projectKey=project_key,
repoKey=repo_key)

response = (self.get(url) or {})
count = 0
for condition in response:
if condition['scope']['type'] == TYPE_REPO:
del response[count]
count+=1
return response

def get_repo_repo_conditions(self, project_key, repo_key):
"""
Request type: GET
Return a page of repository conditions (only type REPOSITORY) with reviewers list associated that have been configured for this repository slug inside project specified.
For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264928992
:projectKey: str- project key involved
:repoKey: str - repo key involved
:return:
"""
TYPE_PROYECT = 'PROJECT'
url = 'rest/default-reviewers/1.0/projects/{projectKey}/repos/{repoKey}/conditions'.format(
projectKey=project_key,
repoKey=repo_key)

response = (self.get(url) or {})
count = 0
for condition in response:
if condition['scope']['type'] == TYPE_PROYECT:
del response[count]
count+=1
return response

def get_repo_condition(self, project_key, repo_key, id_condition):
"""
Request type: GET
Return a specific condition with reviewers list that have been configured for this repository slug inside project specified.
For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264927632
:projectKey: str- project key involved
:repoKey: str - repo key involved
:idCondition: int - condition id involved
:return:
"""
url = 'rest/default-reviewers/1.0/projects/{projectKey}/repos/{repoKey}/conditions/{idCondition}'.format(
projectKey=project_key,
repoKey=repo_key,
idCondition=id_condition)
return (self.get(url) or {})

def create_repo_condition(self, project_key, repo_key, condition):
"""
Request type: POST
Create a new condition for this repository slug inside project specified.
For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264908128
:projectKey: str- project key involved
:repoKey: str - repo key involved
:data: condition: dictionary object
:example condition: '{"sourceMatcher":{"id":"any","type":{"id":"ANY_REF"}},"targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},"reviewers":[{"id": 12}],"requiredApprovals":"0"}'
:return:
"""
url = 'rest/default-reviewers/1.0/projects/{projectKey}/repos/{repoKey}/condition'.format(
projectKey=project_key,
repoKey=repo_key)
return (self.post(url, data=condition) or {})

def update_repo_condition(self, project_key, repo_key, condition, id_condition):
"""
Request type: PUT
Update a specific condition for this repository slug inside project.
For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264927632
:projectKey: str- project key involved
:repoKey: str - repo key involved
:idCondition: int - condition id involved
:data: condition: dictionary object
:example condition: '{"sourceMatcher":{"id":"any","type":{"id":"ANY_REF"}},"targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},"reviewers":[{"id": 12}],"requiredApprovals":"0"}'
:return:
"""
url = 'rest/default-reviewers/1.0/projects/{projectKey}/repos/{repoKey}/condition/{idCondition}'.format(
projectKey=project_key,
repoKey=repo_key,
idCondition=id_condition)
return (self.put(url, data=condition) or {})

def delete_repo_condition(self, project_key, repo_key, id_condition):
"""
Request type: DELETE
Delete a specific condition for this repository slug inside project.
For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm8287339888
:projectKey: str- project key involved
:repoKey: str - repo key involved
:idCondition: int - condition id involved
:return:
"""
url = 'rest/default-reviewers/1.0/projects/{projectKey}/repos/{repoKey}/condition/{idCondition}'.format(
projectKey=project_key,
repoKey=repo_key,
idCondition=id_condition)
return (self.delete(url) or {})
45 changes: 45 additions & 0 deletions docs/bitbucket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,48 @@ Pull Request management

# Reopen pull request
bitbucket.reopen_pull_request(project_key, repository, pr_id, pr_version)

Conditions-Reviewers management
-----------------------

.. code-block:: python

# Get all project conditions with reviewers list for specific project
bitbucket.get_project_conditions(project_key)

# Get a project condition with reviewers list for specific project
bitbucket.get_project_condition(project_key, id_condition)

# Create project condition with reviewers for specific project
# :example condition: '{"sourceMatcher":{"id":"any","type":{"id":"ANY_REF"}},"targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},"reviewers":[{"id": 12}],"requiredApprovals":"0"}'
bitbucket.create_project_condition(project_key, condition)

# Update a project condition with reviewers for specific project
# :example condition: '{"sourceMatcher":{"id":"any","type":{"id":"ANY_REF"}},"targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},"reviewers":[{"id": 12}],"requiredApprovals":"0"}'
bitbucket.update_project_condition(project_key, condition, id_condition)

# Delete a project condition for specific project
bitbucket.delete_project_condition(project_key, id_condition)

# Get all repository conditions with reviewers list for specific repository in project
bitbucket.get_repo_conditions(project_key, repo_key)

# Get repository conditions with reviewers list only only conditions type PROJECT for specific repository in project
bitbucket.get_repo_project_conditions(project_key, repo_key)

# Get repository conditions with reviewers list only conditions type REPOSITORY for specific repository in project
bitbucket.get_repo_repo_conditions(project_key, repo_key)

# Get a project condition with reviewers list for specific repository in project
bitbucket.get_repo_condition(project_key, repo_key, id_condition)

# Create project condition with reviewers for specific repository in project
# :example condition: '{"sourceMatcher":{"id":"any","type":{"id":"ANY_REF"}},"targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},"reviewers":[{"id": 12}],"requiredApprovals":"0"}'
bitbucket.create_repo_condition(project_key, repo_key, condition)

# Update a project condition with reviewers for specific repository in project
# :example condition: '{"sourceMatcher":{"id":"any","type":{"id":"ANY_REF"}},"targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},"reviewers":[{"id": 12}],"requiredApprovals":"0"}'
bitbucket.update_repo_condition(project_key, repo_key, condition, id_condition)

# Delete a project condition for specific repository in project
bitbucket.delete_repo_condition(project_key, repo_key, id_condition)