Skip to content

Commit

Permalink
[BitBucket] add PR related methods: blocker-comments and assign parti…
Browse files Browse the repository at this point in the history
…cipant role
  • Loading branch information
atanev committed Nov 25, 2024
1 parent 22c6988 commit 488e59c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
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

0 comments on commit 488e59c

Please sign in to comment.