From 3c918df0da4727db6d1a10fb1c619934772ca694 Mon Sep 17 00:00:00 2001 From: Adris Date: Fri, 7 Feb 2020 13:31:30 +0100 Subject: [PATCH] Complete docs contribution Complete docs contribution and add two new methods for filter get conditios by type repository or project contidition --- atlassian/bitbucket.py | 78 +++++++++++++++++++++++++++++------------- docs/bitbucket.rst | 45 ++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 24 deletions(-) diff --git a/atlassian/bitbucket.py b/atlassian/bitbucket.py index bf2bbcbb3..dc344d353 100644 --- a/atlassian/bitbucket.py +++ b/atlassian/bitbucket.py @@ -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) @@ -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( @@ -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: @@ -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( @@ -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 @@ -2025,6 +2024,50 @@ 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 @@ -2032,7 +2075,7 @@ def get_repo_condition(self, project_key, repo_key, 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 :return: """ url = 'rest/default-reviewers/1.0/projects/{projectKey}/repos/{repoKey}/conditions/{idCondition}'.format( @@ -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: @@ -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 {}) \ No newline at end of file + return (self.delete(url) or {}) \ No newline at end of file diff --git a/docs/bitbucket.rst b/docs/bitbucket.rst index 71374a36c..f1840ac07 100644 --- a/docs/bitbucket.rst +++ b/docs/bitbucket.rst @@ -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) \ No newline at end of file