From 1cbe725094d2fa06b6f4ff68a229a881cba4eb3f Mon Sep 17 00:00:00 2001 From: Viktxrrr Date: Thu, 23 Jan 2025 23:44:05 +0700 Subject: [PATCH] [Bitbucket] Add "get pullrequests by commit" method --- .../bitbucket/cloud/repositories/commits.py | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/atlassian/bitbucket/cloud/repositories/commits.py b/atlassian/bitbucket/cloud/repositories/commits.py index 8a69c2336..0710f5057 100644 --- a/atlassian/bitbucket/cloud/repositories/commits.py +++ b/atlassian/bitbucket/cloud/repositories/commits.py @@ -3,7 +3,7 @@ from ..base import BitbucketCloudBase from ..common.builds import Build from ..common.comments import Comment -from ..common.users import User, Participant +from ..common.users import Participant, User class Commits(BitbucketCloudBase): @@ -186,3 +186,29 @@ def unapprove(self): API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-approve-delete """ return super(BitbucketCloudBase, self).delete("approve") + + def get_pull_requests(self, start=0, pagelen=0): + """ + Retrieves pull requests associated with the current commit. + + Pull Request Commit Links app must be installed first before using this API; + installation automatically occurs when 'Go to pull request' is clicked + from the web interface for a commit's details. + + API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-commit-commit-pullrequests-get + + :param start: int, OPTIONAL: The starting page of pull requests to retrieve. Defaults to 0. + :param pagelen: int, OPTIONAL: The number of pull requests to retrieve per page. Defaults to 0. + :return: Generator[PullRequest]: A generator that yields `PullRequest` objects. + """ + # NOTE: Import moved inside the method to avoid circular import issues + from ...cloud.repositories.pullRequests import PullRequest + + params = {} + if start: + params["page"] = start + if pagelen: + params["pagelen"] = pagelen + + for pull_request in self._get_paged(url="pullrequests", params=params): + yield PullRequest(pull_request, **self._new_session_args)