Skip to content

[Bitbucket] Add "get pullrequests by commit" method #1497

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

Merged
merged 1 commit into from
Jan 23, 2025
Merged
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
28 changes: 27 additions & 1 deletion atlassian/bitbucket/cloud/repositories/commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Loading