Skip to content

Commit 488e59c

Browse files
author
atanev
committed
[BitBucket] add PR related methods: blocker-comments and assign participant role
1 parent 22c6988 commit 488e59c

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

atlassian/bitbucket/__init__.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,20 @@ def get_pull_requests_participants(
19061906
params["limit"] = limit
19071907
return self._get_paged(url, params)
19081908

1909+
def assign_pull_request_participant_role(self, project_key: str, repository_slug: str, pull_request_id: int, role: str, user: str) -> dict:
1910+
"""
1911+
Assign a role to a user for a pull request
1912+
:param project_key: The project key
1913+
:param repository_slug: The repository key
1914+
:param pull_request_id: The pull request id
1915+
:param role: The role to assign, currently it only accepts REVIEWER
1916+
:param user: The user to assign the role to
1917+
:return:
1918+
"""
1919+
url = self._url_pull_request_participants(project_key, repository_slug, pull_request_id)
1920+
data = {"role": role, "user": {"name": user}}
1921+
return self.post(url, data=data)
1922+
19091923
def get_dashboard_pull_requests(
19101924
self,
19111925
start=0,
@@ -2104,6 +2118,35 @@ def delete_pull_request_comment(
21042118
data = {"version": comment_version}
21052119
return self.delete(url, params=data)
21062120

2121+
def _url_pull_request_blocker_comments(self, project_key, repository_slug, pull_request_id) -> str:
2122+
url = "{}/blocker-comments".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
2123+
return url
2124+
2125+
def add_pull_request_blocker_comment(self, project_key: str, repository_slug: str, pull_request_id: int, text: dict, severity: str) -> dict:
2126+
"""
2127+
Add a comment to a pull request that blocks the merge
2128+
:param project_key: The project key
2129+
:param repository_slug: The repository key
2130+
:param pull_request_id: The pull request id
2131+
:param text: The text of the comment
2132+
:param severity: The severity of the comment
2133+
:return:
2134+
"""
2135+
url = self._url_pull_request_blocker_comments(project_key, repository_slug, pull_request_id)
2136+
data = {"text": text, "severity": severity}
2137+
return self.post(url, data=data)
2138+
2139+
def search_pull_request_blocker_comment(self, project_key: str, repository_slug: str, pull_request_id: int) -> dict:
2140+
"""
2141+
Get all comments that block the merge of a pull request
2142+
:param project_key: The project key
2143+
:param repository_slug: The repository key
2144+
:param pull_request_id: The pull request id
2145+
:return:
2146+
"""
2147+
url = self._url_pull_request_blocker_comments(project_key, repository_slug, pull_request_id)
2148+
return self.get(url)
2149+
21072150
def decline_pull_request(self, project_key, repository_slug, pr_id, pr_version):
21082151
"""
21092152
Decline a pull request.

docs/bitbucket.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,15 @@ Pull Request management
294294
# Reopen pull request
295295
bitbucket.reopen_pull_request(project_key, repository, pr_id, pr_version)
296296
297+
# Assign user as a reviewer of pull request
298+
bitbucket.assign_pull_request_participant_role(project_key, repository, pr_id, "REVIEWER", username)
299+
300+
# Add a blocker comment to a pull request (create a new task)
301+
bitbucket.add_pull_request_blocker_comment(project_key, repository, pr_id, "Input task text here", "BLOCKER")
302+
303+
# Get blocker comments for a pull request
304+
bitbucket.search_pull_request_blocker_comment(project_key, repository, pr_id)
305+
297306
Conditions-Reviewers management
298307
-------------------------------
299308

0 commit comments

Comments
 (0)