Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BitBucket] add PR related methods: blocker-comments and assign participant role #1475

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
43 changes: 43 additions & 0 deletions atlassian/bitbucket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,20 @@ def get_pull_requests_participants(
params["limit"] = limit
return self._get_paged(url, params)

def assign_pull_request_participant_role(self, project_key: str, repository_slug: str, pull_request_id: int, role: str, user: str) -> dict:
"""
Assign a role to a user for a pull request
:param project_key: The project key
:param repository_slug: The repository key
:param pull_request_id: The pull request id
:param role: The role to assign, currently it only accepts REVIEWER
:param user: The user to assign the role to
:return:
"""
url = self._url_pull_request_participants(project_key, repository_slug, pull_request_id)
data = {"role": role, "user": {"name": user}}
return self.post(url, data=data)

def get_dashboard_pull_requests(
self,
start=0,
Expand Down Expand Up @@ -2104,6 +2118,35 @@ def delete_pull_request_comment(
data = {"version": comment_version}
return self.delete(url, params=data)

def _url_pull_request_blocker_comments(self, project_key, repository_slug, pull_request_id) -> str:
url = "{}/blocker-comments".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
return url

def add_pull_request_blocker_comment(self, project_key: str, repository_slug: str, pull_request_id: int, text: dict, severity: str) -> dict:
"""
Add a comment to a pull request that blocks the merge
:param project_key: The project key
:param repository_slug: The repository key
:param pull_request_id: The pull request id
:param text: The text of the comment
:param severity: The severity of the comment
:return:
"""
url = self._url_pull_request_blocker_comments(project_key, repository_slug, pull_request_id)
data = {"text": text, "severity": severity}
return self.post(url, data=data)

def search_pull_request_blocker_comment(self, project_key: str, repository_slug: str, pull_request_id: int) -> dict:
"""
Get all comments that block the merge of a pull request
:param project_key: The project key
:param repository_slug: The repository key
:param pull_request_id: The pull request id
:return:
"""
url = self._url_pull_request_blocker_comments(project_key, repository_slug, pull_request_id)
return self.get(url)

def decline_pull_request(self, project_key, repository_slug, pr_id, pr_version):
"""
Decline a pull request.
Expand Down
9 changes: 9 additions & 0 deletions docs/bitbucket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ Pull Request management
# Reopen pull request
bitbucket.reopen_pull_request(project_key, repository, pr_id, pr_version)

# Assign user as a reviewer of pull request
bitbucket.assign_pull_request_participant_role(project_key, repository, pr_id, "REVIEWER", username)

# Add a blocker comment to a pull request (create a new task)
bitbucket.add_pull_request_blocker_comment(project_key, repository, pr_id, "Input task text here", "BLOCKER")

# Get blocker comments for a pull request
bitbucket.search_pull_request_blocker_comment(project_key, repository, pr_id)

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

Expand Down
Loading