Skip to content

Commit cd46637

Browse files
authored
[Bitbucket] Add "get pullrequests by commit" method (#1497)
1 parent ac8870e commit cd46637

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

atlassian/bitbucket/cloud/repositories/commits.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from ..base import BitbucketCloudBase
44
from ..common.builds import Build
55
from ..common.comments import Comment
6-
from ..common.users import User, Participant
6+
from ..common.users import Participant, User
77

88

99
class Commits(BitbucketCloudBase):
@@ -186,3 +186,29 @@ def unapprove(self):
186186
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-approve-delete
187187
"""
188188
return super(BitbucketCloudBase, self).delete("approve")
189+
190+
def get_pull_requests(self, start=0, pagelen=0):
191+
"""
192+
Retrieves pull requests associated with the current commit.
193+
194+
Pull Request Commit Links app must be installed first before using this API;
195+
installation automatically occurs when 'Go to pull request' is clicked
196+
from the web interface for a commit's details.
197+
198+
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-commit-commit-pullrequests-get
199+
200+
:param start: int, OPTIONAL: The starting page of pull requests to retrieve. Defaults to 0.
201+
:param pagelen: int, OPTIONAL: The number of pull requests to retrieve per page. Defaults to 0.
202+
:return: Generator[PullRequest]: A generator that yields `PullRequest` objects.
203+
"""
204+
# NOTE: Import moved inside the method to avoid circular import issues
205+
from ...cloud.repositories.pullRequests import PullRequest
206+
207+
params = {}
208+
if start:
209+
params["page"] = start
210+
if pagelen:
211+
params["pagelen"] = pagelen
212+
213+
for pull_request in self._get_paged(url="pullrequests", params=params):
214+
yield PullRequest(pull_request, **self._new_session_args)

0 commit comments

Comments
 (0)