Skip to content

Commit

Permalink
Complete docs contribution
Browse files Browse the repository at this point in the history
Complete docs contribution and add two new methods for filter get conditios by type repository or project contidition
  • Loading branch information
adribp13 committed Feb 7, 2020
1 parent 08d29a0 commit 3c918df
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 24 deletions.
78 changes: 54 additions & 24 deletions 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 @@ -1959,7 +1958,7 @@ def get_project_condition(self, project_key, id_condition):
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: str - condition id involved
:idCondition: int - condition id involved
:return:
"""
url = 'rest/default-reviewers/1.0/projects/{projectKey}/conditions/{idCondition}'.format(
Expand Down Expand Up @@ -1987,7 +1986,7 @@ def update_project_condition(self, project_key, condition, id_condition):
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: str - condition id 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:
Expand All @@ -1997,13 +1996,13 @@ def update_project_condition(self, project_key, condition, id_condition):
idCondition=id_condition)
return (self.put(url, data=condition) or {})

def delete_project_condition(self, project_key, condition, id_condition):
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: str - condition id involved
:idCondition: int - condition id involved
:return:
"""
url = 'rest/default-reviewers/1.0/projects/{projectKey}/condition/{idCondition}'.format(
Expand All @@ -2014,7 +2013,7 @@ def delete_project_condition(self, project_key, condition, id_condition):
def get_repo_conditions(self, project_key, repo_key):
"""
Request type: GET
Return a page of defaults conditions with reviewers list that have been configured for this repository slug inside project specified.
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
Expand All @@ -2025,14 +2024,58 @@ def get_repo_conditions(self, project_key, repo_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: str - condition id involved
:idCondition: int - condition id involved
:return:
"""
url = 'rest/default-reviewers/1.0/projects/{projectKey}/repos/{repoKey}/conditions/{idCondition}'.format(
Expand Down Expand Up @@ -2064,7 +2107,7 @@ def update_repo_condition(self, project_key, repo_key, condition, id_condition):
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: str - condition id 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:
Expand All @@ -2075,31 +2118,18 @@ def update_repo_condition(self, project_key, repo_key, condition, id_condition):
idCondition=id_condition)
return (self.put(url, data=condition) or {})

def delete_repo_condition(self, project_key, repo_key, condition, id_condition):
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: str - condition id 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 {})

def get_repo_details(self, project_key, repo_key):
"""
Return repository details for this repository slug inside project specified.
For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html#idm8287366304
:projectKey: str- project key involved
:repoKey: str - repo key involved
:return:
"""
url = 'rest/api/1.0/projects/{projectKey}/repos/{repoKey}'.format(
projectKey=project_key,
repoKey=repo_key)
return (self.get(url) or {})
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)

0 comments on commit 3c918df

Please sign in to comment.